Skip to content

Commit

Permalink
chore: small cleanup (#8965)
Browse files Browse the repository at this point in the history
Please read [contributing guidelines](CONTRIBUTING.md) and remove this
line.
  • Loading branch information
fcarreiro authored Oct 2, 2024
1 parent 797d0ca commit 8031ef4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::protocol_types::{
hash::{poseidon2_hash, poseidon2_hash_with_separator}, address::AztecAddress,
traits::{FromField, ToField}
traits::{FromField, ToField}, utils::arrays::array_concat
};

use crate::context::{PrivateContext, PublicContext, UnconstrainedContext};
Expand Down Expand Up @@ -32,17 +32,6 @@ global HASH_SEPARATOR: u32 = 2;
// can actually use it here
impl<T, let INITIAL_DELAY: u32, Context> Storage<T> for SharedMutable<T, INITIAL_DELAY, Context> {}

fn concat_arrays<let N: u32, let M: u32>(arr_n: [Field; N], arr_m: [Field; M]) -> [Field; N + M] {
let mut out: [Field; N + M] = [0; N + M];
for i in 0..N {
out[i] = arr_n[i];
}
for i in 0..M {
out[N+i] = arr_m[i];
}
out
}

// SharedMutable<T> stores a value of type T that is:
// - publicly known (i.e. unencrypted)
// - mutable in public
Expand Down Expand Up @@ -220,7 +209,7 @@ impl<T, let INITIAL_DELAY: u32> SharedMutable<T, INITIAL_DELAY, &mut PrivateCont
value_change: ScheduledValueChange<T>,
delay_change: ScheduledDelayChange<INITIAL_DELAY>
) -> Field {
let concatenated: [Field; 4] = concat_arrays(value_change.serialize(), delay_change.serialize());
let concatenated: [Field; 4] = array_concat(value_change.serialize(), delay_change.serialize());
poseidon2_hash(concatenated)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,3 @@ pub use eth_address::EthAddress;
pub use partial_address::PartialAddress;
pub use public_keys_hash::PublicKeysHash;
pub use salted_initialization_hash::SaltedInitializationHash;

use crate::{constants::GENERATOR_INDEX__CONSTRUCTOR, hash::poseidon2_hash_with_separator};

pub fn compute_initialization_hash(selector: Field, args_hash: Field) -> Field {
poseidon2_hash_with_separator(
[
selector,
args_hash
],
GENERATOR_INDEX__CONSTRUCTOR
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ pub fn array_length<T, let N: u32>(array: [T; N]) -> u32 where T: Empty + Eq {
length
}

pub fn array_concat<T, let N: u32, let M: u32, let S: u32>(array1: [T; N], array2: [T; M]) -> [T; S] {
assert_eq(N + M, S, "combined array length does not match return array length");
let mut result = [array1[0]; S];
pub fn array_concat<T, let N: u32, let M: u32>(array1: [T; N], array2: [T; M]) -> [T; N + M] {
let mut result = [array1[0]; N + M];
for i in 1..N {
result[i] = array1[i];
}
Expand Down Expand Up @@ -228,13 +227,6 @@ fn test_array_concat() {
assert_eq(concated, [1, 2, 3, 4, 5]);
}

#[test(should_fail_with="combined array length does not match return array length")]
fn array_concat_fails_inconsistent_lengths() {
let array0 = [1, 2, 3];
let array1 = [4, 5];
let _concated: [Field; 4] = array_concat(array0, array1);
}

#[test]
fn check_permutation_basic_test() {
let original_array = [1, 2, 3];
Expand Down

0 comments on commit 8031ef4

Please sign in to comment.