-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
394 additions
and
217 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
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
9 changes: 9 additions & 0 deletions
9
noir-projects/noir-contracts/contracts/auth_registry_contract/Nargo.toml
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,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" } |
92 changes: 92 additions & 0 deletions
92
noir-projects/noir-contracts/contracts/auth_registry_contract/src/main.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
contract AuthRegistry { | ||
use dep::aztec::{state_vars::{PublicMutable, Map}, protocol_types::address::AztecAddress}; | ||
use dep::authwit::auth::{IS_VALID_SELECTOR, compute_outer_authwit_hash}; | ||
|
||
#[aztec(storage)] | ||
struct Storage { | ||
reject_all: Map<AztecAddress, PublicMutable<bool>>, | ||
// on_behalf_of => authwit hash => authorized | ||
approved_actions: Map<AztecAddress, Map<Field, PublicMutable<bool>>>, | ||
} | ||
|
||
/** | ||
* Updates the `reject_all` value for `msg_sender`. | ||
* | ||
* When `reject_all` is `true` any `consume` on `msg_sender` will revert. | ||
* | ||
* @param reject True if all actions should be rejected, false otherwise | ||
*/ | ||
#[aztec(public)] | ||
fn set_reject_all(reject: bool) { | ||
storage.reject_all.at(context.msg_sender()).write(reject); | ||
} | ||
|
||
/** | ||
* Updates the `authorized` value for `msg_sender` for `messageHash`. | ||
* | ||
* @param message_hash The message hash being authorized | ||
* @param authorize True if the caller is authorized to perform the message hash, false otherwise | ||
*/ | ||
#[aztec(public)] | ||
fn set_authorized(message_hash: Field, authorize: bool) { | ||
storage.approved_actions.at(context.msg_sender()).at(message_hash).write(authorize); | ||
} | ||
|
||
/** | ||
* Consumes an `inner_hash` on behalf of `on_behalf_of` if the caller is authorized to do so. | ||
* | ||
* Will revert even if the caller is authorized if `reject_all` is set to true for `on_behalf_of`. | ||
* This is to support "mass-revoke". | ||
* | ||
* @param on_behalf_of The address on whose behalf the action is being consumed | ||
* @param inner_hash The inner_hash of the authwit | ||
* @return `IS_VALID_SELECTOR` if the action was consumed, revert otherwise | ||
*/ | ||
#[aztec(public)] | ||
fn consume(on_behalf_of: AztecAddress, inner_hash: Field) -> Field { | ||
assert_eq(false, storage.reject_all.at(on_behalf_of).read(), "rejecting all"); | ||
|
||
let message_hash = compute_outer_authwit_hash( | ||
context.msg_sender(), | ||
context.chain_id(), | ||
context.version(), | ||
inner_hash | ||
); | ||
|
||
let authorized = storage.approved_actions.at(on_behalf_of).at(message_hash).read(); | ||
|
||
assert_eq(true, authorized, "unauthorized"); | ||
storage.approved_actions.at(on_behalf_of).at(message_hash).write(false); | ||
|
||
IS_VALID_SELECTOR | ||
} | ||
|
||
/** | ||
* Fetches the `reject_all` value for `on_behalf_of`. | ||
* | ||
* @param on_behalf_of The address to check | ||
* @return True if all actions are rejected, false otherwise | ||
*/ | ||
#[aztec(public)] | ||
#[aztec(view)] | ||
fn is_reject_all(on_behalf_of: AztecAddress) -> bool { | ||
storage.reject_all.at(on_behalf_of).read() | ||
} | ||
|
||
/* | ||
* Fetches the `authorized` value for `on_behalf_of` for `message_hash`. | ||
* | ||
* @param on_behalf_of The address on whose behalf the action is being consumed | ||
* @param message_hash The message hash to check | ||
* @return True if the caller is authorized to perform the action, false otherwise | ||
*/ | ||
#[aztec(public)] | ||
#[aztec(view)] | ||
fn is_consumable(on_behalf_of: AztecAddress, message_hash: Field) -> bool { | ||
storage.approved_actions.at(on_behalf_of).at(message_hash).read() | ||
} | ||
|
||
unconstrained fn unconstrained_is_consumable(on_behalf_of: AztecAddress, message_hash: Field) -> pub bool { | ||
storage.approved_actions.at(on_behalf_of).at(message_hash).read() | ||
} | ||
} |
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
Oops, something went wrong.