@aztec/ethereum 0.0.1-commit.85d7d01 → 0.0.1-commit.8655d4a

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 (120) hide show
  1. package/dest/client.d.ts +16 -2
  2. package/dest/client.d.ts.map +1 -1
  3. package/dest/client.js +27 -7
  4. package/dest/config.d.ts +8 -6
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +11 -9
  7. package/dest/contracts/chain_state_override.d.ts +78 -0
  8. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  9. package/dest/contracts/chain_state_override.js +137 -0
  10. package/dest/contracts/empire_base.d.ts +1 -3
  11. package/dest/contracts/empire_base.d.ts.map +1 -1
  12. package/dest/contracts/fee_asset_price_oracle.d.ts +6 -2
  13. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -1
  14. package/dest/contracts/fee_asset_price_oracle.js +11 -6
  15. package/dest/contracts/governance.d.ts +108 -33
  16. package/dest/contracts/governance.d.ts.map +1 -1
  17. package/dest/contracts/governance.js +193 -12
  18. package/dest/contracts/governance_proposer.d.ts +33 -3
  19. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  20. package/dest/contracts/governance_proposer.js +51 -9
  21. package/dest/contracts/inbox.d.ts +3 -3
  22. package/dest/contracts/inbox.d.ts.map +1 -1
  23. package/dest/contracts/inbox.js +12 -7
  24. package/dest/contracts/index.d.ts +3 -3
  25. package/dest/contracts/index.d.ts.map +1 -1
  26. package/dest/contracts/index.js +2 -2
  27. package/dest/contracts/multicall.d.ts +127 -12
  28. package/dest/contracts/multicall.d.ts.map +1 -1
  29. package/dest/contracts/multicall.js +201 -94
  30. package/dest/contracts/outbox.d.ts +21 -4
  31. package/dest/contracts/outbox.d.ts.map +1 -1
  32. package/dest/contracts/outbox.js +29 -6
  33. package/dest/contracts/registry.d.ts +3 -1
  34. package/dest/contracts/registry.d.ts.map +1 -1
  35. package/dest/contracts/registry.js +30 -1
  36. package/dest/contracts/rollup.d.ts +5254 -25
  37. package/dest/contracts/rollup.d.ts.map +1 -1
  38. package/dest/contracts/rollup.js +350 -67
  39. package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +3 -4
  40. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  41. package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +13 -15
  42. package/dest/deploy_aztec_l1_contracts.d.ts +3 -6
  43. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
  44. package/dest/deploy_aztec_l1_contracts.js +2 -4
  45. package/dest/generated/l1-contracts-defaults.d.ts +1 -1
  46. package/dest/generated/l1-contracts-defaults.js +1 -1
  47. package/dest/l1_artifacts.d.ts +13409 -15883
  48. package/dest/l1_artifacts.d.ts.map +1 -1
  49. package/dest/l1_artifacts.js +9 -24
  50. package/dest/l1_contract_addresses.d.ts +61 -65
  51. package/dest/l1_contract_addresses.d.ts.map +1 -1
  52. package/dest/l1_contract_addresses.js +101 -82
  53. package/dest/l1_reader.d.ts +5 -5
  54. package/dest/l1_reader.d.ts.map +1 -1
  55. package/dest/l1_reader.js +9 -7
  56. package/dest/l1_tx_utils/l1_tx_utils.d.ts +11 -1
  57. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  58. package/dest/l1_tx_utils/l1_tx_utils.js +60 -30
  59. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -1
  60. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  61. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +8 -4
  62. package/dest/l1_tx_utils/tx_delayer.d.ts +5 -3
  63. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -1
  64. package/dest/l1_tx_utils/tx_delayer.js +7 -5
  65. package/dest/publisher_manager.d.ts +21 -7
  66. package/dest/publisher_manager.d.ts.map +1 -1
  67. package/dest/publisher_manager.js +81 -7
  68. package/dest/queries.d.ts +13 -2
  69. package/dest/queries.d.ts.map +1 -1
  70. package/dest/queries.js +62 -3
  71. package/dest/test/chain_monitor.d.ts +23 -3
  72. package/dest/test/chain_monitor.d.ts.map +1 -1
  73. package/dest/test/chain_monitor.js +38 -2
  74. package/dest/test/eth_cheat_codes.d.ts +12 -4
  75. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  76. package/dest/test/eth_cheat_codes.js +17 -4
  77. package/dest/test/rollup_cheat_codes.d.ts +31 -3
  78. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  79. package/dest/test/rollup_cheat_codes.js +59 -7
  80. package/dest/test/start_anvil.d.ts +23 -3
  81. package/dest/test/start_anvil.d.ts.map +1 -1
  82. package/dest/test/start_anvil.js +143 -29
  83. package/dest/utils.d.ts +8 -1
  84. package/dest/utils.d.ts.map +1 -1
  85. package/dest/utils.js +35 -12
  86. package/package.json +6 -8
  87. package/src/client.ts +28 -2
  88. package/src/config.ts +21 -13
  89. package/src/contracts/chain_state_override.ts +200 -0
  90. package/src/contracts/empire_base.ts +0 -2
  91. package/src/contracts/fee_asset_price_oracle.ts +10 -5
  92. package/src/contracts/governance.ts +266 -9
  93. package/src/contracts/governance_proposer.ts +52 -5
  94. package/src/contracts/inbox.ts +13 -5
  95. package/src/contracts/index.ts +2 -2
  96. package/src/contracts/multicall.ts +243 -105
  97. package/src/contracts/outbox.ts +38 -8
  98. package/src/contracts/registry.ts +31 -1
  99. package/src/contracts/rollup.ts +391 -73
  100. package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +14 -16
  101. package/src/deploy_aztec_l1_contracts.ts +1 -5
  102. package/src/generated/l1-contracts-defaults.ts +1 -1
  103. package/src/l1_artifacts.ts +12 -35
  104. package/src/l1_contract_addresses.ts +120 -94
  105. package/src/l1_reader.ts +17 -10
  106. package/src/l1_tx_utils/l1_tx_utils.ts +58 -22
  107. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +8 -4
  108. package/src/l1_tx_utils/tx_delayer.ts +16 -7
  109. package/src/publisher_manager.ts +105 -10
  110. package/src/queries.ts +70 -4
  111. package/src/test/chain_monitor.ts +65 -3
  112. package/src/test/eth_cheat_codes.ts +16 -4
  113. package/src/test/rollup_cheat_codes.ts +64 -6
  114. package/src/test/start_anvil.ts +177 -29
  115. package/src/utils.ts +35 -14
  116. package/dest/contracts/empire_slashing_proposer.d.ts +0 -69
  117. package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
  118. package/dest/contracts/empire_slashing_proposer.js +0 -216
  119. package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
  120. package/src/contracts/empire_slashing_proposer.ts +0 -265
