@aztec/ethereum 0.0.1-commit.03f7ef2 → 0.0.1-commit.1142ef1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dest/config.d.ts +4 -1
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +6 -0
  4. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  5. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  6. package/dest/contracts/fee_asset_handler.js +9 -9
  7. package/dest/contracts/governance_proposer.js +382 -8
  8. package/dest/contracts/inbox.d.ts +5 -1
  9. package/dest/contracts/inbox.d.ts.map +1 -1
  10. package/dest/contracts/inbox.js +4 -0
  11. package/dest/contracts/index.d.ts +2 -1
  12. package/dest/contracts/index.d.ts.map +1 -1
  13. package/dest/contracts/index.js +1 -0
  14. package/dest/contracts/outbox.d.ts +41 -0
  15. package/dest/contracts/outbox.d.ts.map +1 -0
  16. package/dest/contracts/outbox.js +86 -0
  17. package/dest/contracts/rollup.d.ts +128 -95
  18. package/dest/contracts/rollup.d.ts.map +1 -1
  19. package/dest/contracts/rollup.js +602 -127
  20. package/dest/deploy_aztec_l1_contracts.d.ts +12 -2
  21. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
  22. package/dest/deploy_aztec_l1_contracts.js +61 -11
  23. package/dest/l1_artifacts.d.ts +3550 -1102
  24. package/dest/l1_artifacts.d.ts.map +1 -1
  25. package/dest/l1_tx_utils/fee-strategies/index.d.ts +3 -2
  26. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -1
  27. package/dest/l1_tx_utils/fee-strategies/index.js +2 -1
  28. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +2 -12
  29. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -1
  30. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +35 -17
  31. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +2 -11
  32. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -1
  33. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +36 -18
  34. package/dest/l1_tx_utils/fee-strategies/types.d.ts +14 -27
  35. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -1
  36. package/dest/l1_tx_utils/fee-strategies/types.js +0 -21
  37. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +2 -2
  38. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -1
  39. package/dest/l1_tx_utils/l1_fee_analyzer.js +3 -3
  40. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -5
  41. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  42. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +14 -51
  43. package/dest/queries.d.ts +1 -1
  44. package/dest/queries.d.ts.map +1 -1
  45. package/dest/queries.js +8 -3
  46. package/dest/test/chain_monitor.js +1 -2
  47. package/dest/test/rollup_cheat_codes.d.ts +2 -1
  48. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  49. package/dest/test/rollup_cheat_codes.js +9 -1
  50. package/package.json +5 -5
  51. package/src/config.ts +8 -0
  52. package/src/contracts/fee_asset_handler.ts +8 -7
  53. package/src/contracts/inbox.ts +5 -0
  54. package/src/contracts/index.ts +1 -0
  55. package/src/contracts/outbox.ts +98 -0
  56. package/src/contracts/rollup.ts +240 -92
  57. package/src/deploy_aztec_l1_contracts.ts +62 -13
  58. package/src/l1_tx_utils/fee-strategies/index.ts +1 -1
  59. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +45 -41
  60. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +48 -44
  61. package/src/l1_tx_utils/fee-strategies/types.ts +14 -46
  62. package/src/l1_tx_utils/l1_fee_analyzer.ts +2 -3
  63. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +20 -59
  64. package/src/queries.ts +8 -2
  65. package/src/test/chain_monitor.ts +1 -1
  66. package/src/test/rollup_cheat_codes.ts +10 -1
