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

feat(AztecNr): create byte utils for L1<>L2 messages #2616

Open
Tracked by #5759
rahul-kothari opened this issue Oct 2, 2023 · 0 comments
Open
Tracked by #5759

feat(AztecNr): create byte utils for L1<>L2 messages #2616

rahul-kothari opened this issue Oct 2, 2023 · 0 comments
Labels
S-blocked Status: Blocked

Comments

@rahul-kothari
Copy link
Contributor

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)
}
@rahul-kothari rahul-kothari added this to A3 Oct 2, 2023
@rahul-kothari rahul-kothari converted this from a draft issue Oct 2, 2023
@rahul-kothari rahul-kothari self-assigned this Oct 2, 2023
rahul-kothari added a commit that referenced this issue Oct 2, 2023
created #2616 to create a similar method for byteutils
@rahul-kothari rahul-kothari moved this from Todo to Blocked in A3 Oct 2, 2023
Maddiaa0 pushed a commit that referenced this issue Oct 6, 2023
created #2616 to create a similar method for byteutils
@rahul-kothari rahul-kothari removed this from A3 Oct 25, 2023
@LHerskind LHerskind added the S-blocked Status: Blocked label Nov 6, 2023
@LHerskind LHerskind added this to A3 Mar 8, 2024
@github-project-automation github-project-automation bot moved this to Todo in A3 Mar 8, 2024
@LHerskind LHerskind added this to the Developer Facing Aztec.nr milestone Mar 8, 2024
@LHerskind LHerskind changed the title create byte utils for L1<>L2 messages feat(AztecNr): create byte utils for L1<>L2 messages Mar 8, 2024
@iAmMichaelConnor iAmMichaelConnor removed this from the Developer Facing Aztec.nr milestone Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked Status: Blocked
Projects
Status: Todo
Development

No branches or pull requests

3 participants