@aztec/ethereum 4.0.0-nightly.20260113 → 4.0.0-nightly.20260115

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.
@@ -0,0 +1,157 @@
1
+ # L1 Contract Wrappers
2
+
3
+ This folder contains TypeScript wrappers for L1 contracts defined in `l1-contracts/`. These wrappers are used by the node client to interact with the rollup and related contracts on Ethereum.
4
+
5
+ ## Purpose
6
+
7
+ The goal of wrapping is to shield consumers from L1-specific and viem-specific details. Clients using these wrappers interact with domain types and branded types native to the Aztec codebase, without needing to understand viem's ABI type system or deal with raw types like `Hex` and `bigint`.
8
+
9
+ ## Type Safety
10
+
11
+ ### Explicit Return Types
12
+
13
+ Every function in the contract wrappers must declare its return type explicitly. This is critical because viem's type inference over ABI types is slow and significantly impacts IDE performance.
14
+
15
+ ```typescript
16
+ // Good: Explicit return type
17
+ async getSlotNumber(): Promise<SlotNumber> {
18
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
19
+ }
20
+
21
+ // Bad: Inferred return type (slow)
22
+ async getSlotNumber() {
23
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
24
+ }
25
+ ```
26
+
27
+ ### Branded and Domain Types
28
+
29
+ Use branded types and domain-specific types instead of viem's autogenerated types for both arguments and return values:
30
+
31
+ - `CheckpointNumber`, `EpochNumber`, `SlotNumber` instead of `bigint`
32
+ - `EthAddress` instead of `` `0x${string}` `` or `Hex`
33
+ - `Fr`, `Buffer32` instead of `Hex` for hashes and field elements
34
+ - Custom domain types (e.g., `CheckpointLog`, `AttesterView`) instead of raw tuples
35
+
36
+ Type conversions happen inside wrapper methods, not at the call site:
37
+
38
+ ```typescript
39
+ async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<CheckpointLog> {
40
+ const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
41
+ return {
42
+ archive: Fr.fromString(result.archive),
43
+ headerHash: Buffer32.fromString(result.headerHash),
44
+ blockCount: result.blockCount,
45
+ };
46
+ }
47
+ ```
48
+
49
+ ## Wrapper Pattern
50
+
51
+ ### Basic Structure
52
+
53
+ Each wrapper follows a consistent structure:
54
+
55
+ ```typescript
56
+ export class FooContract {
57
+ private readonly foo: GetContractReturnType<typeof FooAbi, ViemClient>;
58
+
59
+ constructor(
60
+ public readonly client: ViemClient,
61
+ address: Hex | EthAddress,
62
+ ) {
63
+ if (address instanceof EthAddress) {
64
+ address = address.toString();
65
+ }
66
+ this.foo = getContract({ address, abi: FooAbi, client });
67
+ }
68
+
69
+ public get address(): Hex {
70
+ return this.foo.address;
71
+ }
72
+
73
+ public getContract(): GetContractReturnType<typeof FooAbi, ViemClient> {
74
+ return this.foo;
75
+ }
76
+ }
77
+ ```
78
+
79
+ The raw contract is exposed via `getContract()` for cases where direct access is needed, but most consumers should use the typed wrapper methods. Relying on `getContract()` is a code smell and should be avoided.
80
+
81
+ ### Static Factory Methods
82
+
83
+ Wrappers may provide static factory methods for common initialization patterns:
84
+
85
+ - `getFromConfig(config)` - construct from configuration object
86
+ - `getFromL1ContractsValues(deployResult)` - construct from deployment result
87
+
88
+ ### Wallet Assertions
89
+
90
+ For write operations that require a wallet, use an assertion helper:
91
+
92
+ ```typescript
93
+ private assertWallet(): GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient> {
94
+ if (!isExtendedClient(this.client)) {
95
+ throw new Error('Wallet client is required for this operation');
96
+ }
97
+ return this.foo as GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient>;
98
+ }
99
+ ```
100
+
101
+ ## Event Handling
102
+
103
+ ### Event Log Types
104
+
105
+ Event logs are wrapped in `L1EventLog<T>` to include L1 block context:
106
+
107
+ ```typescript
108
+ type L1EventLog<T> = {
109
+ l1BlockNumber: bigint;
110
+ l1BlockHash: Buffer32;
111
+ l1TransactionHash: Hex;
112
+ args: T;
113
+ };
114
+ ```
115
+
116
+ ### Event Fetching
117
+
118
+ Methods that fetch events convert viem's raw logs to domain types:
119
+
120
+ ```typescript
121
+ async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
122
+ const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
123
+ return logs.map(log => ({
124
+ l1BlockNumber: log.blockNumber!,
125
+ l1BlockHash: Buffer32.fromString(log.blockHash!),
126
+ l1TransactionHash: log.transactionHash!,
127
+ args: {
128
+ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
129
+ // ... convert other fields
130
+ },
131
+ }));
132
+ }
133
+ ```
134
+
135
+ ### Event Listeners
136
+
137
+ For reactive event handling, wrapper methods convert arguments before invoking callbacks:
138
+
139
+ ```typescript
140
+ public listenToCheckpointInvalidated(
141
+ callback: (args: { checkpointNumber: CheckpointNumber }) => unknown,
142
+ ): WatchContractEventReturnType {
143
+ return this.rollup.watchEvent.CheckpointInvalidated({}, {
144
+ onLogs: logs => {
145
+ for (const log of logs) {
146
+ if (log.args.checkpointNumber !== undefined) {
147
+ callback({ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber) });
148
+ }
149
+ }
150
+ },
151
+ });
152
+ }
153
+ ```
154
+
155
+ ## Error Handling
156
+
157
+ Custom error classes in `errors.ts` extend `Error` and set `this.name` for proper error identification. Include relevant context as public readonly properties.
@@ -1,4 +1,6 @@
1
- import { Buffer16 } from '@aztec/foundation/buffer';
1
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
2
+ import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
4
  import { EthAddress } from '@aztec/foundation/eth-address';
