-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Update authwit computation (#2651)
Fixes #2448
- Loading branch information
Showing
38 changed files
with
354 additions
and
537 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.