Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
fix: update imports from plonky2_gadgets
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Jul 25, 2023
1 parent 6b982a5 commit 80a65d4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 70 deletions.
31 changes: 4 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
anyhow = "1.0.71"
clap = { version = "4.3.18", features = ["derive"] }
digest = "0.10.7"
plonky2 = { git = "ssh://git@github.com/succinctlabs/plonky2.git" }
plonky2 = { git = "https://github.com/succinctlabs/plonky2.git" }
plonky2_gadgets = { git = "ssh://git@github.com/succinctlabs/plonky2-gadgets.git" }
rand = "0.8.5"
serde_json = "1.0.103"
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod merkle;
pub mod scripts;
pub mod u32;
pub mod utils;
pub mod validator;

Expand Down
4 changes: 2 additions & 2 deletions src/scripts/generate_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use subtle_encoding::hex;

pub fn generate_tendermint_test_cases(num_validators: usize) {
let mut rng = rand::thread_rng();
// Generate an array of byte arrays where the byte arrays have variable length between 38 and 47 bytes and the total length of the array is less than n
// Generate an array of byte arrays where the byte arrays have variable length between 38 and 46 bytes and the total length of the array is less than n
let random_bytes: Vec<Vec<u8>> = (0..num_validators)
.map(|_| {
let inner_length = rng.gen_range(38..=47);
let inner_length = rng.gen_range(38..=46);
(0..inner_length).map(|_| rng.gen()).collect()
})
.collect();
Expand Down
25 changes: 0 additions & 25 deletions src/u32.rs

This file was deleted.

25 changes: 11 additions & 14 deletions src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use plonky2_gadgets::num::u32::gadgets::arithmetic_u32::{U32Target, CircuitBuild
use crate::merkle::{HASH_SIZE, HASH_SIZE_BITS};

/// The maximum length of a protobuf-encoded Tendermint validator in bytes.
const VALIDATOR_BYTE_LENGTH_MAX: usize = 47;
const VALIDATOR_BYTE_LENGTH_MAX: usize = 46;

/// The maximum length of a protobuf-encoded Tendermint validator in bits.
const VALIDATOR_BIT_LENGTH_MAX: usize = VALIDATOR_BYTE_LENGTH_MAX * 8;
Expand Down Expand Up @@ -380,7 +380,7 @@ impl<F: RichField + Extendable<D>, const D: usize> TendermintMarshaller for Circ

// Load the output of the hash.
// Note: Calculate the inner hash as if both validators are enabled.
let inner_hash = sha256(self, message_bits);
let inner_hash = sha256(self, &message_bits);

for k in 0..HASH_SIZE_BITS {
// If the left node is enabled and the right node is disabled, we pass up the left hash.
Expand Down Expand Up @@ -465,8 +465,9 @@ pub(crate) mod tests {

use crate::merkle::{hash_all_leaves, HASH_SIZE_BITS};

use plonky2_gadgets::num::u32::gadgets::arithmetic_u32::U32Target;

use crate::{
u32::U32Target,
utils::{bits_to_bytes, f_bits_to_bytes},
validator::{I64Target, TendermintMarshaller},
};
Expand Down Expand Up @@ -576,11 +577,7 @@ pub(crate) mod tests {
let config = CircuitConfig::standard_recursion_config();
let mut builder = CircuitBuilder::<F, D>::new(config);

let validators: Vec<&str> = vec![
"de6ad0941095ada2a7996e6a888581928203b8b69e07ee254d289f5b9c9caea193c2ab01902d",
"92fbe0c52937d80c5ea643c7832620b84bfdf154ec7129b8b471a63a763f2fe955af1ac65fd3",
"e902f88b2371ff6243bf4b0ebe8f46205e00749dd4dad07b2ea34350a1f9ceedb7620ab913c2",
];
let validators: Vec<&str> = vec!["6694200ba0e084f7184255abedc39af04463a4ff11e0e0c1326b1b82ea1de50c6b35cf6efa8f7ed3", "739d312e54353379a852b43de497ca4ec52bb49f59b7294a4d6cf19dd648e16cb530b7a7a1e35875d4ab4d90", "4277f2f871f3e041bcd4643c0cf18e5a931c2bfe121ce8983329a289a2b0d2161745a2ddf99bade9a1"];

let validators_bytes: Vec<Vec<u8>> = validators
.iter()
Expand Down Expand Up @@ -630,13 +627,13 @@ pub(crate) mod tests {
let config = CircuitConfig::standard_recursion_config();
let mut builder = CircuitBuilder::<F, D>::new(config);

// Generated array with byte arrays with variable length [38, 47] bytes (to mimic validator bytes), and computed the validator hash corresponding to a merkle tree of depth 2 formed by these validator bytes.
let validators: Vec<&str> = vec!["97b8cc20f17618415186ec0efca0f8a24a070b5e844f3abdaa03436c4cb58af32c3bde71e391", "5f407f30abdec9e3c4f5e8c95d0df93d5977acb7e686dd1dfc331a57f7c693756334f8252ca6b17f5a971fa891a9c7", "0daac88e983737ca1ed37da4fff6c87651deb410b3811dd6d6c0a9ff023a4655ef61d1240d60fe5f"];
// Generated array with byte arrays with variable length [38, 46] bytes (to mimic validator bytes), and computed the validator hash corresponding to a merkle tree of depth 2 formed by these validator bytes.
let validators: Vec<&str> = vec!["6694200ba0e084f7184255abedc39af04463a4ff11e0e0c1326b1b82ea1de50c6b35cf6efa8f7ed3", "739d312e54353379a852b43de497ca4ec52bb49f59b7294a4d6cf19dd648e16cb530b7a7a1e35875d4ab4d90", "4277f2f871f3e041bcd4643c0cf18e5a931c2bfe121ce8983329a289a2b0d2161745a2ddf99bade9a1"];

let (validators_target, validator_byte_length, validator_enabled) =
generate_inputs(&mut builder, &validators);

let expected_digest = "9e75a6467742596100e170527f6c74e654acf208278276025d7448d3ddb211b6";
let expected_digest = "d3430135bc6ed16a421ef1b8ec45d4d8b3e335e479f2bc3b074e9f1ed1d8f67e";
let digest_bits = to_bits(hex::decode(expected_digest).unwrap());

println!(
Expand Down Expand Up @@ -675,13 +672,13 @@ pub(crate) mod tests {
let config = CircuitConfig::standard_recursion_config();
let mut builder = CircuitBuilder::<F, D>::new(config);

// Generated array with byte arrays with variable length [38, 47] bytes (to mimic validator bytes), and computed the validator hash corresponding to a merkle tree of depth 2 formed by these validator bytes.
let validators: Vec<&str> = vec!["864711afc2c955c5bfcc65300d678ba7a5793fc74c629abaae3becaa5ac9e8d7dbd586a1e02fe7b30dd63c9f84b6ba", "b9ec50c618a22ca150f1157af35e0c530b3f7a1a96174f74aa85d86eabbe570efd36b0c73e49fc2725652f94989c"];
// Generated array with byte arrays with variable length [38, 46] bytes (to mimic validator bytes), and computed the validator hash corresponding to a merkle tree of depth 2 formed by these validator bytes.
let validators: Vec<&str> = vec!["364db94241a02b701d0dc85ac016fab2366fba326178e6f11d8294931969072b7441fd6b0ff5129d6867", "6fa0cef8f328eb8e2aef2084599662b1ee0595d842058966166029e96bd263e5367185f19af67b099645ec08aa"];

let (validators_target, validator_byte_length, validator_enabled) =
generate_inputs(&mut builder, &validators);

let expected_digest = "a47148d62d235d74db7619c00bfa0e8c6ad0564fe0ac7b81b78edfa18dd329b3";
let expected_digest = "be110ff9abb6bdeaebf48ac8e179a76fda1f6eaef0150ca6159587f489722204";
let digest_bits = to_bits(hex::decode(expected_digest).unwrap());

println!(
Expand Down

0 comments on commit 80a65d4

Please sign in to comment.