3
5
  import { InboxAbi } from '@aztec/l1-artifacts/InboxAbi';
4
6
 
@@ -8,8 +10,20 @@ import { getPublicClient } from '../client.js';
8
10
  import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
9
11
  import type { L1ReaderConfig } from '../l1_reader.js';
10
12
  import type { ViemClient } from '../types.js';
13
+ import type { L1EventLog } from './log.js';
11
14
  import { checkBlockTag } from './utils.js';
12
15
 
16
+ /** Arguments for the MessageSent event. */
17
+ export type MessageSentArgs = {
18
+ index: bigint;
19
+ leaf: Fr;
20
+ checkpointNumber: CheckpointNumber;
21
+ rollingHash: Buffer16;
22
+ };
23
+
24
+ /** Log type for MessageSent events. */
25
+ export type MessageSentLog = L1EventLog<MessageSentArgs>;
26
+
13
27
  export class InboxContract {
14
28
  private readonly inbox: GetContractReturnType<typeof InboxAbi, ViemClient>;
15
29
 
@@ -59,6 +73,39 @@ export class InboxContract {
59
73
  treeInProgress: state.inProgress,
60
74
  };
61
75
  }
76
+
77
+ /** Fetches MessageSent events within the given block range. */
78
+ async getMessageSentEvents(fromBlock: bigint, toBlock: bigint): Promise<MessageSentLog[]> {
79
+ const logs = await this.inbox.getEvents.MessageSent({}, { fromBlock, toBlock });
80
+ return logs
81
+ .filter(log => log.blockNumber! >= fromBlock && log.blockNumber! <= toBlock)
82
+ .map(log => this.mapMessageSentLog(log));
83
+ }
84
+
85
+ /** Fetches MessageSent events for a specific message hash within the given block range. */
86
+ async getMessageSentEventByHash(hash: Hex, fromBlock: bigint, toBlock: bigint): Promise<MessageSentLog[]> {
87
+ const logs = await this.inbox.getEvents.MessageSent({ hash }, { fromBlock, toBlock });
88
+ return logs.map(log => this.mapMessageSentLog(log));
89
+ }
90
+
91
+ private mapMessageSentLog(log: {
92
+ blockNumber: bigint | null;
93
+ blockHash: `0x${string}` | null;
94
+ transactionHash: `0x${string}` | null;
95
+ args: { index?: bigint; hash?: `0x${string}`; checkpointNumber?: bigint; rollingHash?: `0x${string}` };
96
+ }): MessageSentLog {
97
+ return {
98
+ l1BlockNumber: log.blockNumber!,
99
+ l1BlockHash: Buffer32.fromString(log.blockHash!),
100
+ l1TransactionHash: log.transactionHash!,
101
+ args: {
102
+ index: log.args.index!,
103
+ leaf: Fr.fromString(log.args.hash!),
104
+ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
105
+ rollingHash: Buffer16.fromString(log.args.rollingHash!),
106
+ },
107
+ };
108
+ }
62
109
  }