@@ -7,7 +7,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
7
7
  import { Signature } from '@aztec/foundation/eth-signature';
8
8
  import { hexToBuffer } from '@aztec/foundation/string';
9
9
  import { SlasherAbi } from '@aztec/l1-artifacts/SlasherAbi';
10
- import { TallySlashingProposerAbi } from '@aztec/l1-artifacts/TallySlashingProposerAbi';
10
+ import { SlashingProposerAbi } from '@aztec/l1-artifacts/SlashingProposerAbi';
11
11
 
12
12
  import {
13
13
  type GetContractReturnType,
@@ -19,13 +19,11 @@ import {
19
19
  } from 'viem';
20
20
 
21
21
  /**
22
- * Wrapper around the TallySlashingProposer contract that provides
22
+ * Wrapper around the SlashingProposer contract that provides
23
23
  * a TypeScript interface for interacting with the consensus-based slashing system.
24
24
  */
25
- export class TallySlashingProposerContract {
26
- private readonly contract: GetContractReturnType<typeof TallySlashingProposerAbi, ViemClient>;
27
-
28
- public readonly type = 'tally' as const;
25
+ export class SlashingProposerContract {
26
+ private readonly contract: GetContractReturnType<typeof SlashingProposerAbi, ViemClient>;
29
27
 
30
28
  constructor(
31
29
  public readonly client: ViemClient,
@@ -33,7 +31,7 @@ export class TallySlashingProposerContract {
33
31
  ) {
34
32
  this.contract = getContract({
35
33
  address: typeof address === 'string' ? address : address.toString(),
36
- abi: TallySlashingProposerAbi,
34
+ abi: SlashingProposerAbi,
37
35
  client,
38
36
  });
39
37
  }
@@ -136,12 +134,12 @@ export class TallySlashingProposerContract {
136
134
 
137
135
  /** Tries to extract a VoteCast event from the given logs. */
138
136
  public tryExtractVoteCastEvent(logs: Log[]) {
139
- return tryExtractEvent(logs, this.address.toString(), TallySlashingProposerAbi, 'VoteCast');
137
+ return tryExtractEvent(logs, this.address.toString(), SlashingProposerAbi, 'VoteCast');
140
138
  }
141
139
 
142
140
  /** Tries to extract a RoundExecuted event from the given logs. */
143
141
  public tryExtractRoundExecutedEvent(logs: Log[]) {
144
- return tryExtractEvent(logs, this.address.toString(), TallySlashingProposerAbi, 'RoundExecuted');
142
+ return tryExtractEvent(logs, this.address.toString(), SlashingProposerAbi, 'RoundExecuted');
145
143
  }
146
144
 
147
145
  /**
@@ -161,9 +159,9 @@ export class TallySlashingProposerContract {
161
159
 
162
160
  return {
163
161
  to: this.contract.address,
164
- abi: TallySlashingProposerAbi,
162
+ abi: SlashingProposerAbi,
165
163
  data: encodeFunctionData({
166
- abi: TallySlashingProposerAbi,
164
+ abi: SlashingProposerAbi,
167
165
  functionName: 'vote',
168
166
  args: [votes, signature.toViemSignature()],
169
167
  }),
@@ -173,7 +171,7 @@ export class TallySlashingProposerContract {
173
171
  /** Returns the typed data definition to EIP712-sign for voting */
174
172
  public buildVoteTypedData(votes: Hex, slot: SlotNumber): TypedDataDefinition {
175
173
  const domain = {
176
- name: 'TallySlashingProposer',
174
+ name: 'SlashingProposer',
177
175
  version: '1',
178
176
  chainId: this.client.chain.id,
179
177
  verifyingContract: this.contract.address,
@@ -209,9 +207,9 @@ export class TallySlashingProposerContract {
209
207
  public buildVoteRequestWithSignature(votes: Hex, signature: { v: number; r: Hex; s: Hex }): L1TxRequest {
210
208
  return {
211
209
  to: this.contract.address,
212
- abi: TallySlashingProposerAbi,
210
+ abi: SlashingProposerAbi,
213
211
  data: encodeFunctionData({
214
- abi: TallySlashingProposerAbi,
212
+ abi: SlashingProposerAbi,
215
213
  functionName: 'vote',
216
214
  args: [votes, signature],
217
215
  }),
@@ -227,9 +225,9 @@ export class TallySlashingProposerContract {
227
225
  public buildExecuteRoundRequest(round: bigint, committees: EthAddress[][]): L1TxRequest {
228
226
  return {
229
227
  to: this.contract.address,
230
- abi: mergeAbis([TallySlashingProposerAbi, SlasherAbi]),
228
+ abi: mergeAbis([SlashingProposerAbi, SlasherAbi]),
231
229
  data: encodeFunctionData({
232
- abi: TallySlashingProposerAbi,
230
+ abi: SlashingProposerAbi,
233
231
  functionName: 'executeRound',
234
232
  args: [round, committees.map(c => c.map(addr => addr.toString()))],
235
233
  }),
@@ -230,7 +230,6 @@ export function computeValidatorData(operator: Operator): ValidatorJson {
230
230
  export interface RollupUpgradeAddresses {
231
231
  rollupAddress: string;
232
232
  verifierAddress: string;
233
- slashFactoryAddress: string;
234
233
  inboxAddress: string;
235
234
  outboxAddress: string;
236
235
  feeJuicePortalAddress: string;
@@ -243,7 +242,6 @@ export interface RollupUpgradeAddresses {
243
242
  export interface ForgeRollupUpgradeResult {
244
243
  rollupAddress: Hex;
245
244
  verifierAddress: Hex;
246
- slashFactoryAddress: Hex;
247
245
  inboxAddress: Hex;
248
246
  outboxAddress: Hex;
249
247
  feeJuicePortalAddress: Hex;
@@ -403,7 +401,6 @@ export async function deployAztecL1Contracts(
403
401
  governanceProposerAddress: EthAddress.fromString(result.governanceProposerAddress),
404
402
  governanceAddress: EthAddress.fromString(result.governanceAddress),
405
403
  stakingAssetAddress: EthAddress.fromString(result.stakingAssetAddress),
406
- slashFactoryAddress: result.slashFactoryAddress ? EthAddress.fromString(result.slashFactoryAddress) : undefined,
407
404
  feeAssetHandlerAddress: result.feeAssetHandlerAddress
408
405
  ? EthAddress.fromString(result.feeAssetHandlerAddress)
409
406
  : undefined,
@@ -585,7 +582,7 @@ export function getDeployRollupForUpgradeEnvVars(
585
582
  AZTEC_EXIT_DELAY_SECONDS: args.exitDelaySeconds.toString(),
586
583
  AZTEC_PROVING_COST_PER_MANA: args.provingCostPerMana.toString(),
587
584
  AZTEC_INITIAL_ETH_PER_FEE_ASSET: args.initialEthPerFeeAsset.toString(),
588
- AZTEC_SLASHER_FLAVOR: args.slasherFlavor,
585
+ AZTEC_SLASHER_ENABLED: args.slasherEnabled ? 'true' : 'false',
589
586
  AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS: args.slashingRoundSizeInEpochs.toString(),
590
587
  AZTEC_SLASHING_QUORUM: args.slashingQuorum?.toString(),
591
588
  AZTEC_SLASHING_OFFSET_IN_ROUNDS: args.slashingOffsetInRounds.toString(),
@@ -645,6 +642,5 @@ export const deployRollupForUpgrade = async (
645
642
 
646
643
  return {
647
644
  rollup,
648
- slashFactoryAddress: result.slashFactoryAddress,
649
645
  };
650
646
  };
@@ -18,7 +18,7 @@ export const l1ContractsDefaultEnv = {
18
18
  AZTEC_MANA_TARGET: 100000000,
19
19
  AZTEC_PROVING_COST_PER_MANA: 100,
20
20
  AZTEC_INITIAL_ETH_PER_FEE_ASSET: 10000000,
21
- AZTEC_SLASHER_FLAVOR: 'tally',
21
+ AZTEC_SLASHER_ENABLED: true,
22
22
  AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS: 4,
23
23
  AZTEC_SLASHING_LIFETIME_IN_ROUNDS: 5,
24
24
  AZTEC_SLASHING_EXECUTION_DELAY_IN_ROUNDS: 0,
@@ -3,10 +3,6 @@ import {
3
3
  CoinIssuerBytecode,
4
4
  DateGatedRelayerAbi,
5
5
  DateGatedRelayerBytecode,
6
- EmpireSlasherDeploymentExtLibAbi,
7
- EmpireSlasherDeploymentExtLibBytecode,
8
- EmpireSlashingProposerAbi,
9
- EmpireSlashingProposerBytecode,
10
6
  FeeAssetHandlerAbi,
11
7
  FeeAssetHandlerBytecode,
12
8
  FeeJuicePortalAbi,
@@ -42,16 +38,14 @@ import {
42
38
  RollupLinkReferences,
43
39
  RollupOperationsExtLibAbi,
44
40
  RollupOperationsExtLibBytecode,
45
- SlashFactoryAbi,
46
- SlashFactoryBytecode,
47
41
  SlasherAbi,
48
42
  SlasherBytecode,
43
+ SlasherDeploymentExtLibAbi,
44
+ SlasherDeploymentExtLibBytecode,
45
+ SlashingProposerAbi,
46
+ SlashingProposerBytecode,
49
47
  StakingAssetHandlerAbi,
50
48
  StakingAssetHandlerBytecode,
51
- TallySlasherDeploymentExtLibAbi,
52
- TallySlasherDeploymentExtLibBytecode,
53
- TallySlashingProposerAbi,
54
- TallySlashingProposerBytecode,
55
49
  TestERC20Abi,
56
50
  TestERC20Bytecode,
57
51
  ValidatorOperationsExtLibAbi,
@@ -107,15 +101,10 @@ export const RollupArtifact = {
107
101
  contractAbi: RewardExtLibAbi,
108
102
  contractBytecode: RewardExtLibBytecode as Hex,
109
103
  },
110
- TallySlasherDeploymentExtLib: {
111
- name: 'TallySlasherDeploymentExtLib',
112
- contractAbi: TallySlasherDeploymentExtLibAbi,
113
- contractBytecode: TallySlasherDeploymentExtLibBytecode as Hex,
114
- },
115
- EmpireSlasherDeploymentExtLib: {
116
- name: 'EmpireSlasherDeploymentExtLib',
117
- contractAbi: EmpireSlasherDeploymentExtLibAbi,
118
- contractBytecode: EmpireSlasherDeploymentExtLibBytecode as Hex,
104
+ SlasherDeploymentExtLib: {
105
+ name: 'SlasherDeploymentExtLib',
106
+ contractAbi: SlasherDeploymentExtLibAbi,
107
+ contractBytecode: SlasherDeploymentExtLibBytecode as Hex,
119
108
  },
120
109
  },
121
110
  },
@@ -175,22 +164,10 @@ export const SlasherArtifact = {
175
164
  contractBytecode: SlasherBytecode as Hex,
176
165
  };
177
166
 
178
- export const EmpireSlashingProposerArtifact = {
179
- name: 'EmpireSlashingProposer',
180
- contractAbi: EmpireSlashingProposerAbi,
181
- contractBytecode: EmpireSlashingProposerBytecode as Hex,
182
- };
183
-
184
- export const TallySlashingProposerArtifact = {
185
- name: 'TallySlashingProposer',
186
- contractAbi: TallySlashingProposerAbi,
187
- contractBytecode: TallySlashingProposerBytecode as Hex,
188
- };
189
-
190
- export const SlashFactoryArtifact = {
191
- name: 'SlashFactory',
192
- contractAbi: SlashFactoryAbi,
193
- contractBytecode: SlashFactoryBytecode as Hex,
167
+ export const SlashingProposerArtifact = {
168
+ name: 'SlashingProposer',
169
+ contractAbi: SlashingProposerAbi,
170
+ contractBytecode: SlashingProposerBytecode as Hex,
194
171
  };
195
172
 
196
173
  export const RegisterNewRollupVersionPayloadArtifact = {
@@ -1,15 +1,15 @@
1
- import type { ConfigMappingsType } from '@aztec/foundation/config';
1
+ import type { ConfigMapping, ConfigMappingsType } from '@aztec/foundation/config';
2
2
  import { EthAddress } from '@aztec/foundation/eth-address';
3
- import { schemas, zodFor } from '@aztec/foundation/schemas';
3
+ import { schemas } from '@aztec/foundation/schemas';
4
4
 
5
5
  import { z } from 'zod';
6
6
 
7
7
  /**
8
- * The names of the current L1 contract addresses.
8
+ * Required L1 contract address keys.
9
9
  * NOTE: When changing this list, make sure to update CLI & CI scripts accordingly.
10
10
  * For reference: https://github.com/AztecProtocol/aztec-packages/pull/5553
11
11
  */
12
- export const L1ContractsNames = [
12
+ const REQUIRED_L1_CONTRACT_ADDRESS_KEYS = [
13
13
  'rollupAddress',
14
14
  'registryAddress',
15
15
  'inboxAddress',
@@ -23,102 +23,128 @@ export const L1ContractsNames = [
23
23
  'stakingAssetAddress',
24
24
  ] as const;
25
25
 
26
+ /** Optional L1 contract address keys — present only in some deployments. */
27
+ export const OPTIONAL_L1_CONTRACT_ADDRESS_KEYS = [
28
+ 'feeAssetHandlerAddress',
29
+ 'stakingAssetHandlerAddress',
30
+ 'zkPassportVerifierAddress',
31
+ 'gseAddress',
32
+ 'dateGatedRelayerAddress',
33
+ ] as const;
34
+
35
+ type RequiredContractKey = (typeof REQUIRED_L1_CONTRACT_ADDRESS_KEYS)[number];
36
+ type OptionalContractKey = (typeof OPTIONAL_L1_CONTRACT_ADDRESS_KEYS)[number];
37
+
26
38
  /** Provides the directory of current L1 contract addresses */
27
39
  export type L1ContractAddresses = {
28
- [K in (typeof L1ContractsNames)[number]]: EthAddress;
40
+ [K in RequiredContractKey]: EthAddress;
29
41
  } & {
30
- slashFactoryAddress?: EthAddress | undefined;
31
- feeAssetHandlerAddress?: EthAddress | undefined;
32
- stakingAssetHandlerAddress?: EthAddress | undefined;
33
- zkPassportVerifierAddress?: EthAddress | undefined;
34
- gseAddress?: EthAddress | undefined;
35
- dateGatedRelayerAddress?: EthAddress | undefined;
42
+ [K in OptionalContractKey]?: EthAddress;
36
43
  };
37
44
 
38
- export const L1ContractAddressesSchema = zodFor<L1ContractAddresses>()(
39
- z.object({
40
- rollupAddress: schemas.EthAddress,
41
- registryAddress: schemas.EthAddress,
42
- inboxAddress: schemas.EthAddress,
43
- outboxAddress: schemas.EthAddress,
44
- feeJuiceAddress: schemas.EthAddress,
45
- stakingAssetAddress: schemas.EthAddress,
46
- feeJuicePortalAddress: schemas.EthAddress,
47
- coinIssuerAddress: schemas.EthAddress,
48
- rewardDistributorAddress: schemas.EthAddress,
49
- governanceProposerAddress: schemas.EthAddress,
50
- governanceAddress: schemas.EthAddress,
51
- slashFactoryAddress: schemas.EthAddress.optional(),
52
- feeAssetHandlerAddress: schemas.EthAddress.optional(),
53
- stakingAssetHandlerAddress: schemas.EthAddress.optional(),
54
- zkPassportVerifierAddress: schemas.EthAddress.optional(),
55
- gseAddress: schemas.EthAddress.optional(),
56
- dateGatedRelayerAddress: schemas.EthAddress.optional(),
57
- }),
58
- );
45
+ /**
46
+ * Names of required L1 contract addresses.
47
+ * NOTE: When changing the set of contracts, update CLI & CI scripts accordingly.
48
+ * For reference: https://github.com/AztecProtocol/aztec-packages/pull/5553
49
+ */
50
+ export const L1ContractsNames = REQUIRED_L1_CONTRACT_ADDRESS_KEYS;
59
51
 
60
52
  const parseEnv = (val: string) => EthAddress.fromString(val);
53
+ const addrEnv = (description: string, env?: ConfigMapping<EthAddress>['env']): ConfigMapping<EthAddress> => ({
54
+ description,
55
+ parseEnv,
56
+ ...(env && { env }),
57
+ });
61
58
 
62
- export const l1ContractAddressesMapping: ConfigMappingsType<
63
- Omit<L1ContractAddresses, 'gseAddress' | 'zkPassportVerifierAddress' | 'dateGatedRelayerAddress'>
64
- > = {
65
- registryAddress: {
66
- env: 'REGISTRY_CONTRACT_ADDRESS',
67
- description: 'The deployed L1 registry contract address.',
68
- parseEnv,
69
- },
70
- slashFactoryAddress: {
71
- env: 'SLASH_FACTORY_CONTRACT_ADDRESS',
72
- description: 'The deployed L1 slashFactory contract address',
73
- parseEnv,
74
- },
75
- feeAssetHandlerAddress: {
76
- env: 'FEE_ASSET_HANDLER_CONTRACT_ADDRESS',
77
- description: 'The deployed L1 feeAssetHandler contract address',
78
- parseEnv,
79
- },
80
- rollupAddress: {
81
- description: 'The deployed L1 rollup contract address.',
82
- parseEnv,
83
- },
84
- inboxAddress: {
85
- description: 'The deployed L1 inbox contract address.',
86
- parseEnv,
87
- },
88
- outboxAddress: {
89
- description: 'The deployed L1 outbox contract address.',
90
- parseEnv,
91
- },
92
- feeJuiceAddress: {
93
- description: 'The deployed L1 Fee Juice contract address.',
94
- parseEnv,
95
- },
96
- stakingAssetAddress: {
97
- description: 'The deployed L1 staking asset contract address.',
98
- parseEnv,
99
- },
100
- feeJuicePortalAddress: {
101
- description: 'The deployed L1 Fee Juice portal contract address.',
102
- parseEnv,
103
- },
104
- coinIssuerAddress: {
105
- description: 'The deployed L1 coinIssuer contract address',
106
- parseEnv,
107
- },
108
- rewardDistributorAddress: {
109
- description: 'The deployed L1 rewardDistributor contract address',
110
- parseEnv,
111
- },
112
- governanceProposerAddress: {
113
- description: 'The deployed L1 governanceProposer contract address',
114
- parseEnv,
115
- },
116
- governanceAddress: {
117
- description: 'The deployed L1 governance contract address',
118
- parseEnv,
119
- },
120
- stakingAssetHandlerAddress: {
121
- description: 'The deployed L1 stakingAssetHandler contract address',
122
- parseEnv,
123
- },
59
+ /**
60
+ * Config mapping for all L1 contract addresses.
61
+ * This is the single source of truth for which contract addresses exist and how to parse them.
62
+ */
63
+ export const l1ContractAddressesMapping: ConfigMappingsType<L1ContractAddresses> = {
64
+ rollupAddress: addrEnv('The deployed L1 rollup contract address.'),
65
+ registryAddress: addrEnv('The deployed L1 registry contract address.', 'REGISTRY_CONTRACT_ADDRESS'),
66
+ inboxAddress: addrEnv('The deployed L1 inbox contract address.'),
67
+ outboxAddress: addrEnv('The deployed L1 outbox contract address.'),
68
+ feeJuiceAddress: addrEnv('The deployed L1 Fee Juice contract address.'),
69
+ feeJuicePortalAddress: addrEnv('The deployed L1 Fee Juice portal contract address.'),
70
+ coinIssuerAddress: addrEnv('The deployed L1 coinIssuer contract address'),
71
+ rewardDistributorAddress: addrEnv('The deployed L1 rewardDistributor contract address'),
72
+ governanceProposerAddress: addrEnv('The deployed L1 governanceProposer contract address'),
73
+ governanceAddress: addrEnv('The deployed L1 governance contract address'),
74
+ stakingAssetAddress: addrEnv('The deployed L1 staking asset contract address.'),
75
+ feeAssetHandlerAddress: addrEnv(
76
+ 'The deployed L1 feeAssetHandler contract address',
77
+ 'FEE_ASSET_HANDLER_CONTRACT_ADDRESS',
78
+ ),
79
+ stakingAssetHandlerAddress: addrEnv('The deployed L1 stakingAssetHandler contract address'),
80
+ zkPassportVerifierAddress: addrEnv('The deployed L1 ZK passport verifier contract address'),
81
+ gseAddress: addrEnv('The deployed L1 GSE contract address'),
82
+ dateGatedRelayerAddress: addrEnv('The deployed L1 date-gated relayer contract address'),
124
83
  };
84
+
85
+ /** Keys present in {@link l1ContractAddressesMapping}. */
86
+ export type L1ContractAddressMappingKey = keyof typeof l1ContractAddressesMapping;
87
+
88
+ type RequiredAddressShape = { [K in RequiredContractKey]: typeof schemas.EthAddress };
89
+ type OptionalAddressShape = { [K in OptionalContractKey]: ReturnType<typeof schemas.EthAddress.optional> };
90
+
91
+ export const L1ContractAddressesSchema = z.object({
92
+ ...(Object.fromEntries(REQUIRED_L1_CONTRACT_ADDRESS_KEYS.map(k => [k, schemas.EthAddress])) as RequiredAddressShape),
93
+ ...(Object.fromEntries(
94
+ OPTIONAL_L1_CONTRACT_ADDRESS_KEYS.map(k => [k, schemas.EthAddress.optional()]),
95
+ ) as OptionalAddressShape),
96
+ });
97
+
98
+ /**
99
+ * Selects entries from {@link l1ContractAddressesMapping} so composed configs can reuse the same
100
+ * env vars, descriptions, and parsers without duplicating definitions.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const mappings = {
105
+ * ...pickL1ContractAddressMappings('rollupAddress'),
106
+ * nodeId: { ... },
107
+ * };
108
+ * ```
109
+ */
110
+ export function pickL1ContractAddressMappings<const K extends readonly L1ContractAddressMappingKey[]>(
111
+ ...keys: K
112
+ ): Pick<typeof l1ContractAddressesMapping, K[number]> {
113
+ return Object.fromEntries(keys.map(key => [key, l1ContractAddressesMapping[key]] as const)) as Pick<
114
+ typeof l1ContractAddressesMapping,
115
+ K[number]
116
+ >;
117
+ }
118
+
119
+ /**
120
+ * Like {@link pickL1ContractAddressMappings}, but returns a fragment of {@link L1ContractAddressesSchema}'s shape for
121
+ * spreading into `z.object({ ...pickL1ContractAddressesSchemaShape('rollupAddress'), localField: z... })`.
122
+ */
123
+ export function pickL1ContractAddressesSchema<const K extends readonly L1ContractAddressMappingKey[]>(
124
+ ...keys: K
125
+ ): Pick<typeof L1ContractAddressesSchema.shape, K[number]> {
126
+ return Object.fromEntries(keys.map(key => [key, L1ContractAddressesSchema.shape[key]])) as Pick<
127
+ typeof L1ContractAddressesSchema.shape,
128
+ K[number]
129
+ >;
130
+ }
131
+
132
+ /** Builds an {@link L1ContractAddresses} object from config that stores those fields at the top level. */
133
+ export function pickL1ContractAddresses<T extends L1ContractAddresses>(config: T): L1ContractAddresses {
134
+ const result: Partial<L1ContractAddresses> = {};
135
+ for (const key of REQUIRED_L1_CONTRACT_ADDRESS_KEYS) {
136
+ result[key] = config[key];
137
+ }
138
+ for (const key of OPTIONAL_L1_CONTRACT_ADDRESS_KEYS) {
139
+ const v = config[key];
140
+ if (v !== undefined) {
141
+ result[key] = v;
142
+ }
143
+ }
144
+ return result as L1ContractAddresses;
145
+ }
146
+
147
+ export function randomL1ContractAddresses(includeOptional: boolean = false): L1ContractAddresses {
148
+ const keys = includeOptional ? [...L1ContractsNames, ...OPTIONAL_L1_CONTRACT_ADDRESS_KEYS] : L1ContractsNames;
149
+ return Object.fromEntries(keys.map(name => [name, EthAddress.random()])) as L1ContractAddresses;
150
+ }
package/src/l1_reader.ts CHANGED
@@ -1,29 +1,30 @@
1
- import { type ConfigMappingsType, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
1
+ import {
2
+ type ConfigMappingsType,
3
+ getConfigFromMappings,
4
+ numberConfigHelper,
5
+ optionalNumberConfigHelper,
6
+ } from '@aztec/foundation/config';
2
7
 
3
8
  import { type L1ContractAddresses, l1ContractAddressesMapping } from './l1_contract_addresses.js';
4
9
 
5
10
  /** Configuration of the L1GlobalReader. */
6
- export interface L1ReaderConfig {
11
+ export type L1ReaderConfig = {
7
12
  /** List of URLs of Ethereum RPC nodes that services will connect to (comma separated). */
8
13
  l1RpcUrls: string[];
9
14
  /** The RPC Url of the ethereum debug host for trace and debug methods. */
10
15
  l1DebugRpcUrls: string[];
11
16
  /** The chain ID of the ethereum host. */
12
17
  l1ChainId: number;
13
- /** The deployed l1 contract addresses */
14
- l1Contracts: L1ContractAddresses;
15
18
  /** The polling interval viem uses in ms */
16
19
  viemPollingIntervalMS: number;
17
- }
20
+ /** Timeout for HTTP requests to the L1 RPC node in ms. */
21
+ l1HttpTimeoutMS?: number;
22
+ } & L1ContractAddresses;
18
23
 
19
24
  export const l1ReaderConfigMappings: ConfigMappingsType<L1ReaderConfig> = {
20
- l1Contracts: {
21
- description: 'The deployed L1 contract addresses',
22
- nested: l1ContractAddressesMapping,
23
- },
24
25
  l1ChainId: {
25
26
  env: 'L1_CHAIN_ID',
26
- parseEnv: (val: string) => +val,
27
+ ...optionalNumberConfigHelper(),
27
28
  description: 'The chain ID of the ethereum host.',
28
29
  },
29
30
  l1RpcUrls: {
@@ -43,6 +44,12 @@ export const l1ReaderConfigMappings: ConfigMappingsType<L1ReaderConfig> = {
43
44
  description: 'The polling interval viem uses in ms',
44
45
  ...numberConfigHelper(1_000),
45
46
  },
47
+ l1HttpTimeoutMS: {
48
+ env: 'ETHEREUM_HTTP_TIMEOUT_MS',
49
+ description: 'Timeout for HTTP requests to the L1 RPC node in ms.',
50
+ ...optionalNumberConfigHelper(),
51
+ },
52
+ ...l1ContractAddressesMapping,
46
53
  };
47
54
 
48
55
  export function getL1ReaderConfigFromEnv(): L1ReaderConfig {
@@ -4,6 +4,7 @@ import { merge, pick } from '@aztec/foundation/collection';
4
4
  import { InterruptError, TimeoutError } from '@aztec/foundation/error';
5
5
  import { EthAddress } from '@aztec/foundation/eth-address';
6
6
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
7
+ import { Semaphore } from '@aztec/foundation/queue';
7
8
  import { retryUntil } from '@aztec/foundation/retry';
8
9
  import { sleep } from '@aztec/foundation/sleep';
9
10
  import { DateProvider } from '@aztec/foundation/timer';
@@ -45,6 +46,10 @@ const MAX_L1_TX_STATES = 32;
45
46
 
46
47
  export class L1TxUtils extends ReadOnlyL1TxUtils {
47
48
  protected txs: L1TxState[] = [];
49
+ /** Last nonce successfully sent to the chain. Used as a lower bound when a fallback RPC node returns a stale count. */
50
+ private lastSentNonce: number | undefined;
51
+ /** Mutex to prevent concurrent sendTransaction calls from racing on the same nonce. */
52
+ private readonly sendMutex = new Semaphore(1);
48
53
  /** Tx delayer for testing. Only set when enableDelayer config is true. */
49
54
  public delayer?: Delayer;
50
55
  /** KZG instance for blob operations. */
@@ -105,6 +110,11 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
105
110
  this.metrics?.recordMinedTx(l1TxState, new Date(l1Timestamp));
106
111
  } else if (newState === TxUtilsState.NOT_MINED) {
107
112
  this.metrics?.recordDroppedTx(l1TxState);
113
+ // The tx was dropped: the chain nonce reverted to l1TxState.nonce, so our lower bound is
114
+ // no longer valid. Clear it so the next send fetches the real nonce from the chain.
115
+ if (this.lastSentNonce === l1TxState.nonce) {
116
+ this.lastSentNonce = undefined;
117
+ }
108
118
  }
109
119
 
110
120
  // Update state in the store
@@ -121,6 +131,14 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
121
131
  );
122
132
  }
123
133
 
134
+ /**
135
+ * Clears the cached `lastSentNonce` so the next `sendTransaction` call fetches the real
136
+ * nonce from the chain. Call this after an L1 reorg to prevent stale nonce references.
137
+ */
138
+ public resetNonce(): void {
139
+ this.lastSentNonce = undefined;
140
+ }
141
+
124
142
  public getSenderAddress() {
125
143
  return this.address;
126
144
  }
@@ -203,6 +221,19 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
203
221
  return await this.signTransaction(txRequest as TransactionSerializable);
204
222
  }
205
223
 
224
+ private async checkInterruptedOrTimedOut(gasConfig: Pick<L1TxConfig, 'txTimeoutAt'>): Promise<Date> {
225
+ if (this.interrupted) {
226
+ throw new InterruptError(`Transaction sending is interrupted`);
227
+ }
228
+ const now = new Date(await this.getL1Timestamp());
229
+ if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
230
+ throw new TimeoutError(
231
+ `Transaction timed out before sending (now ${now.toISOString()} > timeoutAt ${gasConfig.txTimeoutAt.toISOString()})`,
232
+ );
233
+ }
234
+ return now;
235
+ }
236
+
206
237
  /**
207
238
  * Sends a transaction with gas estimation and pricing
208
239
  * @param request - The transaction request (to, data, value)
@@ -215,14 +246,15 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
215
246
  blobInputs?: L1BlobInputs,
216
247
  stateChange: TxUtilsState = TxUtilsState.SENT,
217
248
  ): Promise<{ txHash: Hex; state: L1TxState }> {
218
- if (this.interrupted) {
219
- throw new InterruptError(`Transaction sending is interrupted`);
220
- }
221
-
222
249
  try {
223
250
  const gasConfig = merge(this.config, gasConfigOverrides);
224
251
  const account = this.getSenderAddress().toString();
225
252
 
253
+ // Fail fast before doing any work (gas estimation, balance check) if we've been interrupted
254
+ // or if the caller's deadline has already passed. The same check is repeated after gas
255
+ // estimation in case it took long enough to push us past the deadline.
256
+ await this.checkInterruptedOrTimedOut(gasConfig);
257
+
226
258
  let gasLimit: bigint;
227
259
  if (this.debugMaxGasLimit) {
228
260
  gasLimit = MAX_L1_TX_LIMIT;
@@ -235,30 +267,34 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
235
267
 
236
268
  const gasPrice = await this.getGasPrice(gasConfig, !!blobInputs);
237
269
 
238
- if (this.interrupted) {
239
- throw new InterruptError(`Transaction sending is interrupted`);
240
- }
241
-
242
- const now = new Date(await this.getL1Timestamp());
243
- if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
244
- throw new TimeoutError(
245
- `Transaction timed out before sending (now ${now.toISOString()} > timeoutAt ${gasConfig.txTimeoutAt.toISOString()})`,
246
- );
247
- }
248
-
249
- const nonce = await this.client.getTransactionCount({ address: account, blockTag: 'pending' });
270
+ const now = await this.checkInterruptedOrTimedOut(gasConfig);
250
271
 
251
- const baseState = { request, gasLimit, blobInputs, gasPrice, nonce };
252
- const txData = this.makeTxData(baseState, { isCancelTx: false });
272
+ let txHash: Hex;
273
+ let nonce: number;
274
+ let baseState: Pick<L1TxState, 'request' | 'gasLimit' | 'blobInputs' | 'gasPrice' | 'nonce'>;
253
275
 
254
- // Send the new tx
255
- const signedRequest = await this.prepareSignedTransaction(txData);
256
- const txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
276
+ await this.sendMutex.acquire();
277
+ try {
278
+ const chainNonce = await this.client.getTransactionCount({ address: account, blockTag: 'pending' });
279
+ // If a fallback RPC node returns a stale count (lower than what we last sent), use our
280
+ // local lower bound to avoid sending a duplicate of an already-pending transaction.
281
+ nonce =
282
+ this.lastSentNonce !== undefined && chainNonce <= this.lastSentNonce ? this.lastSentNonce + 1 : chainNonce;
283
+
284
+ baseState = { request, gasLimit, blobInputs, gasPrice, nonce };
285
+ const txData = this.makeTxData(baseState, { isCancelTx: false });
286
+
287
+ const signedRequest = await this.prepareSignedTransaction(txData);
288
+ txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
289
+ this.lastSentNonce = nonce;
290
+ } finally {
291
+ this.sendMutex.release();
292
+ }
257
293
 
258
294
  // Create the new state for monitoring
259
295
  const l1TxState: L1TxState = {
260
296
  ...baseState,
261
- id: (await this.store?.consumeNextStateId(account)) ?? Math.max(...this.txs.map(tx => tx.id), 0),
297
+ id: (await this.store?.consumeNextStateId(account)) ?? Math.max(...this.txs.map(tx => tx.id), -1) + 1,
262
298
  txHashes: [txHash],
263
299
  cancelTxHashes: [],
264
300
  status: TxUtilsState.IDLE,