package/src/config.ts CHANGED
@@ -32,6 +32,8 @@ export type L1ContractsConfig = {
32
32
  lagInEpochsForValidatorSet: number;
33
33
  /** The number of epochs to lag behind the current epoch for randao selection. */
34
34
  lagInEpochsForRandao: number;
35
+ /** The number of checkpoints to lag in the inbox (prevents sequencer DOS attacks). */
36
+ inboxLag: number;
35
37
  /** The number of epochs after an epoch ends that proofs are still accepted. */
36
38
  aztecProofSubmissionEpochs: number;
37
39
  /** The deposit amount for a validator */
@@ -81,6 +83,7 @@ export const DefaultL1ContractsConfig = {
81
83
  aztecTargetCommitteeSize: 48,
82
84
  lagInEpochsForValidatorSet: 2,
83
85
  lagInEpochsForRandao: 2, // For PROD, this value should be > lagInEpochsForValidatorSet
86
+ inboxLag: 1, // Default inbox lag to prevent sequencer DOS attacks
84
87
  aztecProofSubmissionEpochs: 1, // you have a full epoch to submit a proof after the epoch to prove ends
85
88
  activationThreshold: 100n * 10n ** 18n,
86
89
  ejectionThreshold: 50n * 10n ** 18n,
@@ -132,6 +135,11 @@ export const l1ContractsConfigMappings: ConfigMappingsType<L1ContractsConfig> =
132
135
  description: 'The number of epochs to lag behind the current epoch for randao selection.',
133
136
  ...numberConfigHelper(DefaultL1ContractsConfig.lagInEpochsForRandao),
134
137
  },
138
+ inboxLag: {
139
+ env: 'AZTEC_INBOX_LAG',
140
+ description: 'The number of checkpoints to lag in the inbox (prevents sequencer DOS attacks).',
141
+ ...numberConfigHelper(DefaultL1ContractsConfig.inboxLag),
142
+ },
135
143
  aztecProofSubmissionEpochs: {
136
144
  env: 'AZTEC_PROOF_SUBMISSION_EPOCHS',
137
145
  description: 'The number of epochs after an epoch ends that proofs are still accepted.',
@@ -4,13 +4,14 @@ import { FeeAssetHandlerAbi } from '@aztec/l1-artifacts/FeeAssetHandlerAbi';
4
4
  import { type Hex, encodeFunctionData, getContract } from 'viem';
5
5
 
6
6
  import type { L1TxUtils } from '../l1_tx_utils/index.js';
7
+ import type { ViemClient } from '../types.js';
7
8
 
8
9
  export class FeeAssetHandlerContract {
9
10
  public address: EthAddress;
10
11
 
11
12
  constructor(
13
+ public readonly client: ViemClient,
12
14
  address: Hex | EthAddress,
13
- public readonly txUtils: L1TxUtils,
14
15
  ) {
15
16
  if (address instanceof EthAddress) {
16
17
  address = address.toString();
@@ -22,7 +23,7 @@ export class FeeAssetHandlerContract {
22
23
  const contract = getContract({
23
24
  abi: FeeAssetHandlerAbi,
24
25
  address: this.address.toString(),
25
- client: this.txUtils.client,
26
+ client: this.client,
26
27
  });
27
28
  return EthAddress.fromString(await contract.read.owner());
28
29
  }
@@ -31,16 +32,16 @@ export class FeeAssetHandlerContract {
31
32
  const contract = getContract({
32
33
  abi: FeeAssetHandlerAbi,
33
34
  address: this.address.toString(),
34
- client: this.txUtils.client,
35
+ client: this.client,
35
36
  });
36
37
  return contract.read.mintAmount();
37
38
  }
38
39
 
39
- public mint(recipient: Hex | EthAddress) {
40
+ public mint(txUtils: L1TxUtils, recipient: Hex | EthAddress) {
40
41
  if (recipient instanceof EthAddress) {
41
42
  recipient = recipient.toString();
42
43
  }
43
- return this.txUtils.sendAndMonitorTransaction({
44
+ return txUtils.sendAndMonitorTransaction({
44
45
  to: this.address.toString(),
45
46
  data: encodeFunctionData({
46
47
  abi: FeeAssetHandlerAbi,
@@ -50,8 +51,8 @@ export class FeeAssetHandlerContract {
50
51
  });
51
52
  }
52
53
 
53
- public setMintAmount(amount: bigint) {
54
- return this.txUtils.sendAndMonitorTransaction({
54
+ public setMintAmount(txUtils: L1TxUtils, amount: bigint) {
55
+ return txUtils.sendAndMonitorTransaction({
55
56
  to: this.address.toString(),
56
57
  data: encodeFunctionData({
57
58
  abi: FeeAssetHandlerAbi,
@@ -45,6 +45,11 @@ export class InboxContract {
45
45
  return this.inbox;
46
46
  }
47
47
 
48
+ public async getLag(opts: { blockTag?: BlockTag; blockNumber?: bigint } = {}): Promise<bigint> {
49
+ await checkBlockTag(opts.blockNumber, this.client);
50
+ return await this.inbox.read.LAG(opts);
51
+ }
52
+
48
53
  public async getState(opts: { blockTag?: BlockTag; blockNumber?: bigint } = {}): Promise<InboxContractState> {
49
54
  await checkBlockTag(opts.blockNumber, this.client);
50
55
  const state = await this.inbox.read.getState(opts);
@@ -7,6 +7,7 @@ export * from './governance_proposer.js';
7
7
  export * from './gse.js';
8
8
  export * from './inbox.js';
9
9
  export * from './multicall.js';
10
+ export * from './outbox.js';
10
11
  export * from './registry.js';
11
12
  export * from './rollup.js';
12
13
  export * from './empire_slashing_proposer.js';
@@ -0,0 +1,98 @@
1
+ import type { EpochNumber } from '@aztec/foundation/branded-types';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
3
+ import { OutboxAbi } from '@aztec/l1-artifacts/OutboxAbi';
4
+
5
+ import { type GetContractReturnType, type Hex, encodeAbiParameters, getContract, hexToBigInt, keccak256 } from 'viem';
6
+
7
+ import { getPublicClient } from '../client.js';
8
+ import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
9
+ import type { L1ReaderConfig } from '../l1_reader.js';
10
+ import { type ExtendedViemWalletClient, type ViemClient, isExtendedClient } from '../types.js';
11
+
12
+ export type ViemL1Actor = {
13
+ actor: Hex;
14
+ chainId: bigint;
15
+ };
16
+
17
+ export type ViemL2Actor = {
18
+ actor: Hex;
19
+ version: bigint;
20
+ };
21
+
22
+ export type ViemL2ToL1Msg = {
23
+ sender: ViemL2Actor;
24
+ recipient: ViemL1Actor;
25
+ content: Hex;
26
+ };
27
+
28
+ export class OutboxContract {
29
+ private readonly outbox: GetContractReturnType<typeof OutboxAbi, ViemClient>;
30
+
31
+ static getFromL1ContractsValues(deployL1ContractsValues: DeployAztecL1ContractsReturnType) {
32
+ const {
33
+ l1Client,
34
+ l1ContractAddresses: { outboxAddress },
35
+ } = deployL1ContractsValues;
36
+ return new OutboxContract(l1Client, outboxAddress.toString());
37
+ }
38
+
39
+ static getFromConfig(config: L1ReaderConfig) {
40
+ const client = getPublicClient(config);
41
+ const address = config.l1Contracts.outboxAddress.toString();
42
+ return new OutboxContract(client, address);
43
+ }
44
+
45
+ static getEpochRootStorageSlot(epoch: EpochNumber) {
46
+ return hexToBigInt(keccak256(encodeAbiParameters([{ type: 'uint256' }, { type: 'uint256' }], [BigInt(epoch), 0n])));
47
+ }
48
+
49
+ constructor(
50
+ public readonly client: ViemClient,
51
+ address: Hex | EthAddress,
52
+ ) {
53
+ if (address instanceof EthAddress) {
54
+ address = address.toString();
55
+ }
56
+ this.outbox = getContract({ address, abi: OutboxAbi, client });
57
+ }
58
+
59
+ public get address() {
60
+ return this.outbox.address;
61
+ }
62
+
63
+ public getContract(): GetContractReturnType<typeof OutboxAbi, ViemClient> {
64
+ return this.outbox;
65
+ }
66
+
67
+ public hasMessageBeenConsumedAtEpoch(epoch: EpochNumber, leafId: bigint) {
68
+ return this.outbox.read.hasMessageBeenConsumedAtEpoch([BigInt(epoch), leafId]);
69
+ }
70
+
71
+ public getRootData(epoch: EpochNumber) {
72
+ return this.outbox.read.getRootData([BigInt(epoch)]);
73
+ }
74
+
75
+ public consume(message: ViemL2ToL1Msg, epoch: EpochNumber, leafIndex: bigint, path: Hex[]) {
76
+ const wallet = this.assertWallet();
77
+ return wallet.write.consume([message, BigInt(epoch), leafIndex, path]);
78
+ }
79
+
80
+ public async getMessageConsumedEvents(
81
+ l1BlockHash: Hex,
82
+ ): Promise<{ epoch: bigint; root: Hex; messageHash: Hex; leafId: bigint }[]> {
83
+ const events = await this.outbox.getEvents.MessageConsumed({}, { blockHash: l1BlockHash, strict: true });
84
+ return events.map(event => ({
85
+ epoch: event.args.epoch!,
86
+ root: event.args.root!,
87
+ messageHash: event.args.messageHash!,
88
+ leafId: event.args.leafId!,
89
+ }));
90
+ }
91
+
92
+ private assertWallet(): GetContractReturnType<typeof OutboxAbi, ExtendedViemWalletClient> {
93
+ if (!isExtendedClient(this.client)) {
94
+ throw new Error('Wallet client is required for this operation');
95
+ }
96
+ return this.outbox as GetContractReturnType<typeof OutboxAbi, ExtendedViemWalletClient>;
97
+ }
98
+ }