-
Notifications
You must be signed in to change notification settings - Fork 316
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: auth registry #7035
feat: auth registry #7035
Changes from 6 commits
ddf69f4
7d4b657
e495960
f131a12
2f05bcc
8c33bae
1b2245f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use dep::aztec::protocol_types::{ | ||
abis::function_selector::FunctionSelector, address::AztecAddress, | ||
constants::{GENERATOR_INDEX__AUTHWIT_INNER, GENERATOR_INDEX__AUTHWIT_OUTER}, hash::pedersen_hash | ||
constants::{GENERATOR_INDEX__AUTHWIT_INNER, GENERATOR_INDEX__AUTHWIT_OUTER, CANONICAL_AUTH_REGISTRY_ADDRESS}, | ||
hash::pedersen_hash | ||
}; | ||
use dep::aztec::{prelude::Deserialize, context::{PrivateContext, PublicContext, gas::GasOpts}, hash::hash_args_array}; | ||
|
||
|
@@ -19,14 +20,14 @@ pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf | |
// docs:start:assert_current_call_valid_authwit_public | ||
// Assert that `on_behalf_of` have authorized the current call in a public context | ||
pub fn assert_current_call_valid_authwit_public(context: &mut PublicContext, on_behalf_of: AztecAddress) { | ||
let function_selector = FunctionSelector::from_signature("spend_public_authwit(Field)"); | ||
let inner_hash = compute_inner_authwit_hash( | ||
[(*context).msg_sender().to_field(), (*context).selector().to_field(), (*context).get_args_hash()] | ||
); | ||
|
||
let result: Field = context.call_public_function( | ||
on_behalf_of, | ||
function_selector, | ||
[inner_hash].as_slice(), | ||
AztecAddress::from_field(CANONICAL_AUTH_REGISTRY_ADDRESS), | ||
FunctionSelector::from_signature("consume((Field),Field)"), | ||
[on_behalf_of.to_field(), inner_hash].as_slice(), | ||
GasOpts::default() | ||
).deserialize_into(); | ||
assert(result == IS_VALID_SELECTOR, "Message not authorized by account"); | ||
|
@@ -69,3 +70,32 @@ pub fn compute_outer_authwit_hash( | |
GENERATOR_INDEX__AUTHWIT_OUTER | ||
) | ||
} | ||
|
||
/** | ||
* Helper function to set the authorization status of a message hash | ||
* | ||
* @param message_hash The hash of the message to authorize | ||
* @param authorize True if the message should be authorized, false if it should be revoked | ||
*/ | ||
pub fn set_authorized(context: &mut PublicContext, message_hash: Field, authorize: bool) { | ||
context.call_public_function( | ||
AztecAddress::from_field(CANONICAL_AUTH_REGISTRY_ADDRESS), | ||
FunctionSelector::from_signature("set_authorized(Field,bool)"), | ||
[message_hash, authorize as Field].as_slice(), | ||
GasOpts::default() | ||
).assert_empty(); | ||
} | ||
|
||
/** | ||
* Helper function to reject all authwits | ||
* | ||
* @param reject True if all authwits should be rejected, false otherwise | ||
*/ | ||
pub fn set_reject_all(context: &mut PublicContext, reject: bool) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this is a bit confusing because from looking at it I would guess that all the authwits are nullified for good. But this essentially just makes them unspendable until you set reject to false again. What is the intention here? Is it to give user a time to manually deauthorize all the authwits? Or is the expectation that user just sets this and then never sets any public authwits with that particular account? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The expectation is that it is a "panic-button" making it easy for a user to make sure their funds stays put, and then can then handle them as they want in the tempo they desire. |
||
context.call_public_function( | ||
AztecAddress::from_field(CANONICAL_AUTH_REGISTRY_ADDRESS), | ||
FunctionSelector::from_signature("set_reject_all(bool)"), | ||
[context.this_address().to_field(), reject as Field].as_slice(), | ||
GasOpts::default() | ||
).assert_empty(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "auth_registry_contract" | ||
authors = [""] | ||
compiler_version = ">=0.25.0" | ||
type = "contract" | ||
|
||
[dependencies] | ||
aztec = { path = "../../../aztec-nr/aztec" } | ||
authwit = { path = "../../../aztec-nr/authwit" } |
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.