-
Notifications
You must be signed in to change notification settings - Fork 610
refactor: Update authwit computation #2651
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fc0522a
refactor: Update authwit computation
LHerskind 636f2f4
chore: move `computeAuthWitHash` to aztec.js utils
LHerskind 7b64e57
chore: linter
LHerskind 4164e93
chore: align function auth with function naming
LHerskind 1bbf745
chore: naming improvement 🤞
LHerskind b7dfd2b
chore: add todo and ref in auth.nr
LHerskind 7f66228
chore: make Rahul happy
LHerskind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [package] | ||
| name = "auth_wit" | ||
| authors = ["aztec-labs"] | ||
| compiler_version = "0.1" | ||
| type = "lib" | ||
|
|
||
| [dependencies] | ||
| aztec = { path = "../aztec" } |
12 changes: 8 additions & 4 deletions
12
yarn-project/aztec-nr/aztec/src/account.nr → yarn-project/aztec-nr/authwit/src/account.nr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| use dep::std::hash::pedersen_with_separator; | ||
|
|
||
| use dep::aztec::{ | ||
| context::{PrivateContext, PublicContext, Context}, | ||
| constants_gen::{EMPTY_NULLIFIED_COMMITMENT, GENERATOR_INDEX__SIGNATURE_PAYLOAD}, | ||
| types::address::AztecAddress, | ||
| abi::hash_args, | ||
| }; | ||
|
|
||
| global IS_VALID_SELECTOR = 0xe86ab4ff; | ||
| global IS_VALID_PUBLIC_SELECTOR = 0xf3661153; | ||
|
|
||
| // @todo #2676 Should use different generator than the payload to limit probability of collisions. | ||
|
|
||
| // Assert that `whom` have authorized `message_hash` with a valid authentication witness | ||
| fn assert_valid_authwit(context: &mut PrivateContext, whom: AztecAddress, message_hash: Field) { | ||
| let result = context.call_private_function(whom.address, IS_VALID_SELECTOR, [message_hash])[0]; | ||
| context.push_new_nullifier(message_hash, EMPTY_NULLIFIED_COMMITMENT); | ||
| assert(result == IS_VALID_SELECTOR, "Message not authorized by account"); | ||
| } | ||
|
|
||
| // Assert that `whom` have authorized the current call with a valid authentication witness | ||
| fn assert_current_call_valid_authwit(context: &mut PrivateContext, whom: AztecAddress) { | ||
| let args = [context.msg_sender(), context.this_address(), context.selector(), context.args_hash]; | ||
| let message_hash = pedersen_with_separator(args, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0]; | ||
| assert_valid_authwit(context, whom, message_hash); | ||
| } | ||
|
|
||
| // Assert that `whom` have authorized `message_hash` in a public context | ||
| fn assert_valid_authwit_public(context: &mut PublicContext, whom: AztecAddress, message_hash: Field) { | ||
| let result = context.call_public_function(whom.address, IS_VALID_PUBLIC_SELECTOR, [message_hash])[0]; | ||
| context.push_new_nullifier(message_hash, EMPTY_NULLIFIED_COMMITMENT); | ||
| assert(result == IS_VALID_SELECTOR, "Message not authorized by account"); | ||
| } | ||
|
|
||
| // Assert that `whom` have authorized the current call in a public context | ||
| fn assert_current_call_valid_authwit_public(context: &mut PublicContext, whom: AztecAddress) { | ||
| let args = [context.msg_sender(), context.this_address(), context.selector(), context.args_hash]; | ||
| let message_hash = pedersen_with_separator(args, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0]; | ||
| assert_valid_authwit_public(context, whom, message_hash); | ||
| } | ||
|
|
||
| // Compute the message hash to be used by an authentication witness | ||
| fn compute_authwit_message_hash<N>(caller: AztecAddress, target: AztecAddress, selector: Field, args: [Field; N]) -> Field { | ||
| let args_hash = hash_args(args); | ||
| pedersen_with_separator([caller.address, target.address, selector, args_hash], GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0] | ||
| } | ||
File renamed without changes.
12 changes: 6 additions & 6 deletions
12
...-project/aztec-nr/aztec/src/entrypoint.nr → ...roject/aztec-nr/authwit/src/entrypoint.nr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| mod account; | ||
| mod auth_witness; | ||
| mod auth; | ||
| mod entrypoint; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { AztecAddress, CircuitsWasm, GeneratorIndex } from '@aztec/circuits.js'; | ||
| import { pedersenPlookupCompressWithHashIndex } from '@aztec/circuits.js/barretenberg'; | ||
| import { FunctionCall, PackedArguments } from '@aztec/types'; | ||
|
|
||
| /** | ||
| * Compute an authentication witness message hash from a caller and a request | ||
| * H(caller: AztecAddress, target: AztecAddress, selector: Field, args_hash: Field) | ||
| * @param caller - The caller approved to make the call | ||
| * @param request - The request to be made (function call) | ||
| * @returns The message hash for the witness | ||
| */ | ||
| export const computeAuthWitMessageHash = async (caller: AztecAddress, request: FunctionCall) => { | ||
| const wasm = await CircuitsWasm.get(); | ||
| return pedersenPlookupCompressWithHashIndex( | ||
| wasm, | ||
| [ | ||
| caller.toField(), | ||
| request.to.toField(), | ||
| request.functionData.selector.toField(), | ||
| (await PackedArguments.fromArgs(request.args, wasm)).hash, | ||
| ].map(fr => fr.toBuffer()), | ||
| GeneratorIndex.SIGNATURE_PAYLOAD, | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously we had a TODO here reminding us to reconsider if this is the best pederson generator. Is that not the case anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a todo in the tracking issue, have created #2676 now, and will ref that.