Skip to content

Commit

Permalink
fix: workaround for noir issue with slices
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant committed Aug 24, 2023
1 parent 2c5c10f commit 8839fd5
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 177 deletions.
71 changes: 3 additions & 68 deletions yarn-project/aztec.js/src/abis/ecdsa_account_contract.json

Large diffs are not rendered by default.

69 changes: 2 additions & 67 deletions yarn-project/aztec.js/src/abis/schnorr_account_contract.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ contract EcdsaAccount {
// Note that noir expects the hash of the message/challenge as input to the ECDSA verification.
let payload_fields: [Field; entrypoint::ENTRYPOINT_PAYLOAD_SIZE] = payload.serialize();
let message_field: Field = std::hash::pedersen_with_separator(payload_fields, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0];
let message_bytes = message_field.to_be_bytes(32);
// TODO workaround for https://github.com/noir-lang/noir/issues/2421
let message_bytes_slice = message_field.to_be_bytes(32);
let mut message_bytes: [u8; 32] = [0; 32];
for i in 0..32 {
message_bytes[i] = message_bytes_slice[i];
}
let hashed_message: [u8; 32] = std::hash::sha256(message_bytes);
let verification = std::ecdsa_secp256k1::verify_signature(public_key.x, public_key.y, signature, hashed_message);
assert(verification == true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ contract SchnorrAccount {
// Verify payload signature
let payload_fields: [Field; entrypoint::ENTRYPOINT_PAYLOAD_SIZE] = payload.serialize();
let message_field: Field = std::hash::pedersen_with_separator(payload_fields, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0];
let message_bytes = message_field.to_be_bytes(32);
// TODO workaround for https://github.com/noir-lang/noir/issues/2421
let message_bytes_slice = message_field.to_be_bytes(32);
let mut message_bytes: [u8; 32] = [0; 32];
for i in 0..32 {
message_bytes[i] = message_bytes_slice[i];
}

// Verify signature of the payload bytes
let verification = std::schnorr::verify_signature(public_key.x, public_key.y, signature, message_bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ contract SchnorrSingleKeyAccount {
// Verify payload signature
let payload_fields: [Field; entrypoint::ENTRYPOINT_PAYLOAD_SIZE] = payload.serialize();
let message_field: Field = std::hash::pedersen_with_separator(payload_fields, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0];
let message_bytes = message_field.to_be_bytes(32);
// TODO workaround for https://github.com/noir-lang/noir/issues/2421
let message_bytes_slice = message_field.to_be_bytes(32);
let mut message_bytes: [u8; 32] = [0; 32];
for i in 0..32 {
message_bytes[i] = message_bytes_slice[i];
}

// Convert owner pubkey into fields
let mut x: Field = 0;
Expand All @@ -50,7 +55,6 @@ contract SchnorrSingleKeyAccount {
}

// Verify signature of the payload hash
// TODO: Find out why this signature verification never fails
let verification = std::schnorr::verify_signature(x, y, signature, message_bytes);
assert(verification == true);

Expand Down
2 changes: 2 additions & 0 deletions yarn-project/noir-contracts/src/scripts/copy_output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function writeToProject(abi: any) {
const toWrite = {
...abi,
functions: abi.functions.map((f: any) => omit(f, projectContract.exclude)),
// If we maintain debug symbols they will get commited to git.
debug: undefined,
};
const targetFilename = pathJoin(projectContract.target, `${snakeCase(abi.name)}_contract.json`);
writeFileSync(targetFilename, JSON.stringify(toWrite, null, 2) + '\n');
Expand Down

0 comments on commit 8839fd5

Please sign in to comment.