Skip to content
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

Closed

Conversation

alexghr
Copy link
Contributor

@alexghr alexghr commented Apr 3, 2024

This PR enables account contracts to pay for tx fees when they're deployed.

Fix #5190

Copy link
Contributor Author

alexghr commented Apr 3, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @alexghr and the rest of your teammates on Graphite Graphite

@alexghr alexghr marked this pull request as draft April 3, 2024 08:26
@alexghr alexghr changed the title feat: pay fee when deploying schnorr account feat: pay fee when deploying account contracts Apr 3, 2024
@alexghr alexghr force-pushed the 04-02-feat_pay_fee_when_deploying_schnorr_account branch from 90f4dbc to e951798 Compare April 3, 2024 08:36
@AztecBot
Copy link
Collaborator

AztecBot commented Apr 3, 2024

Benchmark results

Metrics with a significant change:

  • note_history_successful_decrypting_time_in_ms (10): 2,816 (+17%)
Detailed results

All benchmarks are run on txs on the Benchmarking contract on the repository. Each tx consists of a batch call to create_note and increment_balance, which guarantees that each tx has a private call, a nested private call, a public call, and a nested public call, as well as an emitted private note, an unencrypted log, and public storage read and write.

This benchmark source data is available in JSON format on S3 here.

Values are compared against data from master at commit e0e72008 and shown if the difference exceeds 1%.

L2 block published to L1

Each column represents the number of txs on an L2 block published to L1.

Metric 8 txs 32 txs 64 txs
l1_rollup_calldata_size_in_bytes 676 676 676
l1_rollup_calldata_gas 6,412 6,412 6,400
l1_rollup_execution_gas 585,745 585,745 585,733
l2_block_processing_time_in_ms 1,316 (+2%) 4,718 (-3%) 9,297
note_successful_decrypting_time_in_ms 261 (+10%) 614 (+14%) 989 (+3%)
note_trial_decrypting_time_in_ms 62.6 (+65%) 23.4 (-53%) 106 (+29%)
l2_block_building_time_in_ms 11,868 43,070 (+1%) 85,069 (+1%)
l2_block_rollup_simulation_time_in_ms 7,099 24,340 (+1%) 47,123
l2_block_public_tx_process_time_in_ms 4,733 18,602 (+1%) 37,707 (+2%)

L2 chain processing

Each column represents the number of blocks on the L2 chain where each block has 16 txs.

Metric 5 blocks 10 blocks
node_history_sync_time_in_ms 14,058 (+1%) 28,597 (+7%)
note_history_successful_decrypting_time_in_ms 1,275 (-1%) ⚠️ 2,816 (+17%)
note_history_trial_decrypting_time_in_ms 73.0 (-21%) 82.0 (-20%)
node_database_size_in_bytes 18,632,784 34,971,728
pxe_database_size_in_bytes 29,859 59,414

Circuits stats

Stats on running time and I/O sizes collected for every circuit run across all benchmarks.

Circuit circuit_simulation_time_in_ms circuit_input_size_in_bytes circuit_output_size_in_bytes
private-kernel-init 184 (-1%) 44,377 26,164
private-kernel-ordering 165 (-1%) 50,830 39,325
base-parity 4,386 (+8%) 128 311
root-parity 1,171 (+1%) 1,244 311
base-rollup 14,676 (+2%) 116,608 861
root-rollup 50.3 (-1%) 4,359 725
private-kernel-inner 223 (-1%) 71,744 26,164
public-kernel-app-logic 121 47,695 40,661
public-kernel-tail 165 (+1%) 53,372 13,269
merge-rollup 9.85 2,568 861
public-kernel-teardown 118 (+2%) 47,695 40,661
public-kernel-setup 116 (+1%) 47,695 40,661

Tree insertion stats

The duration to insert a fixed batch of leaves into each tree type.

