From efd70f4b8bb284815c5345bd16d79018ed2dd812 Mon Sep 17 00:00:00 2001 From: Lasse Herskind <16536249+LHerskind@users.noreply.github.com> Date: Wed, 28 Feb 2024 09:02:55 +0100 Subject: [PATCH] feat: AUTHWIT generator (#4798) Fixes #2676 by using a different index for the pedersen hash. --- noir-projects/aztec-nr/authwit/src/auth.nr | 8 ++++---- .../src/crates/types/src/constants.nr | 1 + yarn-project/aztec.js/src/utils/authwit.ts | 2 +- yarn-project/circuits.js/src/constants.gen.ts | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/noir-projects/aztec-nr/authwit/src/auth.nr b/noir-projects/aztec-nr/authwit/src/auth.nr index 99b07bf11a8..34af8aa8bf9 100644 --- a/noir-projects/aztec-nr/authwit/src/auth.nr +++ b/noir-projects/aztec-nr/authwit/src/auth.nr @@ -1,6 +1,6 @@ use dep::aztec::protocol_types::{ abis::function_selector::FunctionSelector, address::AztecAddress, - constants::{GENERATOR_INDEX__SIGNATURE_PAYLOAD}, hash::{hash_args, pedersen_hash} + constants::{GENERATOR_INDEX__AUTHWIT}, hash::{hash_args, pedersen_hash} }; use dep::aztec::context::{PrivateContext, PublicContext, Context}; @@ -31,7 +31,7 @@ pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf [ context.msg_sender().to_field(), context.this_address().to_field(), context.selector().to_field(), context.args_hash ], - GENERATOR_INDEX__SIGNATURE_PAYLOAD + GENERATOR_INDEX__AUTHWIT ); assert_valid_authwit(context, on_behalf_of, message_hash); } @@ -55,7 +55,7 @@ pub fn assert_current_call_valid_authwit_public(context: &mut PublicContext, on_ [ context.msg_sender().to_field(), context.this_address().to_field(), context.selector().to_field(), context.args_hash ], - GENERATOR_INDEX__SIGNATURE_PAYLOAD + GENERATOR_INDEX__AUTHWIT ); assert_valid_authwit_public(context, on_behalf_of, message_hash); } @@ -72,7 +72,7 @@ pub fn compute_authwit_message_hash( let args_hash = hash_args(args); pedersen_hash( [caller.to_field(), target.to_field(), selector.to_field(), args_hash], - GENERATOR_INDEX__SIGNATURE_PAYLOAD + GENERATOR_INDEX__AUTHWIT ) } // docs:end:compute_authwit_message_hash diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr index 690da1a59d5..49fcbd999bf 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr @@ -232,3 +232,4 @@ global GENERATOR_INDEX__VK = 41; global GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS = 42; global GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS = 43; global GENERATOR_INDEX__FUNCTION_ARGS = 44; +global GENERATOR_INDEX__AUTHWIT = 45; diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts index f449a429b2b..79898897e9a 100644 --- a/yarn-project/aztec.js/src/utils/authwit.ts +++ b/yarn-project/aztec.js/src/utils/authwit.ts @@ -18,7 +18,7 @@ export const computeAuthWitMessageHash = (caller: AztecAddress, request: Functio request.functionData.selector.toField(), PackedArguments.fromArgs(request.args).hash, ].map(fr => fr.toBuffer()), - GeneratorIndex.SIGNATURE_PAYLOAD, + GeneratorIndex.AUTHWIT, ); }; // docs:end:authwit_computeAuthWitMessageHash diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 5213d7fe103..d4c77e327b6 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -145,4 +145,5 @@ export enum GeneratorIndex { PRIVATE_CIRCUIT_PUBLIC_INPUTS = 42, PUBLIC_CIRCUIT_PUBLIC_INPUTS = 43, FUNCTION_ARGS = 44, + AUTHWIT = 45, }