-
Notifications
You must be signed in to change notification settings - Fork 306
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: pay fee when deploying account contracts #5540
Changes from all commits
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ use dep::aztec::protocol_types::{address::AztecAddress, abis::function_selector: | |
use crate::entrypoint::{app::AppPayload, fee::FeePayload}; | ||
use crate::auth::{IS_VALID_SELECTOR, compute_outer_authwit_hash}; | ||
|
||
use crate::capsule::pop_capsule; | ||
|
||
struct AccountActions { | ||
context: Context, | ||
is_valid_impl: fn(&mut PrivateContext, Field) -> bool, | ||
|
@@ -54,6 +56,17 @@ impl AccountActions { | |
) | ||
} | ||
|
||
pub fn initialize_account_contract(self) { | ||
let valid_fn = self.is_valid_impl; | ||
let mut private_context = self.context.private.unwrap(); | ||
|
||
let fee_payload = FeePayload::deserialize(pop_capsule()); | ||
let fee_hash = fee_payload.hash(); | ||
Comment on lines
+63
to
+64
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 think I'm starting to agree with Joe on this use case for capsules. The 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 think the tasks for this would be:
It's quite a lot unfortunately, but feels cleaner..? 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.
lol same, but I was actually thinking of going the protocol contract route instead of adding a new macro 😅 |
||
assert(valid_fn(private_context, fee_hash)); | ||
fee_payload.execute_calls(private_context); | ||
private_context.capture_min_revertible_side_effect_counter(); | ||
} | ||
|
||
// docs:start:entrypoint | ||
pub fn entrypoint(self, app_payload: AppPayload, fee_payload: FeePayload) { | ||
let valid_fn = self.is_valid_impl; | ||
|
@@ -73,7 +86,7 @@ impl AccountActions { | |
// docs:start:spend_private_authwit | ||
pub fn spend_private_authwit(self, inner_hash: Field) -> Field { | ||
let context = self.context.private.unwrap(); | ||
// The `inner_hash` is "siloed" with the `msg_sender` to ensure that only it can | ||
// The `inner_hash` is "siloed" with the `msg_sender` to ensure that only it can | ||
// consume the message. | ||
// This ensures that contracts cannot consume messages that are not intended for them. | ||
let message_hash = compute_outer_authwit_hash( | ||
|
@@ -92,7 +105,7 @@ impl AccountActions { | |
// docs:start:spend_public_authwit | ||
pub fn spend_public_authwit(self, inner_hash: Field) -> Field { | ||
let context = self.context.public.unwrap(); | ||
// The `inner_hash` is "siloed" with the `msg_sender` to ensure that only it can | ||
// The `inner_hash` is "siloed" with the `msg_sender` to ensure that only it can | ||
// consume the message. | ||
// This ensures that contracts cannot consume messages that are not intended for them. | ||
let message_hash = compute_outer_authwit_hash( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copied from noir-contracts/contracts/slow_tree_contract/src/capsule.nr | ||
// We should extract this to a shared lib in aztec-nr once we settle on a design for capsules | ||
|
||
#[oracle(popCapsule)] | ||
fn pop_capsule_oracle<N>() -> [Field; N] {} | ||
|
||
// A capsule is a "blob" of data that is passed to the contract through an oracle. | ||
unconstrained pub fn pop_capsule<N>() -> [Field; N] { | ||
pop_capsule_oracle() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ mod account; | |
mod auth_witness; | ||
mod auth; | ||
mod entrypoint; | ||
mod capsule; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,13 @@ contract SchnorrHardcodedAccount { | |
|
||
global ACCOUNT_ACTIONS_STORAGE_SLOT = 1; | ||
|
||
#[aztec(private)] | ||
#[aztec(initializer)] | ||
fn constructor() { | ||
let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); | ||
actions.initialize_account_contract(); | ||
} | ||
Comment on lines
+17
to
+22
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. Let's remove this: this account contract does not need initialization at all. |
||
|
||
// Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts | ||
#[aztec(private)] | ||
fn entrypoint(app_payload: pub AppPayload, fee_payload: pub FeePayload) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,13 @@ contract SchnorrSingleKeyAccount { | |
|
||
global ACCOUNT_ACTIONS_STORAGE_SLOT = 1; | ||
|
||
#[aztec(private)] | ||
#[aztec(initializer)] | ||
fn constructor() { | ||
let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); | ||
actions.initialize_account_contract(); | ||
} | ||
Comment on lines
+13
to
+18
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. Let's remove this one as well |
||
|
||
// Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts | ||
#[aztec(private)] | ||
fn entrypoint(app_payload: pub AppPayload, fee_payload: pub FeePayload) { | ||
|
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.
I'd rename this to something like "execute_fee_payload_for_init", since it's not actually initializing the contract.