Metric 1 leaves 16 leaves 64 leaves 128 leaves 512 leaves 1024 leaves 2048 leaves 4096 leaves 32 leaves
batch_insert_into_append_only_tree_16_depth_ms 10.3 (+2%) 16.7 (+4%) N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_count 16.8 31.6 N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_ms 0.598 (+3%) 0.515 (+4%) N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 48.0 (+5%) 77.4 (+7%) 231 (+1%) 454 (+1%) 868 (+1%) 1,731 (+1%) N/A
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 96.0 159 543 1,055 2,079 4,127 N/A
batch_insert_into_append_only_tree_32_depth_hash_ms N/A N/A 0.493 (+5%) 0.478 (+7%) 0.421 (+1%) 0.424 (+1%) 0.413 (+1%) 0.414 (+1%) N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 56.8 (+5%) 115 (+7%) 336 (-1%) 670 (+1%) 1,307 (+1%) 2,604 (+1%) N/A
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 105 207 691 1,363 2,707 5,395 N/A
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.502 (+5%) 0.517 (+7%) 0.457 (-2%) 0.462 (+1%) 0.454 (+1%) 0.453 (+1%) N/A
batch_insert_into_indexed_tree_40_depth_ms N/A N/A N/A N/A N/A N/A N/A N/A 62.8 (+3%)
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A N/A N/A N/A N/A N/A N/A 109
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A N/A N/A N/A N/A N/A N/A 0.548 (+3%)

Miscellaneous

Transaction sizes based on how many contract classes are registered in the tx.

Metric 0 registered classes 1 registered classes
tx_size_in_bytes 40,548 501,142

Transaction size based on fee payment method

Metric native fee payment method fpc_public fee payment method fpc_private fee payment method
tx_with_fee_size_in_bytes 905 1,161 1,377

Transaction processing duration by data writes.

Metric 0 new note hashes 1 new note hashes 2 new note hashes
tx_pxe_processing_time_ms 1,672 (-2%) 1,109 5,400
Metric 1 public data writes 2 public data writes 3 public data writes 4 public data writes 5 public data writes 8 public data writes
tx_sequencer_processing_time_ms 586 (+2%) 435 1,071 522 1,747 586

@alexghr alexghr force-pushed the 04-02-feat_pay_fee_when_deploying_schnorr_account branch 3 times, most recently from 51ed6a1 to f61f732 Compare April 4, 2024 08:07
@alexghr alexghr marked this pull request as ready for review April 4, 2024 08:10
@alexghr alexghr force-pushed the 04-02-feat_pay_fee_when_deploying_schnorr_account branch 3 times, most recently from 4d98bc8 to 1bbdc57 Compare April 4, 2024 12:22
@alexghr alexghr force-pushed the 04-02-feat_pay_fee_when_deploying_schnorr_account branch from 1bbdc57 to 086911b Compare April 4, 2024 13:53
@alexghr
Copy link
Contributor Author

alexghr commented Apr 4, 2024

Looks like boxes use the published versions of aztec.js & accounts instead of what's in the current workspace so the their tests will fail. We can either disable them temporarily until the next release or find a way to link them against the workspace's packages.

Copy link
Collaborator

@spalladino spalladino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I left a few comments but we can address those later. I was about to comment on how it'd be nice to be able to publicly deploy and initialize simultaneously, when I remembered that you just mentioned that on Slack heh.

Comment on lines +17 to +22
#[aztec(private)]
#[aztec(initializer)]
fn constructor() {
let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl);
actions.initialize_account_contract();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

@@ -54,6 +56,17 @@ impl AccountActions {
)
}

