Skip to content

Commit

Permalink
chore: use external keccak256 lib (#11954)
Browse files Browse the repository at this point in the history
This PR uses https://github.com/noir-lang/keccak256 as a replacement for
the stdlib version of this function which will soon be deprecated and
removed.
  • Loading branch information
TomAFrench authored Feb 13, 2025
1 parent 438c905 commit b613bb6
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ type = "contract"

[dependencies]
aztec = { path = "../../../aztec-nr/aztec" }
keccak256 = { tag = "v0.1.0", git = "https://github.com/noir-lang/keccak256" }
sha256 = { tag = "v0.1.2", git = "https://github.com/noir-lang/sha256" }
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ contract AvmGadgetsTest {

#[public]
fn keccak_hash(data: [u8; 10]) -> [u8; 32] {
std::hash::keccak256(data, data.len() as u32)
keccak256::keccak256(data, data.len())
}

#[public]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ type = "contract"
aztec = { path = "../../../aztec-nr/aztec" }
compressed_string = { path = "../../../aztec-nr/compressed-string" }
sha256 = { tag = "v0.1.2", git = "https://github.com/noir-lang/sha256" }
keccak256 = { tag = "v0.1.0", git = "https://github.com/noir-lang/keccak256" }
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ pub contract AvmTest {
dep::aztec::oracle::debug_log::debug_log("read_storage_map");
let _ = read_storage_map(context.this_address());
dep::aztec::oracle::debug_log::debug_log("keccak_hash");
let _ = std::hash::keccak256(args_u8, args_u8.len());
let _ = keccak256::keccak256(args_u8, args_u8.len());
dep::aztec::oracle::debug_log::debug_log("sha256_hash");
let _ = sha256::sha256_var(args_u8, args_u8.len() as u64);
dep::aztec::oracle::debug_log::debug_log("poseidon2_hash");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ aztec = { path = "../../../aztec-nr/aztec" }
authwit = { path = "../../../aztec-nr/authwit" }
deployer = { path = "../contract_instance_deployer_contract" }
registerer = { path = "../contract_class_registerer_contract" }
keccak256 = { tag = "v0.1.0", git = "https://github.com/noir-lang/keccak256" }
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn get_bridge_gas_msg_hash(owner: AztecAddress, amount: U128) -> Field {

// The purpose of including the following selector is to make the message unique to that specific call. Note that
// it has nothing to do with calling the function.
let selector = comptime { std::hash::keccak256("claim(bytes32,uint256)".as_bytes(), 22) };
let selector = comptime { keccak256::keccak256("claim(bytes32,uint256)".as_bytes(), 22) };

for i in 0..4 {
hash_bytes[i] = selector[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ type = "lib"

[dependencies]
aztec = { path = "../../../aztec-nr/aztec" }
keccak256 = { tag = "v0.1.0", git = "https://github.com/noir-lang/keccak256" }
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn get_mint_to_public_content_hash(owner: AztecAddress, amount: U128) -> Fie

// The purpose of including the following selector is to make the message unique to that specific call. Note that
// it has nothing to do with calling the function.
let selector = comptime { std::hash::keccak256("mint_to_public(bytes32,uint256)".as_bytes(), 31) };
let selector = comptime { keccak256::keccak256("mint_to_public(bytes32,uint256)".as_bytes(), 31) };

for i in 0..4 {
hash_bytes[i] = selector[i];
Expand All @@ -36,7 +36,7 @@ pub fn get_mint_to_private_content_hash(amount: U128) -> Field {

// The purpose of including the following selector is to make the message unique to that specific call. Note that
// it has nothing to do with calling the function.
let selector = comptime { std::hash::keccak256("mint_to_private(uint256)".as_bytes(), 24) };
let selector = comptime { keccak256::keccak256("mint_to_private(uint256)".as_bytes(), 24) };

for i in 0..4 {
hash_bytes[i] = selector[i];
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn get_withdraw_content_hash(recipient: EthAddress, amount: U128, caller_on_

// The purpose of including the following selector is to make the message unique to that specific call. Note that
// it has nothing to do with calling the function.
let selector = comptime { std::hash::keccak256("withdraw(address,uint256,address)".as_bytes(), 33) };
let selector = comptime { keccak256::keccak256("withdraw(address,uint256,address)".as_bytes(), 33) };

for i in 0..4 {
hash_bytes[i] = selector[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ type = "contract"
aztec = { path = "../../../aztec-nr/aztec" }
authwit = { path = "../../../aztec-nr/authwit" }
token = { path = "../token_contract" }
token_bridge = { path = "../token_bridge_contract" }
token_bridge = { path = "../token_bridge_contract" }
keccak256 = { tag = "v0.1.0", git = "https://github.com/noir-lang/keccak256" }
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn compute_swap_public_content_hash(
// The purpose of including the following selector is to make the message unique to that specific call. Note that
// it has nothing to do with calling the function.
let selector = comptime {
std::hash::keccak256(
keccak256::keccak256(
"swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)".as_bytes(),
75,
)
Expand Down Expand Up @@ -84,7 +84,7 @@ pub fn compute_swap_private_content_hash(
// The purpose of including the following selector is to make the message unique to that specific call. Note that
// it has nothing to do with calling the function.
let selector = comptime {
std::hash::keccak256(
keccak256::keccak256(
"swap_private(address,uint256,uint24,address,uint256,bytes32,address)".as_bytes(),
68,
)
Expand Down

0 comments on commit b613bb6

Please sign in to comment.