Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace AztecU128 with U128 #3951

Merged
merged 8 commits into from
Jan 15, 2024
11 changes: 11 additions & 0 deletions noir/noir_stdlib/src/uint128.nr
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ impl U128 {
}
}

pub fn to_be_bytes(self: Self) -> [u8; 16] {
let lo = self.lo.to_be_bytes(8);
let hi = self.hi.to_be_bytes(8);
let mut bytes = [0;16];
for i in 0..8 {
bytes[i] = hi[i];
bytes[i+8] = lo[i];
}
bytes
}

pub fn to_le_bytes(self: Self) -> [u8; 16] {
let lo = self.lo.to_le_bytes(8);
let hi = self.hi.to_le_bytes(8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use dep::types::{
utils::{
arrays::{array_length, array_to_bounded_vec},
bounded_vec::BoundedVec,
uint128::AztecU128,
},
traits::is_empty_array
};
Expand Down Expand Up @@ -280,10 +279,10 @@ pub fn accumulate_unencrypted_logs(

let current_unencrypted_logs_hash = public_call_public_inputs.unencrypted_logs_hash;
public_inputs.end.unencrypted_logs_hash = accumulate_sha256([
AztecU128::from_field(previous_unencrypted_logs_hash[0]),
AztecU128::from_field(previous_unencrypted_logs_hash[1]),
AztecU128::from_field(current_unencrypted_logs_hash[0]),
AztecU128::from_field(current_unencrypted_logs_hash[1])
U128::from_integer(previous_unencrypted_logs_hash[0]),
U128::from_integer(previous_unencrypted_logs_hash[1]),
U128::from_integer(current_unencrypted_logs_hash[0]),
U128::from_integer(current_unencrypted_logs_hash[1])
]);

// Add log preimages lengths from current iteration to accumulated lengths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ struct BaseOrMergeRollupPublicInputs {
end: PartialStateReference,

// We hash public inputs to make them constant-sized (to then be unpacked on-chain)
// AztecU128 isn't safe if it's an input to the circuit (it won't automatically constrain the witness)
// So we want to constrain it when casting these fields to AztecU128
// U128 isn't safe if it's an input to the circuit (it won't automatically constrain the witness)
// So we want to constrain it when casting these fields to U128

TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
// TODO(#3938): split this to txs_hash and out_hash
// We hash public inputs to make them constant-sized (to then be unpacked on-chain)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs;
use dep::types::mocked::AggregationObject;
use dep::types::hash::{accumulate_sha256, assert_check_membership, root_from_sibling_path};
use dep::types::utils::uint128::AztecU128;
use dep::types::constants::NUM_FIELDS_PER_SHA256;
use crate::abis::previous_rollup_data::PreviousRollupData;
use dep::types::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot;
Expand Down Expand Up @@ -86,10 +85,10 @@ pub fn assert_prev_rollups_follow_on_from_each_other(
pub fn compute_calldata_hash(previous_rollup_data: [PreviousRollupData; 2]) -> [Field; NUM_FIELDS_PER_SHA256] {
accumulate_sha256(
[
AztecU128::from_field(previous_rollup_data[0].base_or_merge_rollup_public_inputs.calldata_hash[0]),
AztecU128::from_field(previous_rollup_data[0].base_or_merge_rollup_public_inputs.calldata_hash[1]),
AztecU128::from_field(previous_rollup_data[1].base_or_merge_rollup_public_inputs.calldata_hash[0]),
AztecU128::from_field(previous_rollup_data[1].base_or_merge_rollup_public_inputs.calldata_hash[1])
U128::from_integer(previous_rollup_data[0].base_or_merge_rollup_public_inputs.calldata_hash[0]),
U128::from_integer(previous_rollup_data[0].base_or_merge_rollup_public_inputs.calldata_hash[1]),
U128::from_integer(previous_rollup_data[1].base_or_merge_rollup_public_inputs.calldata_hash[0]),
U128::from_integer(previous_rollup_data[1].base_or_merge_rollup_public_inputs.calldata_hash[1])
]
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ mod tests {
tests::merge_rollup_inputs::default_merge_rollup_inputs,
};
use dep::types::hash::accumulate_sha256;
use dep::types::utils::uint128::AztecU128;

#[test(should_fail_with="input proofs are of different rollup types")]
fn different_rollup_type_fails() {
Expand Down Expand Up @@ -141,10 +140,10 @@ mod tests {
let mut inputs = default_merge_rollup_inputs();
let expected_calldata_hash = accumulate_sha256(
[
AztecU128::from_field(0),
AztecU128::from_field(1),
AztecU128::from_field(2),
AztecU128::from_field(3)
U128::from_integer(0),
U128::from_integer(1),
U128::from_integer(2),
U128::from_integer(3)
]
);
let outputs = inputs.merge_rollup_circuit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ mod tests {
},
tests::root_rollup_inputs::default_root_rollup_inputs,
};
use dep::types::utils::uint128::AztecU128;
use dep::types::utils::uint256::U256;
use dep::types::hash::accumulate_sha256;

Expand All @@ -146,10 +145,10 @@ mod tests {

let expected_calldata_hash = accumulate_sha256(
[
AztecU128::from_field(0),
AztecU128::from_field(1),
AztecU128::from_field(2),
AztecU128::from_field(3)
U128::from_integer(0),
U128::from_integer(1),
U128::from_integer(2),
U128::from_integer(3)
]
);

Expand Down
13 changes: 6 additions & 7 deletions yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::abis::function_leaf_preimage::FunctionLeafPreimage;
use crate::abis::new_contract_data::NewContractData as ContractLeafPreimage;
use crate::abis::function_data::FunctionData;
use crate::abis::side_effect::{SideEffect};
use crate::utils::uint128::AztecU128;
use crate::utils::uint256::U256;
use crate::utils::bounded_vec::BoundedVec;
use crate::constants::{
Expand Down Expand Up @@ -243,9 +242,9 @@ pub fn compute_constructor_hash(
// Returning a Field would be desirable because then this can be replaced with
// poseidon without changing the rest of the code
//
pub fn accumulate_sha256(input: [AztecU128; 4]) -> [Field; NUM_FIELDS_PER_SHA256] {
pub fn accumulate_sha256(input: [U128; 4]) -> [Field; NUM_FIELDS_PER_SHA256] {
// This is a note about the cpp code, since it takes an array of Fields
// instead of a AztecU128.
// instead of a U128.
// 4 Field elements when converted to bytes will usually
// occupy 4 * 32 = 128 bytes.
// However, this function is making the assumption that each Field
Expand Down Expand Up @@ -273,10 +272,10 @@ pub fn compute_logs_hash(
) -> [Field; NUM_FIELDS_PER_SHA256] {
accumulate_sha256(
[
AztecU128::from_field(previous_log_hash[0]),
AztecU128::from_field(previous_log_hash[1]),
AztecU128::from_field(current_log_hash[0]),
AztecU128::from_field(current_log_hash[1])
U128::from_integer(previous_log_hash[0]),
U128::from_integer(previous_log_hash[1]),
U128::from_integer(current_log_hash[0]),
U128::from_integer(current_log_hash[1])
]
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
mod arrays;
mod bounded_vec;
mod field;
mod uint128;
mod uint256;

// if predicate == true then return lhs, else return rhs
Expand Down

This file was deleted.