pub fn initialize_account_contract(self) {
Copy link
Collaborator

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.

Comment on lines +63 to +64
let fee_payload = FeePayload::deserialize(pop_capsule());
let fee_hash = fee_payload.hash();
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 fee_payload should be an argument to this function and not something that shows up magically, and what we really need is a way to say "this argument is not part of the initialization hash". But we can change that in a future PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the tasks for this would be:

  • Add a noinitargcheck attribute in Noir for the argument to be skipped
  • Make sure the attribute is emitted in the abi
  • Compute a separate args hash for initialization preimage check if there are any noinitargcheck
  • Change the address computation so it ignores args marked as noinitargcheck when computing the initialization hash in the address preimage (this will be the most annoying bit I think)
  • Ensure the deploy method does not ignore them when actually executing the initialization

It's quite a lot unfortunately, but feels cleaner..?

Copy link
Contributor Author

@alexghr alexghr Apr 5, 2024

Choose a reason for hiding this comment

The 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

lol same, but I was actually thinking of going the protocol contract route instead of adding a new macro 😅

Comment on lines +13 to +18
#[aztec(private)]
#[aztec(initializer)]
fn constructor() {
let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl);
actions.initialize_account_contract();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this one as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa, when was entrypoints moved to a package of its own?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We creates the entrypoints package during the offsite. In hindsight I think a better approach would've been to expose it as aztec.js/entrypoints.

Comment on lines +62 to +64
if (!this.initializerArtifact) {
throw new Error('Account contract can not be initialized without an initializer');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extend this to support account contracts without initializers, in which case we should just publicly deploy the instance.

Comment on lines -134 to -141
const deployWallet = new SignerlessWallet(this.pxe);
const deployer = new ContractDeployer(
this.accountContract.getContractArtifact(),
deployWallet,
const args = this.accountContract.getDeploymentArgs() ?? [];
this.deployMethod = new DeployAccountMethod(
this.pxe,
this.accountContract.getAuthWitnessProvider(this.getCompleteAddress()),
encryptionPublicKey,
this.accountContract.getContractArtifact(),
args,
() => this.#register(),
);
const args = this.accountContract.getDeploymentArgs() ?? [];
this.deployMethod = deployer.deploy(...args);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks a lot nicer!

Comment on lines +65 to +71
/**
* The function calls to execute
* @internal
*/
get function_calls() {
return this.#functionCalls;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment why this snake_case property is needed

/**
* Contract interaction for deploying an account contract. Handles fee preparation and contract initialization.
*/
export class DeployAccountMethod<TContract extends ContractBase = Contract> extends BaseContractInteraction {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename to InitializeAccount, since it doesn't have the capability to publicly deploy.

@alexghr
Copy link
Contributor Author

alexghr commented Apr 8, 2024

Superseded by #5601

@alexghr alexghr closed this Apr 8, 2024
alexghr added a commit that referenced this pull request Apr 10, 2024
This PR enables accounts to pay tx fees when they're deployed. To
achieve this a new deployment method was added that's used by the
`AccountManager` class to optionally register/publicly deploy and
initialize the target account contract.

Entrypoint classes now accept authwits/packed arguments alongside the
normal function calls from before. This is needed so that authwits could
be created in a parent context and then passed along as transient
authwits to the transaction (see `ExecutionRequestInit` wrapper type)

Initializing an account contract can use any of the three existing
payment methods:
- using bridged gas token from L1
- paying privately through a fee payment contract
- paying publicly through a fee payment contract

In order to use fee payment contracts this PR adds `noinitcheck` to
`spend_private_authwit` and `spend_public_authwit` because it's not
possible to read the init nullifier in the current tx (protocol
limitation). Instead the contract relies on the note containing the
public key to exist to validate that the contract has been initialized
correctly.

An extra payment flow is tested as well: a third party takes the
account's public keys and deploys and initializes the account while
paying the associated fee. This simulates the flow where a deployment
service is used that takes payment through a side chain (e.g. fiat).

Breaking change: moved `DefaultMultiCallEntrypoint` to aztec.js

This PR supersedes #5540 and #5543.

Fix #5190 #5191 #5544.
@ludamad ludamad deleted the 04-02-feat_pay_fee_when_deploying_schnorr_account branch August 22, 2024 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pay fees natively during account contract initialization
3 participants