63
110
 
64
111
  export type InboxContractState = {
@@ -6,6 +6,7 @@ export * from './governance.js';
6
6
  export * from './governance_proposer.js';
7
7
  export * from './gse.js';
8
8
  export * from './inbox.js';
9
+ export * from './log.js';
9
10
  export * from './multicall.js';
10
11
  export * from './outbox.js';
11
12
  export * from './registry.js';
@@ -0,0 +1,13 @@
1
+ import type { Buffer32 } from '@aztec/foundation/buffer';
2
+
3
+ /** Base L1 event log with common fields. */
4
+ export type L1EventLog<T> = {
5
+ /** L1 block number where the event was emitted. */
6
+ l1BlockNumber: bigint;
7
+ /** L1 block hash. */
8
+ l1BlockHash: Buffer32;
9
+ /** L1 transaction hash that emitted the event. */
10
+ l1TransactionHash: `0x${string}`;
11
+ /** Event-specific arguments. */
12
+ args: T;
13
+ };
@@ -30,6 +30,7 @@ import type { ViemClient } from '../types.js';
30
30
  import { formatViemError } from '../utils.js';
31
31
  import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
32
32
  import { GSEContract } from './gse.js';
33
+ import type { L1EventLog } from './log.js';
33
34
  import { SlasherContract } from './slasher_contract.js';
34
35
  import { TallySlashingProposerContract } from './tally_slashing_proposer.js';
35
36
  import { checkBlockTag } from './utils.js';
@@ -69,6 +70,7 @@ export type ViemHeader = {
69
70
  blockHeadersHash: `0x${string}`;
70
71
  blobsHash: `0x${string}`;
71
72
  inHash: `0x${string}`;
73
+ outHash: `0x${string}`;
72
74
  slotNumber: bigint;
73
75
  timestamp: bigint;
74
76
  coinbase: `0x${string}`;
@@ -185,6 +187,20 @@ export type RollupStatusResponse = {
185
187
  archiveOfMyCheckpoint: Fr;
186
188
  };
187
189
 
190
+ /** Arguments for the CheckpointProposed event. */
191
+ export type CheckpointProposedArgs = {
192
+ checkpointNumber: CheckpointNumber;
193
+ archive: Fr;
194
+ versionedBlobHashes: Buffer[];
195
+ /** Hash of attestations. Undefined for older events (backwards compatibility). */
196
+ attestationsHash?: Buffer32;
197
+ /** Digest of the payload. Undefined for older events (backwards compatibility). */
198
+ payloadDigest?: Buffer32;
199
+ };
200
+
201
+ /** Log type for CheckpointProposed events. */
202
+ export type CheckpointProposedLog = L1EventLog<CheckpointProposedArgs>;
203
+
188
204
  export class RollupContract {
189
205
  private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
190
206
 
@@ -965,4 +981,23 @@ export class RollupContract {
965
981
  },
966
982
  );
967
983
  }
984
+
985
+ /** Fetches CheckpointProposed events within the given block range. */
986
+ async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
987
+ const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
988
+ return logs
989
+ .filter(log => log.blockNumber! >= fromBlock && log.blockNumber! <= toBlock)
990
+ .map(log => ({
991
+ l1BlockNumber: log.blockNumber!,
992
+ l1BlockHash: Buffer32.fromString(log.blockHash!),
993
+ l1TransactionHash: log.transactionHash!,
994
+ args: {
995
+ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
996
+ archive: Fr.fromString(log.args.archive!),
997
+ versionedBlobHashes: log.args.versionedBlobHashes!.map(h => Buffer.from(h.slice(2), 'hex')),
998
+ attestationsHash: log.args.attestationsHash ? Buffer32.fromString(log.args.attestationsHash) : undefined,
999
+ payloadDigest: log.args.payloadDigest ? Buffer32.fromString(log.args.payloadDigest) : undefined,
1000
+ },
1001
+ }));
1002
+ }
968
1003
  }
