You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similar to abi.encodeWithSelector - makes L1<>L2 messages easier
// Compute sha256 hash to a field for a message with a 4 bytes of function selector and a number of arguments
// Useful for content hash used in L1<>L2 messages
fn compute_sha256_hash_for_function_signature<N>(selector: Field, args: [Field; N]) -> Field {
let len = 4 + (N*32);
let mut bytes_to_hash: [u8; len] = [0; len];
// copy first 4 bytes of selector:
let selector_in_bytes = selector.to_be_bytes(4);
for i in 0..4 {
bytes_to_hash[i] = selector_in_bytes[i];
}
// copy the args:
for i in 0..N {
let offset = 4 + i*32;
let arg_in_bytes = args[i].to_be_bytes(32);
for j in 0..32 {
bytes_to_hash[offset + j] = arg_in_bytes[j];
}
}
sha256_to_field(bytes_to_hash)
}
The text was updated successfully, but these errors were encountered:
Similar to abi.encodeWithSelector - makes L1<>L2 messages easier
The text was updated successfully, but these errors were encountered: