@aztec/ethereum 0.0.0-test.0
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.
- package/README.md +3 -0
- package/dest/chain.d.ts +25 -0
- package/dest/chain.d.ts.map +1 -0
- package/dest/chain.js +53 -0
- package/dest/client.d.ts +16 -0
- package/dest/client.d.ts.map +1 -0
- package/dest/client.js +31 -0
- package/dest/config.d.ts +39 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +70 -0
- package/dest/constants.d.ts +4 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- package/dest/contracts/empire_base.d.ts +13 -0
- package/dest/contracts/empire_base.d.ts.map +1 -0
- package/dest/contracts/empire_base.js +11 -0
- package/dest/contracts/fee_juice.d.ts +15 -0
- package/dest/contracts/fee_juice.d.ts.map +1 -0
- package/dest/contracts/fee_juice.js +52 -0
- package/dest/contracts/forwarder.d.ts +24 -0
- package/dest/contracts/forwarder.d.ts.map +1 -0
- package/dest/contracts/forwarder.js +101 -0
- package/dest/contracts/governance.d.ts +79 -0
- package/dest/contracts/governance.d.ts.map +1 -0
- package/dest/contracts/governance.js +247 -0
- package/dest/contracts/governance_proposer.d.ts +28 -0
- package/dest/contracts/governance_proposer.d.ts.map +1 -0
- package/dest/contracts/governance_proposer.js +82 -0
- package/dest/contracts/index.d.ts +9 -0
- package/dest/contracts/index.d.ts.map +1 -0
- package/dest/contracts/index.js +8 -0
- package/dest/contracts/registry.d.ts +24 -0
- package/dest/contracts/registry.d.ts.map +1 -0
- package/dest/contracts/registry.js +85 -0
- package/dest/contracts/rollup.d.ts +92 -0
- package/dest/contracts/rollup.d.ts.map +1 -0
- package/dest/contracts/rollup.js +234 -0
- package/dest/contracts/slashing_proposer.d.ts +21 -0
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/slashing_proposer.js +47 -0
- package/dest/deploy_l1_contracts.d.ts +21210 -0
- package/dest/deploy_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_l1_contracts.js +687 -0
- package/dest/eth_cheat_codes.d.ts +147 -0
- package/dest/eth_cheat_codes.d.ts.map +1 -0
- package/dest/eth_cheat_codes.js +303 -0
- package/dest/index.d.ts +14 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +13 -0
- package/dest/l1_contract_addresses.d.ts +57 -0
- package/dest/l1_contract_addresses.d.ts.map +1 -0
- package/dest/l1_contract_addresses.js +97 -0
- package/dest/l1_reader.d.ts +16 -0
- package/dest/l1_reader.d.ts.map +1 -0
- package/dest/l1_reader.js +27 -0
- package/dest/l1_tx_utils.d.ts +192 -0
- package/dest/l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils.js +641 -0
- package/dest/l1_tx_utils_with_blobs.d.ts +12 -0
- package/dest/l1_tx_utils_with_blobs.d.ts.map +1 -0
- package/dest/l1_tx_utils_with_blobs.js +64 -0
- package/dest/queries.d.ts +12 -0
- package/dest/queries.d.ts.map +1 -0
- package/dest/queries.js +35 -0
- package/dest/test/delayed_tx_utils.d.ts +8 -0
- package/dest/test/delayed_tx_utils.d.ts.map +1 -0
- package/dest/test/delayed_tx_utils.js +21 -0
- package/dest/test/eth_cheat_codes_with_state.d.ts +18 -0
- package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -0
- package/dest/test/eth_cheat_codes_with_state.js +34 -0
- package/dest/test/index.d.ts +6 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +5 -0
- package/dest/test/start_anvil.d.ts +12 -0
- package/dest/test/start_anvil.d.ts.map +1 -0
- package/dest/test/start_anvil.js +46 -0
- package/dest/test/tx_delayer.d.ts +25 -0
- package/dest/test/tx_delayer.d.ts.map +1 -0
- package/dest/test/tx_delayer.js +116 -0
- package/dest/test/upgrade_utils.d.ts +11 -0
- package/dest/test/upgrade_utils.d.ts.map +1 -0
- package/dest/test/upgrade_utils.js +104 -0
- package/dest/types.d.ts +14 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +1 -0
- package/dest/utils.d.ts +24 -0
- package/dest/utils.d.ts.map +1 -0
- package/dest/utils.js +209 -0
- package/package.json +98 -0
- package/src/chain.ts +71 -0
- package/src/client.ts +58 -0
- package/src/config.ts +103 -0
- package/src/constants.ts +4 -0
- package/src/contracts/empire_base.ts +19 -0
- package/src/contracts/fee_juice.ts +43 -0
- package/src/contracts/forwarder.ts +132 -0
- package/src/contracts/governance.ts +285 -0
- package/src/contracts/governance_proposer.ts +82 -0
- package/src/contracts/index.ts +8 -0
- package/src/contracts/registry.ts +106 -0
- package/src/contracts/rollup.ts +274 -0
- package/src/contracts/slashing_proposer.ts +51 -0
- package/src/deploy_l1_contracts.ts +948 -0
- package/src/eth_cheat_codes.ts +314 -0
- package/src/index.ts +13 -0
- package/src/l1_contract_addresses.ts +109 -0
- package/src/l1_reader.ts +42 -0
- package/src/l1_tx_utils.ts +847 -0
- package/src/l1_tx_utils_with_blobs.ts +86 -0
- package/src/queries.ts +58 -0
- package/src/test/delayed_tx_utils.ts +24 -0
- package/src/test/eth_cheat_codes_with_state.ts +38 -0
- package/src/test/index.ts +5 -0
- package/src/test/start_anvil.ts +52 -0
- package/src/test/tx_delayer.ts +163 -0
- package/src/test/upgrade_utils.ts +100 -0
- package/src/types.ts +33 -0
- package/src/utils.ts +276 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { memoize } from '@aztec/foundation/decorators';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import type { ViemSignature } from '@aztec/foundation/eth-signature';
|
|
4
|
+
import { RollupAbi, RollupStorage, SlasherAbi } from '@aztec/l1-artifacts';
|
|
5
|
+
|
|
6
|
+
import { type Account, type GetContractReturnType, type Hex, getAddress, getContract } from 'viem';
|
|
7
|
+
|
|
8
|
+
import { getPublicClient } from '../client.js';
|
|
9
|
+
import type { DeployL1ContractsReturnType } from '../deploy_l1_contracts.js';
|
|
10
|
+
import type { L1ContractAddresses } from '../l1_contract_addresses.js';
|
|
11
|
+
import type { L1ReaderConfig } from '../l1_reader.js';
|
|
12
|
+
import type { ViemPublicClient } from '../types.js';
|
|
13
|
+
import { formatViemError } from '../utils.js';
|
|
14
|
+
import { SlashingProposerContract } from './slashing_proposer.js';
|
|
15
|
+
|
|
16
|
+
export type L1RollupContractAddresses = Pick<
|
|
17
|
+
L1ContractAddresses,
|
|
18
|
+
| 'rollupAddress'
|
|
19
|
+
| 'inboxAddress'
|
|
20
|
+
| 'outboxAddress'
|
|
21
|
+
| 'feeJuicePortalAddress'
|
|
22
|
+
| 'feeJuiceAddress'
|
|
23
|
+
| 'stakingAssetAddress'
|
|
24
|
+
| 'rewardDistributorAddress'
|
|
25
|
+
| 'slashFactoryAddress'
|
|
26
|
+
>;
|
|
27
|
+
|
|
28
|
+
export type EpochProofPublicInputArgs = {
|
|
29
|
+
previousArchive: `0x${string}`;
|
|
30
|
+
endArchive: `0x${string}`;
|
|
31
|
+
previousBlockHash: `0x${string}`;
|
|
32
|
+
endBlockHash: `0x${string}`;
|
|
33
|
+
endTimestamp: bigint;
|
|
34
|
+
outHash: `0x${string}`;
|
|
35
|
+
proverId: `0x${string}`;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export class RollupContract {
|
|
39
|
+
private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>;
|
|
40
|
+
|
|
41
|
+
static get checkBlobStorageSlot(): bigint {
|
|
42
|
+
const asString = RollupStorage.find(storage => storage.label === 'checkBlob')?.slot;
|
|
43
|
+
if (asString === undefined) {
|
|
44
|
+
throw new Error('checkBlobStorageSlot not found');
|
|
45
|
+
}
|
|
46
|
+
return BigInt(asString);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static getFromL1ContractsValues(deployL1ContractsValues: DeployL1ContractsReturnType) {
|
|
50
|
+
const {
|
|
51
|
+
publicClient,
|
|
52
|
+
l1ContractAddresses: { rollupAddress },
|
|
53
|
+
} = deployL1ContractsValues;
|
|
54
|
+
return new RollupContract(publicClient, rollupAddress.toString());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static getFromConfig(config: L1ReaderConfig) {
|
|
58
|
+
const client = getPublicClient(config);
|
|
59
|
+
const address = config.l1Contracts.rollupAddress.toString();
|
|
60
|
+
return new RollupContract(client, address);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
constructor(public readonly client: ViemPublicClient, address: Hex | EthAddress) {
|
|
64
|
+
if (address instanceof EthAddress) {
|
|
65
|
+
address = address.toString();
|
|
66
|
+
}
|
|
67
|
+
this.rollup = getContract({ address, abi: RollupAbi, client });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public get address() {
|
|
71
|
+
return this.rollup.address;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@memoize
|
|
75
|
+
public async getSlashingProposer() {
|
|
76
|
+
const slasherAddress = await this.rollup.read.getSlasher();
|
|
77
|
+
const slasher = getContract({ address: slasherAddress, abi: SlasherAbi, client: this.client });
|
|
78
|
+
const proposerAddress = await slasher.read.PROPOSER();
|
|
79
|
+
return new SlashingProposerContract(this.client, proposerAddress);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@memoize
|
|
83
|
+
getL1StartBlock() {
|
|
84
|
+
return this.rollup.read.L1_BLOCK_AT_GENESIS();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@memoize
|
|
88
|
+
getL1GenesisTime() {
|
|
89
|
+
return this.rollup.read.getGenesisTime();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@memoize
|
|
93
|
+
getProofSubmissionWindow() {
|
|
94
|
+
return this.rollup.read.getProofSubmissionWindow();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@memoize
|
|
98
|
+
getEpochDuration() {
|
|
99
|
+
return this.rollup.read.getEpochDuration();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@memoize
|
|
103
|
+
getSlotDuration() {
|
|
104
|
+
return this.rollup.read.getSlotDuration();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@memoize
|
|
108
|
+
getTargetCommitteeSize() {
|
|
109
|
+
return this.rollup.read.getTargetCommitteeSize();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@memoize
|
|
113
|
+
getMinimumStake() {
|
|
114
|
+
return this.rollup.read.getMinimumStake();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public async getSlashingProposerAddress() {
|
|
118
|
+
const slasherAddress = await this.rollup.read.getSlasher();
|
|
119
|
+
const slasher = getContract({
|
|
120
|
+
address: getAddress(slasherAddress.toString()),
|
|
121
|
+
abi: SlasherAbi,
|
|
122
|
+
client: this.client,
|
|
123
|
+
});
|
|
124
|
+
return EthAddress.fromString(await slasher.read.PROPOSER());
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getBlockNumber() {
|
|
128
|
+
return this.rollup.read.getPendingBlockNumber();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
getProvenBlockNumber() {
|
|
132
|
+
return this.rollup.read.getProvenBlockNumber();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
getSlotNumber() {
|
|
136
|
+
return this.rollup.read.getCurrentSlot();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
getCommitteeAt(timestamp: bigint) {
|
|
140
|
+
return this.rollup.read.getCommitteeAt([timestamp]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getSampleSeedAt(timestamp: bigint) {
|
|
144
|
+
return this.rollup.read.getSampleSeedAt([timestamp]);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
getCurrentSampleSeed() {
|
|
148
|
+
return this.rollup.read.getCurrentSampleSeed();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getCurrentEpochCommittee() {
|
|
152
|
+
return this.rollup.read.getCurrentEpochCommittee();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
getCurrentProposer() {
|
|
156
|
+
return this.rollup.read.getCurrentProposer();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
getProposerAt(timestamp: bigint) {
|
|
160
|
+
return this.rollup.read.getProposerAt([timestamp]);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getBlock(blockNumber: bigint) {
|
|
164
|
+
return this.rollup.read.getBlock([blockNumber]);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
getTips() {
|
|
168
|
+
return this.rollup.read.getTips();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
getTimestampForSlot(slot: bigint) {
|
|
172
|
+
return this.rollup.read.getTimestampForSlot([slot]);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async getEpochNumber(blockNumber?: bigint) {
|
|
176
|
+
blockNumber ??= await this.getBlockNumber();
|
|
177
|
+
return this.rollup.read.getEpochForBlock([BigInt(blockNumber)]);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async getRollupAddresses(): Promise<L1RollupContractAddresses> {
|
|
181
|
+
const [
|
|
182
|
+
inboxAddress,
|
|
183
|
+
outboxAddress,
|
|
184
|
+
feeJuicePortalAddress,
|
|
185
|
+
rewardDistributorAddress,
|
|
186
|
+
feeJuiceAddress,
|
|
187
|
+
stakingAssetAddress,
|
|
188
|
+
] = (
|
|
189
|
+
await Promise.all([
|
|
190
|
+
this.rollup.read.getInbox(),
|
|
191
|
+
this.rollup.read.getOutbox(),
|
|
192
|
+
this.rollup.read.getFeeAssetPortal(),
|
|
193
|
+
this.rollup.read.getRewardDistributor(),
|
|
194
|
+
this.rollup.read.getFeeAsset(),
|
|
195
|
+
this.rollup.read.getStakingAsset(),
|
|
196
|
+
] as const)
|
|
197
|
+
).map(EthAddress.fromString);
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
rollupAddress: EthAddress.fromString(this.address),
|
|
201
|
+
inboxAddress,
|
|
202
|
+
outboxAddress,
|
|
203
|
+
feeJuicePortalAddress,
|
|
204
|
+
feeJuiceAddress,
|
|
205
|
+
stakingAssetAddress,
|
|
206
|
+
rewardDistributorAddress,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public async getEpochNumberForSlotNumber(slotNumber: bigint): Promise<bigint> {
|
|
211
|
+
return await this.rollup.read.getEpochAtSlot([slotNumber]);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
getEpochProofPublicInputs(
|
|
215
|
+
args: readonly [bigint, bigint, EpochProofPublicInputArgs, readonly `0x${string}`[], `0x${string}`, `0x${string}`],
|
|
216
|
+
) {
|
|
217
|
+
return this.rollup.read.getEpochProofPublicInputs(args);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public async validateHeader(
|
|
221
|
+
args: readonly [
|
|
222
|
+
`0x${string}`,
|
|
223
|
+
ViemSignature[],
|
|
224
|
+
`0x${string}`,
|
|
225
|
+
bigint,
|
|
226
|
+
`0x${string}`,
|
|
227
|
+
{
|
|
228
|
+
ignoreDA: boolean;
|
|
229
|
+
ignoreSignatures: boolean;
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
account: `0x${string}` | Account,
|
|
233
|
+
): Promise<void> {
|
|
234
|
+
try {
|
|
235
|
+
await this.rollup.read.validateHeader(args, { account });
|
|
236
|
+
} catch (error: unknown) {
|
|
237
|
+
throw formatViemError(error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* @notice Calls `canProposeAtTime` with the time of the next Ethereum block and the sender address
|
|
243
|
+
*
|
|
244
|
+
* @dev Throws if unable to propose
|
|
245
|
+
*
|
|
246
|
+
* @param archive - The archive that we expect to be current state
|
|
247
|
+
* @return [slot, blockNumber] - If you can propose, the L2 slot number and L2 block number of the next Ethereum block,
|
|
248
|
+
* @throws otherwise
|
|
249
|
+
*/
|
|
250
|
+
public async canProposeAtNextEthBlock(
|
|
251
|
+
archive: Buffer,
|
|
252
|
+
account: `0x${string}` | Account,
|
|
253
|
+
slotDuration: bigint | number,
|
|
254
|
+
): Promise<[bigint, bigint]> {
|
|
255
|
+
if (typeof slotDuration === 'number') {
|
|
256
|
+
slotDuration = BigInt(slotDuration);
|
|
257
|
+
}
|
|
258
|
+
const timeOfNextL1Slot = (await this.client.getBlock()).timestamp + slotDuration;
|
|
259
|
+
try {
|
|
260
|
+
const [slot, blockNumber] = await this.rollup.read.canProposeAtTime(
|
|
261
|
+
[timeOfNextL1Slot, `0x${archive.toString('hex')}`],
|
|
262
|
+
{ account },
|
|
263
|
+
);
|
|
264
|
+
return [slot, blockNumber];
|
|
265
|
+
} catch (err: unknown) {
|
|
266
|
+
throw formatViemError(err);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Calls getHasSubmitted directly. Returns whether the given prover has submitted a proof with the given length for the given epoch. */
|
|
271
|
+
public getHasSubmittedProof(epochNumber: number, numberOfBlocksInEpoch: number, prover: EthAddress) {
|
|
272
|
+
return this.rollup.read.getHasSubmitted([BigInt(epochNumber), BigInt(numberOfBlocksInEpoch), prover.toString()]);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { SlashingProposerAbi } from '@aztec/l1-artifacts';
|
|
3
|
+
|
|
4
|
+
import { type GetContractReturnType, type Hex, getContract } from 'viem';
|
|
5
|
+
|
|
6
|
+
import type { L1TxRequest } from '../l1_tx_utils.js';
|
|
7
|
+
import type { ViemPublicClient } from '../types.js';
|
|
8
|
+
import { type IEmpireBase, encodeVote } from './empire_base.js';
|
|
9
|
+
|
|
10
|
+
export class SlashingProposerContract implements IEmpireBase {
|
|
11
|
+
private readonly proposer: GetContractReturnType<typeof SlashingProposerAbi, ViemPublicClient>;
|
|
12
|
+
|
|
13
|
+
constructor(public readonly client: ViemPublicClient, address: Hex) {
|
|
14
|
+
this.proposer = getContract({ address, abi: SlashingProposerAbi, client });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public get address() {
|
|
18
|
+
return EthAddress.fromString(this.proposer.address);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public getQuorumSize() {
|
|
22
|
+
return this.proposer.read.N();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public getRoundSize() {
|
|
26
|
+
return this.proposer.read.M();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public computeRound(slot: bigint): Promise<bigint> {
|
|
30
|
+
return this.proposer.read.computeRound([slot]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async getRoundInfo(
|
|
34
|
+
rollupAddress: Hex,
|
|
35
|
+
round: bigint,
|
|
36
|
+
): Promise<{ lastVote: bigint; leader: Hex; executed: boolean }> {
|
|
37
|
+
const roundInfo = await this.proposer.read.rounds([rollupAddress, round]);
|
|
38
|
+
return {
|
|
39
|
+
lastVote: roundInfo[0],
|
|
40
|
+
leader: roundInfo[1],
|
|
41
|
+
executed: roundInfo[2],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public createVoteRequest(payload: Hex): L1TxRequest {
|
|
46
|
+
return {
|
|
47
|
+
to: this.address.toString(),
|
|
48
|
+
data: encodeVote(payload),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|