@@ -10,7 +10,7 @@ import { fileURLToPath } from '@aztec/foundation/url';
10
10
  import { bn254 } from '@noble/curves/bn254';
11
11
  import type { Abi, Narrow } from 'abitype';
12
12
  import { spawn } from 'child_process';
13
- import { cpSync, existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync } from 'fs';
13
+ import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
14
14
  import { tmpdir } from 'os';
15
15
  import { dirname, join, resolve } from 'path';
16
16
  import readline from 'readline';
@@ -141,11 +141,14 @@ function cleanupDeployDir() {
141
141
  */
142
142
  export function prepareL1ContractsForDeployment(): string {
143
143
  if (preparedDeployDir && existsSync(preparedDeployDir)) {
144
+ logger.verbose(`Using cached deployment directory: ${preparedDeployDir}`);
144
145
  return preparedDeployDir;
145
146
  }
146
147
 
147
148
  const basePath = getL1ContractsPath();
149
+ logger.verbose(`Preparing L1 contracts from: ${basePath}`);
148
150
  const tempDir = mkdtempSync(join(tmpdir(), '.foundry-deploy-'));
151
+ logger.verbose(`Created temp directory for deployment: ${tempDir}`);
149
152
  preparedDeployDir = tempDir;
150
153
  process.on('exit', cleanupDeployDir);
151
154
 
@@ -157,13 +160,21 @@ export function prepareL1ContractsForDeployment(): string {
157
160
  cpSync(join(basePath, 'src'), join(tempDir, 'src'), copyOpts);
158
161
  cpSync(join(basePath, 'script'), join(tempDir, 'script'), copyOpts);
159
162
  cpSync(join(basePath, 'generated'), join(tempDir, 'generated'), copyOpts);
160
- cpSync(join(basePath, 'foundry.toml'), join(tempDir, 'foundry.toml'));
163
+ // Kludge: copy test/ to appease forge cache which references test/shouting.t.sol
164
+ cpSync(join(basePath, 'test'), join(tempDir, 'test'), copyOpts);
161
165
  cpSync(join(basePath, 'foundry.lock'), join(tempDir, 'foundry.lock'));
162
- for (const file of readdirSync(basePath)) {
163
- if (file.startsWith('solc-')) {
164
- cpSync(join(basePath, file), join(tempDir, file));
165
- }
166
+
167
+ // Update foundry.toml to use absolute path to solc binary (avoids copying to noexec tmpfs)
168
+ const foundryTomlPath = join(basePath, 'foundry.toml');
169
+ let foundryToml = readFileSync(foundryTomlPath, 'utf-8');
170
+ const solcPathMatch = foundryToml.match(/solc\s*=\s*"\.\/solc-([^"]+)"/);
171
+ if (solcPathMatch) {
172
+ const solcVersion = solcPathMatch[1];
173
+ const absoluteSolcPath = join(basePath, `solc-${solcVersion}`);
174
+ foundryToml = foundryToml.replace(/solc\s*=\s*"\.\/solc-[^"]+"/, `solc = "${absoluteSolcPath}"`);
175
+ logger.verbose(`Updated solc path in foundry.toml to: ${absoluteSolcPath}`);
166
176
  }
177
+ writeFileSync(join(tempDir, 'foundry.toml'), foundryToml);
167
178
 
168
179
  mkdirSync(join(tempDir, 'broadcast'));
169
180
  return tempDir;