@aztec/ethereum 0.0.1-commit.b33fc05d0 → 0.0.1-commit.b3d3157a
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/dest/client.d.ts +25 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +60 -8
- package/dest/config.d.ts +6 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +5 -9
- package/dest/contracts/chain_state_override.d.ts +78 -0
- package/dest/contracts/chain_state_override.d.ts.map +1 -0
- package/dest/contracts/chain_state_override.js +137 -0
- package/dest/contracts/empire_base.d.ts +1 -3
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/fee_asset_price_oracle.d.ts +6 -2
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -1
- package/dest/contracts/fee_asset_price_oracle.js +11 -6
- package/dest/contracts/governance.d.ts +108 -33
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +193 -12
- package/dest/contracts/governance_proposer.d.ts +33 -3
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +51 -9
- package/dest/contracts/inbox.d.ts +3 -3
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +12 -7
- package/dest/contracts/index.d.ts +3 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +2 -2
- package/dest/contracts/multicall.d.ts +127 -12
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +201 -94
- package/dest/contracts/outbox.d.ts +27 -4
- package/dest/contracts/outbox.d.ts.map +1 -1
- package/dest/contracts/outbox.js +34 -7
- package/dest/contracts/rollup.d.ts +5250 -24
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +366 -64
- package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +3 -4
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +13 -15
- package/dest/deploy_aztec_l1_contracts.d.ts +3 -6
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +2 -4
- package/dest/generated/l1-contracts-defaults.d.ts +1 -1
- package/dest/generated/l1-contracts-defaults.js +1 -1
- package/dest/l1_artifacts.d.ts +13409 -15883
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_artifacts.js +9 -24
- package/dest/l1_contract_addresses.d.ts +61 -65
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +101 -82
- package/dest/l1_reader.d.ts +5 -5
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +9 -7
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +9 -1
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +54 -35
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +2 -1
- package/dest/l1_tx_utils/tx_delayer.d.ts +5 -3
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -1
- package/dest/l1_tx_utils/tx_delayer.js +7 -5
- package/dest/publisher_manager.d.ts +21 -7
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +81 -7
- package/dest/queries.d.ts +13 -2
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +62 -3
- package/dest/test/chain_monitor.d.ts +23 -3
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +38 -2
- package/dest/test/eth_cheat_codes.d.ts +12 -4
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +17 -4
- package/dest/test/rollup_cheat_codes.d.ts +31 -3
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +59 -7
- package/dest/test/start_anvil.d.ts +8 -1
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +16 -2
- package/dest/utils.d.ts +9 -2
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +34 -6
- package/package.json +6 -6
- package/src/client.ts +66 -2
- package/src/config.ts +9 -13
- package/src/contracts/chain_state_override.ts +200 -0
- package/src/contracts/empire_base.ts +0 -2
- package/src/contracts/fee_asset_price_oracle.ts +10 -5
- package/src/contracts/governance.ts +266 -9
- package/src/contracts/governance_proposer.ts +52 -5
- package/src/contracts/inbox.ts +13 -5
- package/src/contracts/index.ts +2 -2
- package/src/contracts/multicall.ts +243 -105
- package/src/contracts/outbox.ts +42 -8
- package/src/contracts/rollup.ts +401 -64
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +14 -16
- package/src/deploy_aztec_l1_contracts.ts +1 -5
- package/src/generated/l1-contracts-defaults.ts +1 -1
- package/src/l1_artifacts.ts +12 -35
- package/src/l1_contract_addresses.ts +120 -94
- package/src/l1_reader.ts +17 -10
- package/src/l1_tx_utils/l1_tx_utils.ts +51 -28
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +2 -1
- package/src/l1_tx_utils/tx_delayer.ts +16 -7
- package/src/publisher_manager.ts +105 -10
- package/src/queries.ts +70 -4
- package/src/test/chain_monitor.ts +65 -3
- package/src/test/eth_cheat_codes.ts +16 -4
- package/src/test/rollup_cheat_codes.ts +64 -6
- package/src/test/start_anvil.ts +25 -2
- package/src/utils.ts +30 -6
- package/dest/contracts/empire_slashing_proposer.d.ts +0 -69
- package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/empire_slashing_proposer.js +0 -216
- package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
- package/src/contracts/empire_slashing_proposer.ts +0 -265
package/src/contracts/rollup.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
4
4
|
import { memoize } from '@aztec/foundation/decorators';
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
6
|
import type { ViemSignature } from '@aztec/foundation/eth-signature';
|
|
7
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
7
8
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
9
|
+
import { getErrorCause } from '@aztec/foundation/types';
|
|
8
10
|
import { EscapeHatchAbi } from '@aztec/l1-artifacts/EscapeHatchAbi';
|
|
9
11
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
10
12
|
import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
|
|
@@ -12,10 +14,15 @@ import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
|
|
|
12
14
|
import chunk from 'lodash.chunk';
|
|
13
15
|
import {
|
|
14
16
|
type Account,
|
|
17
|
+
ContractFunctionRevertedError,
|
|
15
18
|
type GetContractReturnType,
|
|
16
19
|
type Hex,
|
|
20
|
+
type Log,
|
|
21
|
+
RpcRequestError,
|
|
17
22
|
type StateOverride,
|
|
18
23
|
type WatchContractEventReturnType,
|
|
24
|
+
decodeErrorResult,
|
|
25
|
+
encodeAbiParameters,
|
|
19
26
|
encodeFunctionData,
|
|
20
27
|
getContract,
|
|
21
28
|
hexToBigInt,
|
|
@@ -29,11 +36,10 @@ import type { L1ReaderConfig } from '../l1_reader.js';
|
|
|
29
36
|
import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
|
|
30
37
|
import type { ViemClient } from '../types.js';
|
|
31
38
|
import { formatViemError } from '../utils.js';
|
|
32
|
-
import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
|
|
33
39
|
import { GSEContract } from './gse.js';
|
|
34
40
|
import type { L1EventLog } from './log.js';
|
|
35
41
|
import { SlasherContract } from './slasher_contract.js';
|
|
36
|
-
import {
|
|
42
|
+
import { SlashingProposerContract } from './slashing_proposer.js';
|
|
37
43
|
import { checkBlockTag } from './utils.js';
|
|
38
44
|
|
|
39
45
|
export type ViemCommitteeAttestation = {
|
|
@@ -55,7 +61,6 @@ export type L1RollupContractAddresses = Pick<
|
|
|
55
61
|
| 'feeJuiceAddress'
|
|
56
62
|
| 'stakingAssetAddress'
|
|
57
63
|
| 'rewardDistributorAddress'
|
|
58
|
-
| 'slashFactoryAddress'
|
|
59
64
|
| 'gseAddress'
|
|
60
65
|
>;
|
|
61
66
|
|
|
@@ -85,12 +90,6 @@ export type ViemGasFees = {
|
|
|
85
90
|
feePerL2Gas: bigint;
|
|
86
91
|
};
|
|
87
92
|
|
|
88
|
-
export enum SlashingProposerType {
|
|
89
|
-
None = 0,
|
|
90
|
-
Tally = 1,
|
|
91
|
-
Empire = 2,
|
|
92
|
-
}
|
|
93
|
-
|
|
94
93
|
/**
|
|
95
94
|
* Status of a validator/attester in the staking system.
|
|
96
95
|
* Matches the Status enum in StakingLib.sol
|
|
@@ -134,6 +133,39 @@ export type L1FeeData = {
|
|
|
134
133
|
blobFee: bigint;
|
|
135
134
|
};
|
|
136
135
|
|
|
136
|
+
/** Field offsets within the CompressedTempCheckpointLog struct in Solidity storage. */
|
|
137
|
+
export enum TempCheckpointLogField {
|
|
138
|
+
HeaderHash = 0,
|
|
139
|
+
BlobCommitmentsHash = 1,
|
|
140
|
+
OutHash = 2,
|
|
141
|
+
AttestationsHash = 3,
|
|
142
|
+
PayloadDigest = 4,
|
|
143
|
+
SlotNumber = 5,
|
|
144
|
+
FeeHeader = 6,
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Field-level override input for `tempCheckpointLogs[checkpointNumber]`. Covers the fields the
|
|
149
|
+
* `propose()` path actually reads back. `payloadDigest` is `Buffer32` because it carries an
|
|
150
|
+
* arbitrary `bytes32` value rather than a BN254 scalar. `slotNumber` carries the uint32 portion
|
|
151
|
+
* of the on-chain `CompressedSlot`.
|
|
152
|
+
*/
|
|
153
|
+
export type TempCheckpointLogOverrideFields = {
|
|
154
|
+
headerHash?: Fr;
|
|
155
|
+
outHash?: Fr;
|
|
156
|
+
payloadDigest?: Buffer32;
|
|
157
|
+
slotNumber?: SlotNumber;
|
|
158
|
+
feeHeader?: FeeHeader;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/** Components of the minimum fee per mana, as returned by the L1 rollup contract. */
|
|
162
|
+
export type ManaMinFeeComponents = {
|
|
163
|
+
sequencerCost: bigint;
|
|
164
|
+
proverCost: bigint;
|
|
165
|
+
congestionCost: bigint;
|
|
166
|
+
congestionMultiplier: bigint;
|
|
167
|
+
};
|
|
168
|
+
|
|
137
169
|
/**
|
|
138
170
|
* Reward configuration for the rollup
|
|
139
171
|
*/
|
|
@@ -202,8 +234,35 @@ export type CheckpointProposedArgs = {
|
|
|
202
234
|
/** Log type for CheckpointProposed events. */
|
|
203
235
|
export type CheckpointProposedLog = L1EventLog<CheckpointProposedArgs>;
|
|
204
236
|
|
|
237
|
+
const INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR = 'ValidatorSelection__InsufficientValidatorSetSize';
|
|
238
|
+
|
|
239
|
+
function isValidatorSelectionError(err: unknown, errorName: string): boolean {
|
|
240
|
+
return (
|
|
241
|
+
getErrorCause(err, ContractFunctionRevertedError)?.data?.errorName === errorName ||
|
|
242
|
+
decodeRpcRequestErrorName(err) === errorName
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function decodeRpcRequestErrorName(err: unknown): string | undefined {
|
|
247
|
+
const data = getErrorCause(err, RpcRequestError)?.data;
|
|
248
|
+
if (!isHexString(data)) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
return decodeErrorResult({ abi: RollupAbi, data }).errorName;
|
|
254
|
+
} catch {
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function isHexString(value: unknown): value is Hex {
|
|
260
|
+
return typeof value === 'string' && value.startsWith('0x');
|
|
261
|
+
}
|
|
262
|
+
|
|
205
263
|
export class RollupContract {
|
|
206
264
|
private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
|
|
265
|
+
private readonly logger = createLogger('ethereum:rollup');
|
|
207
266
|
|
|
208
267
|
private static cachedStfStorageSlot: Hex | undefined;
|
|
209
268
|
private cachedEscapeHatch?: {
|
|
@@ -233,7 +292,7 @@ export class RollupContract {
|
|
|
233
292
|
|
|
234
293
|
static getFromConfig(config: L1ReaderConfig) {
|
|
235
294
|
const client = getPublicClient(config);
|
|
236
|
-
const address = config.
|
|
295
|
+
const address = config.rollupAddress.toString();
|
|
237
296
|
return new RollupContract(client, address);
|
|
238
297
|
}
|
|
239
298
|
|
|
@@ -259,34 +318,18 @@ export class RollupContract {
|
|
|
259
318
|
return this.rollup;
|
|
260
319
|
}
|
|
261
320
|
|
|
262
|
-
public async getSlashingProposer(): Promise<
|
|
263
|
-
EmpireSlashingProposerContract | TallySlashingProposerContract | undefined
|
|
264
|
-
> {
|
|
321
|
+
public async getSlashingProposer(): Promise<SlashingProposerContract | undefined> {
|
|
265
322
|
const slasher = await this.getSlasherContract();
|
|
266
323
|
if (!slasher) {
|
|
267
324
|
return undefined;
|
|
268
325
|
}
|
|
269
326
|
|
|
270
327
|
const proposerAddress = await slasher.getProposer();
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
type: 'function',
|
|
274
|
-
name: 'SLASHING_PROPOSER_TYPE',
|
|
275
|
-
inputs: [],
|
|
276
|
-
outputs: [{ name: '', type: 'uint8', internalType: 'enum SlasherFlavor' }],
|
|
277
|
-
stateMutability: 'view',
|
|
278
|
-
},
|
|
279
|
-
] as const;
|
|
280
|
-
|
|
281
|
-
const proposer = getContract({ address: proposerAddress.toString(), abi: proposerAbi, client: this.client });
|
|
282
|
-
const proposerType = await proposer.read.SLASHING_PROPOSER_TYPE();
|
|
283
|
-
if (proposerType === SlashingProposerType.Tally.valueOf()) {
|
|
284
|
-
return new TallySlashingProposerContract(this.client, proposerAddress);
|
|
285
|
-
} else if (proposerType === SlashingProposerType.Empire.valueOf()) {
|
|
286
|
-
return new EmpireSlashingProposerContract(this.client, proposerAddress);
|
|
287
|
-
} else {
|
|
288
|
-
throw new Error(`Unknown slashing proposer type: ${proposerType}`);
|
|
328
|
+
if (proposerAddress.isZero()) {
|
|
329
|
+
return undefined;
|
|
289
330
|
}
|
|
331
|
+
|
|
332
|
+
return new SlashingProposerContract(this.client, proposerAddress);
|
|
290
333
|
}
|
|
291
334
|
|
|
292
335
|
@memoize
|
|
@@ -379,6 +422,20 @@ export class RollupContract {
|
|
|
379
422
|
return Fr.fromString(await this.rollup.read.archiveAt([0n]));
|
|
380
423
|
}
|
|
381
424
|
|
|
425
|
+
@memoize
|
|
426
|
+
async getVkTreeRoot(): Promise<Fr> {
|
|
427
|
+
const slot = BigInt(RollupContract.stfStorageSlot) + 3n;
|
|
428
|
+
const value = await this.client.getStorageAt({ address: this.address, slot: `0x${slot.toString(16)}` });
|
|
429
|
+
return Fr.fromString(value ?? '0x0');
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
@memoize
|
|
433
|
+
async getProtocolContractsHash(): Promise<Fr> {
|
|
434
|
+
const slot = BigInt(RollupContract.stfStorageSlot) + 4n;
|
|
435
|
+
const value = await this.client.getStorageAt({ address: this.address, slot: `0x${slot.toString(16)}` });
|
|
436
|
+
return Fr.fromString(value ?? '0x0');
|
|
437
|
+
}
|
|
438
|
+
|
|
382
439
|
/**
|
|
383
440
|
* Returns rollup constants used for epoch queries.
|
|
384
441
|
* Return type is `L1RollupConstants` which is defined in stdlib,
|
|
@@ -473,7 +530,11 @@ export class RollupContract {
|
|
|
473
530
|
|
|
474
531
|
const [isOpen] = await escapeHatch.read.isHatchOpen([BigInt(epoch)]);
|
|
475
532
|
return isOpen;
|
|
476
|
-
} catch {
|
|
533
|
+
} catch (err) {
|
|
534
|
+
this.logger.warn('isEscapeHatchOpen failed (treating as closed); RPC or contract error may cause liveness risk', {
|
|
535
|
+
epoch: Number(epoch),
|
|
536
|
+
error: err,
|
|
537
|
+
});
|
|
477
538
|
return false;
|
|
478
539
|
}
|
|
479
540
|
}
|
|
@@ -509,8 +570,9 @@ export class RollupContract {
|
|
|
509
570
|
return this.rollup.read.getCheckpointReward();
|
|
510
571
|
}
|
|
511
572
|
|
|
512
|
-
async getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
513
|
-
|
|
573
|
+
async getCheckpointNumber(options?: { blockNumber?: bigint }): Promise<CheckpointNumber> {
|
|
574
|
+
await checkBlockTag(options?.blockNumber, this.client);
|
|
575
|
+
return CheckpointNumber.fromBigInt(await this.rollup.read.getPendingCheckpointNumber(options));
|
|
514
576
|
}
|
|
515
577
|
|
|
516
578
|
async getProvenCheckpointNumber(options?: { blockNumber?: bigint }): Promise<CheckpointNumber> {
|
|
@@ -518,18 +580,31 @@ export class RollupContract {
|
|
|
518
580
|
return CheckpointNumber.fromBigInt(await this.rollup.read.getProvenCheckpointNumber(options));
|
|
519
581
|
}
|
|
520
582
|
|
|
521
|
-
async getSlotNumber(): Promise<SlotNumber> {
|
|
522
|
-
|
|
583
|
+
async getSlotNumber(options?: { blockNumber?: bigint }): Promise<SlotNumber> {
|
|
584
|
+
await checkBlockTag(options?.blockNumber, this.client);
|
|
585
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot(options));
|
|
523
586
|
}
|
|
524
587
|
|
|
525
|
-
async getL1FeesAt(timestamp: bigint): Promise<L1FeeData> {
|
|
526
|
-
|
|
588
|
+
async getL1FeesAt(timestamp: bigint, options?: { blockNumber?: bigint }): Promise<L1FeeData> {
|
|
589
|
+
await checkBlockTag(options?.blockNumber, this.client);
|
|
590
|
+
const result = await this.rollup.read.getL1FeesAt([timestamp], options);
|
|
527
591
|
return {
|
|
528
592
|
baseFee: result.baseFee,
|
|
529
593
|
blobFee: result.blobFee,
|
|
530
594
|
};
|
|
531
595
|
}
|
|
532
596
|
|
|
597
|
+
async getFeeHeader(checkpointNumber: bigint): Promise<FeeHeader> {
|
|
598
|
+
const result = await this.rollup.read.getFeeHeader([checkpointNumber]);
|
|
599
|
+
return {
|
|
600
|
+
excessMana: result.excessMana,
|
|
601
|
+
manaUsed: result.manaUsed,
|
|
602
|
+
ethPerFeeAsset: result.ethPerFeeAsset,
|
|
603
|
+
congestionCost: result.congestionCost,
|
|
604
|
+
proverCost: result.proverCost,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
|
|
533
608
|
getEthPerFeeAsset(): Promise<bigint> {
|
|
534
609
|
return this.rollup.read.getEthPerFeeAsset();
|
|
535
610
|
}
|
|
@@ -543,7 +618,7 @@ export class RollupContract {
|
|
|
543
618
|
args: [timestamp],
|
|
544
619
|
})
|
|
545
620
|
.catch(e => {
|
|
546
|
-
if (e
|
|
621
|
+
if (isValidatorSelectionError(e, INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR)) {
|
|
547
622
|
return { result: undefined };
|
|
548
623
|
}
|
|
549
624
|
throw e;
|
|
@@ -573,7 +648,7 @@ export class RollupContract {
|
|
|
573
648
|
args: [],
|
|
574
649
|
})
|
|
575
650
|
.catch(e => {
|
|
576
|
-
if (e
|
|
651
|
+
if (isValidatorSelectionError(e, INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR)) {
|
|
577
652
|
return { result: undefined };
|
|
578
653
|
}
|
|
579
654
|
throw e;
|
|
@@ -604,8 +679,9 @@ export class RollupContract {
|
|
|
604
679
|
return EthAddress.fromString(result);
|
|
605
680
|
}
|
|
606
681
|
|
|
607
|
-
async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<CheckpointLog> {
|
|
608
|
-
|
|
682
|
+
async getCheckpoint(checkpointNumber: CheckpointNumber, options?: { blockNumber?: bigint }): Promise<CheckpointLog> {
|
|
683
|
+
await checkBlockTag(options?.blockNumber, this.client);
|
|
684
|
+
const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)], options);
|
|
609
685
|
return {
|
|
610
686
|
archive: Fr.fromString(result.archive),
|
|
611
687
|
headerHash: Buffer32.fromString(result.headerHash),
|
|
@@ -638,6 +714,30 @@ export class RollupContract {
|
|
|
638
714
|
);
|
|
639
715
|
}
|
|
640
716
|
|
|
717
|
+
/**
|
|
718
|
+
* Returns the effective pending checkpoint, accounting for potential prunes.
|
|
719
|
+
* When a prune can happen, the L1 contract uses the proven checkpoint instead of the pending one.
|
|
720
|
+
* This mirrors the behavior of getEffectivePendingCheckpointNumber in STFLib.sol.
|
|
721
|
+
* @param atTimestamp - The timestamp to evaluate pruneability at. Defaults to the current L1 block timestamp.
|
|
722
|
+
* @param options - Optional L1 block number to pin the queries to.
|
|
723
|
+
*/
|
|
724
|
+
getEffectivePendingCheckpoint(atTimestamp?: bigint, options?: { blockNumber?: bigint }) {
|
|
725
|
+
return retry(
|
|
726
|
+
async () => {
|
|
727
|
+
const timestamp = atTimestamp ?? (await this.client.getBlock()).timestamp;
|
|
728
|
+
const canPrune = await this.canPruneAtTime(timestamp, options);
|
|
729
|
+
if (canPrune) {
|
|
730
|
+
const provenCheckpointNumber = await this.getProvenCheckpointNumber(options);
|
|
731
|
+
return await this.getCheckpoint(provenCheckpointNumber, options);
|
|
732
|
+
}
|
|
733
|
+
const pendingCheckpointNumber = await this.getCheckpointNumber(options);
|
|
734
|
+
return await this.getCheckpoint(pendingCheckpointNumber, options);
|
|
735
|
+
},
|
|
736
|
+
'getting effective pending checkpoint',
|
|
737
|
+
makeBackoff([0.5, 0.5, 0.5]),
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
|
|
641
741
|
async getTips(): Promise<{ pending: CheckpointNumber; proven: CheckpointNumber }> {
|
|
642
742
|
const { pending, proven } = await this.rollup.read.getTips();
|
|
643
743
|
return {
|
|
@@ -756,14 +856,13 @@ export class RollupContract {
|
|
|
756
856
|
* timestamp of the next L1 block
|
|
757
857
|
* @throws otherwise
|
|
758
858
|
*/
|
|
759
|
-
public async
|
|
859
|
+
public async canProposeAt(
|
|
760
860
|
archive: Buffer,
|
|
761
861
|
account: `0x${string}` | Account,
|
|
762
|
-
|
|
763
|
-
|
|
862
|
+
timestamp: bigint,
|
|
863
|
+
stateOverride: StateOverride = [],
|
|
764
864
|
): Promise<{ slot: SlotNumber; checkpointNumber: CheckpointNumber; timeOfNextL1Slot: bigint }> {
|
|
765
|
-
const
|
|
766
|
-
const timeOfNextL1Slot = latestBlock.timestamp + BigInt(slotDuration);
|
|
865
|
+
const timeOfNextL1Slot = timestamp;
|
|
767
866
|
const who = typeof account === 'string' ? account : account.address;
|
|
768
867
|
|
|
769
868
|
try {
|
|
@@ -775,7 +874,7 @@ export class RollupContract {
|
|
|
775
874
|
functionName: 'canProposeAtTime',
|
|
776
875
|
args: [timeOfNextL1Slot, `0x${archive.toString('hex')}`, who],
|
|
777
876
|
account,
|
|
778
|
-
stateOverride
|
|
877
|
+
stateOverride,
|
|
779
878
|
});
|
|
780
879
|
|
|
781
880
|
return {
|
|
@@ -789,20 +888,32 @@ export class RollupContract {
|
|
|
789
888
|
}
|
|
790
889
|
|
|
791
890
|
/**
|
|
792
|
-
* Returns a state override that sets the pending
|
|
793
|
-
*
|
|
794
|
-
*
|
|
891
|
+
* Returns a state override that sets the pending and/or proven checkpoint numbers. Useful for simulations.
|
|
892
|
+
* Both values share a single storage slot (pending in the upper 128 bits, proven in the lower 128 bits), so
|
|
893
|
+
* a single combined override is emitted to avoid the second state-diff clobbering the first. The current live
|
|
894
|
+
* value is read once to preserve any half not being overridden. Returns an empty override if neither is set.
|
|
895
|
+
*
|
|
896
|
+
* Throws if the resulting `proven > pending`, which would crash the simulation: `STFLib.canPruneAtTime` calls
|
|
897
|
+
* `getEpochForCheckpoint(proven + 1)` whenever `pending != proven`, and that asserts `_n <= tips.pending`.
|
|
795
898
|
*/
|
|
796
|
-
public async
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
899
|
+
public async makeChainTipsOverride(override: {
|
|
900
|
+
pending?: CheckpointNumber;
|
|
901
|
+
proven?: CheckpointNumber;
|
|
902
|
+
}): Promise<StateOverride> {
|
|
903
|
+
if (override.pending === undefined && override.proven === undefined) {
|
|
800
904
|
return [];
|
|
801
905
|
}
|
|
802
906
|
const slot = RollupContract.stfStorageSlot;
|
|
803
907
|
const currentValue = await this.client.getStorageAt({ address: this.address, slot });
|
|
804
|
-
const
|
|
805
|
-
const
|
|
908
|
+
const currentRaw = currentValue ? hexToBigInt(currentValue) : 0n;
|
|
909
|
+
const currentPending = currentRaw >> 128n;
|
|
910
|
+
const currentProven = currentRaw & ((1n << 128n) - 1n);
|
|
911
|
+
const newPending = override.pending !== undefined ? BigInt(override.pending) : currentPending;
|
|
912
|
+
const newProven = override.proven !== undefined ? BigInt(override.proven) : currentProven;
|
|
913
|
+
if (newProven > newPending) {
|
|
914
|
+
throw new Error(`Invalid chain tips override: proven (${newProven}) > pending (${newPending})`);
|
|
915
|
+
}
|
|
916
|
+
const newValue = (newPending << 128n) | newProven;
|
|
806
917
|
return [
|
|
807
918
|
{
|
|
808
919
|
address: this.address,
|
|
@@ -811,6 +922,168 @@ export class RollupContract {
|
|
|
811
922
|
];
|
|
812
923
|
}
|
|
813
924
|
|
|
925
|
+
/**
|
|
926
|
+
* Returns a state override that patches `tempCheckpointLogs[checkpointNumber]` with every field that
|
|
927
|
+
* the L1 contract reads during `propose()` for the checkpoint that builds on top of it (proposer
|
|
928
|
+
* pipelining simulation). Mirrors the writes done by `ProposeLib.addTempCheckpointLog`.
|
|
929
|
+
*
|
|
930
|
+
* `blobCommitmentsHash` and `attestationsHash` are intentionally not exposed here — the propose path
|
|
931
|
+
* never asserts against them, so leaving them at storage zero is harmless.
|
|
932
|
+
*/
|
|
933
|
+
public async makeTempCheckpointLogOverride(
|
|
934
|
+
checkpointNumber: CheckpointNumber,
|
|
935
|
+
fields: TempCheckpointLogOverrideFields,
|
|
936
|
+
): Promise<StateOverride> {
|
|
937
|
+
const constants = await this.getRollupConstants();
|
|
938
|
+
const slotAt = (field: TempCheckpointLogField) =>
|
|
939
|
+
`0x${this.computeTempCheckpointLogStorageSlot(checkpointNumber, field, constants).toString(16).padStart(64, '0')}` as const;
|
|
940
|
+
const word = (v: bigint) => `0x${v.toString(16).padStart(64, '0')}` as const;
|
|
941
|
+
|
|
942
|
+
const stateDiff: { slot: `0x${string}`; value: `0x${string}` }[] = [];
|
|
943
|
+
|
|
944
|
+
if (fields.headerHash) {
|
|
945
|
+
stateDiff.push({ slot: slotAt(TempCheckpointLogField.HeaderHash), value: fields.headerHash.toString() });
|
|
946
|
+
}
|
|
947
|
+
if (fields.outHash) {
|
|
948
|
+
stateDiff.push({ slot: slotAt(TempCheckpointLogField.OutHash), value: fields.outHash.toString() });
|
|
949
|
+
}
|
|
950
|
+
if (fields.payloadDigest) {
|
|
951
|
+
stateDiff.push({
|
|
952
|
+
slot: slotAt(TempCheckpointLogField.PayloadDigest),
|
|
953
|
+
value: fields.payloadDigest.toString() as `0x${string}`,
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
if (fields.slotNumber !== undefined) {
|
|
957
|
+
// CompressedSlot is uint32 on L1 (SafeCast.toUint32 reverts on overflow). Match that behavior here
|
|
958
|
+
// so a malformed override surfaces immediately rather than silently truncating into a wrong slot.
|
|
959
|
+
const slotNumber = BigInt(fields.slotNumber);
|
|
960
|
+
if (slotNumber < 0n || slotNumber > 0xffffffffn) {
|
|
961
|
+
throw new Error(`slotNumber ${slotNumber} does not fit in uint32`);
|
|
962
|
+
}
|
|
963
|
+
stateDiff.push({ slot: slotAt(TempCheckpointLogField.SlotNumber), value: word(slotNumber) });
|
|
964
|
+
}
|
|
965
|
+
if (fields.feeHeader) {
|
|
966
|
+
stateDiff.push({
|
|
967
|
+
slot: slotAt(TempCheckpointLogField.FeeHeader),
|
|
968
|
+
value: word(RollupContract.compressFeeHeader(fields.feeHeader)),
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
if (stateDiff.length === 0) {
|
|
973
|
+
return [];
|
|
974
|
+
}
|
|
975
|
+
return [{ address: this.address, stateDiff }];
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Returns a state override that sets archives[checkpointNumber] to the given archive value.
|
|
980
|
+
* Used when simulating a canProposeAtTime call where the local archive differs from L1
|
|
981
|
+
* (e.g. pipelining where the parent checkpoint hasn't landed on L1 yet).
|
|
982
|
+
*/
|
|
983
|
+
public makeArchiveOverride(checkpointNumber: CheckpointNumber, archive: Fr): StateOverride {
|
|
984
|
+
const archivesMappingBase = hexToBigInt(RollupContract.stfStorageSlot) + 1n;
|
|
985
|
+
const archiveSlot = hexToBigInt(
|
|
986
|
+
keccak256(
|
|
987
|
+
encodeAbiParameters(
|
|
988
|
+
[{ type: 'uint256' }, { type: 'uint256' }],
|
|
989
|
+
[BigInt(checkpointNumber), archivesMappingBase],
|
|
990
|
+
),
|
|
991
|
+
),
|
|
992
|
+
);
|
|
993
|
+
return [
|
|
994
|
+
{
|
|
995
|
+
address: this.address,
|
|
996
|
+
stateDiff: [
|
|
997
|
+
{
|
|
998
|
+
slot: `0x${archiveSlot.toString(16).padStart(64, '0')}`,
|
|
999
|
+
value: archive.toString(),
|
|
1000
|
+
},
|
|
1001
|
+
],
|
|
1002
|
+
},
|
|
1003
|
+
];
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/** Merges multiple StateOverride arrays, combining stateDiff entries for the same address. */
|
|
1007
|
+
public static mergeStateOverrides(...overrides: StateOverride[]): StateOverride {
|
|
1008
|
+
type StateDiffEntry = { slot: `0x${string}`; value: `0x${string}` };
|
|
1009
|
+
const byAddress = new Map<string, { address: `0x${string}`; balance?: bigint; stateDiff: StateDiffEntry[] }>();
|
|
1010
|
+
for (const override of overrides) {
|
|
1011
|
+
for (const entry of override) {
|
|
1012
|
+
const key = entry.address.toLowerCase();
|
|
1013
|
+
const existing = byAddress.get(key);
|
|
1014
|
+
if (existing) {
|
|
1015
|
+
existing.stateDiff.push(...(entry.stateDiff ?? []));
|
|
1016
|
+
if (entry.balance !== undefined) {
|
|
1017
|
+
existing.balance = entry.balance;
|
|
1018
|
+
}
|
|
1019
|
+
} else {
|
|
1020
|
+
byAddress.set(key, {
|
|
1021
|
+
address: entry.address,
|
|
1022
|
+
balance: entry.balance,
|
|
1023
|
+
stateDiff: [...(entry.stateDiff ?? [])],
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
return [...byAddress.values()];
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/** Compresses a FeeHeader into a uint256 matching FeeHeaderLib.compress() in FeeStructs.sol. */
|
|
1032
|
+
public static compressFeeHeader(feeHeader: FeeHeader): bigint {
|
|
1033
|
+
const MASK_48_BITS = (1n << 48n) - 1n;
|
|
1034
|
+
const MASK_64_BITS = (1n << 64n) - 1n;
|
|
1035
|
+
const MASK_63_BITS = (1n << 63n) - 1n;
|
|
1036
|
+
|
|
1037
|
+
let value = BigInt(feeHeader.manaUsed) & ((1n << 32n) - 1n); // bits [0:31]
|
|
1038
|
+
value |= (feeHeader.excessMana < MASK_48_BITS ? feeHeader.excessMana : MASK_48_BITS) << 32n; // bits [32:79]
|
|
1039
|
+
value |= (BigInt(feeHeader.ethPerFeeAsset) & MASK_48_BITS) << 80n; // bits [80:127]
|
|
1040
|
+
value |= (feeHeader.congestionCost < MASK_64_BITS ? feeHeader.congestionCost : MASK_64_BITS) << 128n; // bits [128:191]
|
|
1041
|
+
value |= (feeHeader.proverCost < MASK_63_BITS ? feeHeader.proverCost : MASK_63_BITS) << 192n; // bits [192:254]
|
|
1042
|
+
value |= 1n << 255n; // preheat flag
|
|
1043
|
+
return value;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/** Computes the fee header for a child checkpoint given parent fee header and child data.
|
|
1047
|
+
* Must stay in sync with Solidity FeeLib.sol (computeNewEthPerFeeAsset, clampedAdd). */
|
|
1048
|
+
public static computeChildFeeHeader(
|
|
1049
|
+
parentFeeHeader: FeeHeader,
|
|
1050
|
+
childManaUsed: bigint,
|
|
1051
|
+
feeAssetPriceModifier: bigint,
|
|
1052
|
+
manaTarget: bigint,
|
|
1053
|
+
): FeeHeader {
|
|
1054
|
+
const MIN_ETH_PER_FEE_ASSET = 100n;
|
|
1055
|
+
const MAX_ETH_PER_FEE_ASSET = 100_000_000_000_000n; // 1e14, matches FeeLib.sol
|
|
1056
|
+
|
|
1057
|
+
// excessMana = clampedAdd(parent.excessMana + parent.manaUsed, -manaTarget)
|
|
1058
|
+
const sum = parentFeeHeader.excessMana + parentFeeHeader.manaUsed;
|
|
1059
|
+
const excessMana = sum > manaTarget ? sum - manaTarget : 0n;
|
|
1060
|
+
|
|
1061
|
+
// ethPerFeeAsset = computeNewEthPerFeeAsset(max(parent.ethPerFeeAsset, MIN), modifier)
|
|
1062
|
+
const parentPrice =
|
|
1063
|
+
parentFeeHeader.ethPerFeeAsset > MIN_ETH_PER_FEE_ASSET ? parentFeeHeader.ethPerFeeAsset : MIN_ETH_PER_FEE_ASSET;
|
|
1064
|
+
let newPrice: bigint;
|
|
1065
|
+
if (feeAssetPriceModifier >= 0n) {
|
|
1066
|
+
newPrice = (parentPrice * (10_000n + feeAssetPriceModifier)) / 10_000n;
|
|
1067
|
+
} else {
|
|
1068
|
+
const absMod = -feeAssetPriceModifier;
|
|
1069
|
+
newPrice = (parentPrice * (10_000n - absMod)) / 10_000n;
|
|
1070
|
+
}
|
|
1071
|
+
if (newPrice < MIN_ETH_PER_FEE_ASSET) {
|
|
1072
|
+
newPrice = MIN_ETH_PER_FEE_ASSET;
|
|
1073
|
+
}
|
|
1074
|
+
if (newPrice > MAX_ETH_PER_FEE_ASSET) {
|
|
1075
|
+
newPrice = MAX_ETH_PER_FEE_ASSET;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
return {
|
|
1079
|
+
excessMana,
|
|
1080
|
+
manaUsed: childManaUsed,
|
|
1081
|
+
ethPerFeeAsset: newPrice,
|
|
1082
|
+
congestionCost: 0n,
|
|
1083
|
+
proverCost: 0n,
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
|
|
814
1087
|
/** Creates a request to Rollup#invalidateBadAttestation to be simulated or sent */
|
|
815
1088
|
public buildInvalidateBadAttestationRequest(
|
|
816
1089
|
checkpointNumber: CheckpointNumber,
|
|
@@ -859,8 +1132,18 @@ export class RollupContract {
|
|
|
859
1132
|
return this.rollup.read.getHasSubmitted([BigInt(epochNumber), BigInt(numberOfCheckpointsInEpoch), prover]);
|
|
860
1133
|
}
|
|
861
1134
|
|
|
862
|
-
getManaMinFeeAt(timestamp: bigint, inFeeAsset: boolean): Promise<bigint> {
|
|
863
|
-
return this.rollup.read.getManaMinFeeAt([timestamp, inFeeAsset]);
|
|
1135
|
+
getManaMinFeeAt(timestamp: bigint, inFeeAsset: boolean, stateOverride?: StateOverride): Promise<bigint> {
|
|
1136
|
+
return this.rollup.read.getManaMinFeeAt([timestamp, inFeeAsset], { stateOverride });
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
async getManaMinFeeComponentsAt(timestamp: bigint, inFeeAsset: boolean): Promise<ManaMinFeeComponents> {
|
|
1140
|
+
const result = await this.rollup.read.getManaMinFeeComponentsAt([timestamp, inFeeAsset]);
|
|
1141
|
+
return {
|
|
1142
|
+
sequencerCost: result.sequencerCost,
|
|
1143
|
+
proverCost: result.proverCost,
|
|
1144
|
+
congestionCost: result.congestionCost,
|
|
1145
|
+
congestionMultiplier: result.congestionMultiplier,
|
|
1146
|
+
};
|
|
864
1147
|
}
|
|
865
1148
|
|
|
866
1149
|
async getSlotAt(timestamp: bigint): Promise<SlotNumber> {
|
|
@@ -906,11 +1189,10 @@ export class RollupContract {
|
|
|
906
1189
|
return this.rollup.read.getSpecificProverRewardsForEpoch([epoch, prover]);
|
|
907
1190
|
}
|
|
908
1191
|
|
|
909
|
-
async getAttesters(): Promise<EthAddress[]> {
|
|
1192
|
+
async getAttesters(timestamp?: bigint): Promise<EthAddress[]> {
|
|
910
1193
|
const attesterSize = await this.getActiveAttesterCount();
|
|
911
1194
|
const gse = new GSEContract(this.client, await this.getGSE());
|
|
912
|
-
const ts = (await this.client.getBlock()).timestamp;
|
|
913
|
-
|
|
1195
|
+
const ts = timestamp ?? (await this.client.getBlock()).timestamp;
|
|
914
1196
|
const indices = Array.from({ length: attesterSize }, (_, i) => BigInt(i));
|
|
915
1197
|
const chunks = chunk(indices, 1000);
|
|
916
1198
|
|
|
@@ -1016,7 +1298,7 @@ export class RollupContract {
|
|
|
1016
1298
|
}
|
|
1017
1299
|
|
|
1018
1300
|
public listenToCheckpointInvalidated(
|
|
1019
|
-
callback: (args: { checkpointNumber: CheckpointNumber }) => unknown,
|
|
1301
|
+
callback: (args: { checkpointNumber: CheckpointNumber; event: Log }) => unknown,
|
|
1020
1302
|
): WatchContractEventReturnType {
|
|
1021
1303
|
return this.rollup.watchEvent.CheckpointInvalidated(
|
|
1022
1304
|
{},
|
|
@@ -1025,7 +1307,7 @@ export class RollupContract {
|
|
|
1025
1307
|
for (const log of logs) {
|
|
1026
1308
|
const args = log.args;
|
|
1027
1309
|
if (args.checkpointNumber !== undefined) {
|
|
1028
|
-
callback({ checkpointNumber: CheckpointNumber.fromBigInt(args.checkpointNumber) });
|
|
1310
|
+
callback({ checkpointNumber: CheckpointNumber.fromBigInt(args.checkpointNumber), event: log });
|
|
1029
1311
|
}
|
|
1030
1312
|
}
|
|
1031
1313
|
},
|
|
@@ -1058,6 +1340,17 @@ export class RollupContract {
|
|
|
1058
1340
|
);
|
|
1059
1341
|
}
|
|
1060
1342
|
|
|
1343
|
+
/**
|
|
1344
|
+
* Fetches OwnershipTransferred events emitted on the L1 block this rollup was deployed on.
|
|
1345
|
+
* The Rollup inherits from Ownable and emits this event in its constructor, so the event
|
|
1346
|
+
* is guaranteed to exist on `l1StartBlock` for any correctly deployed rollup. Used as a
|
|
1347
|
+
* probe to detect RPC nodes that prune historical logs.
|
|
1348
|
+
*/
|
|
1349
|
+
async getOwnershipTransferredEventsAtDeploy() {
|
|
1350
|
+
const l1StartBlock = await this.getL1StartBlock();
|
|
1351
|
+
return await this.rollup.getEvents.OwnershipTransferred({}, { fromBlock: l1StartBlock, toBlock: l1StartBlock });
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1061
1354
|
/** Fetches CheckpointProposed events within the given block range. */
|
|
1062
1355
|
async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
|
|
1063
1356
|
const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
|
|
@@ -1090,4 +1383,48 @@ export class RollupContract {
|
|
|
1090
1383
|
},
|
|
1091
1384
|
}));
|
|
1092
1385
|
}
|
|
1386
|
+
|
|
1387
|
+
/** Packs pending and proven checkpoint numbers into the chain tips storage format. */
|
|
1388
|
+
static packChainTips(pendingCheckpointNumber: bigint, provenCheckpointNumber: bigint): bigint {
|
|
1389
|
+
return (pendingCheckpointNumber << 128n) | (provenCheckpointNumber & ((1n << 128n) - 1n));
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
/** Storage slot for the chain tips (offset 0 within the STF storage struct). */
|
|
1393
|
+
static get chainTipsStorageSlot(): bigint {
|
|
1394
|
+
return BigInt(RollupContract.stfStorageSlot);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
/**
|
|
1398
|
+
* Computes the storage slot for a field within a tempCheckpointLog entry.
|
|
1399
|
+
* @param checkpointNumber - The checkpoint number
|
|
1400
|
+
* @param field - The field within the CompressedTempCheckpointLog struct
|
|
1401
|
+
*/
|
|
1402
|
+
async getTempCheckpointLogStorageSlot(
|
|
1403
|
+
checkpointNumber: CheckpointNumber,
|
|
1404
|
+
field: TempCheckpointLogField,
|
|
1405
|
+
): Promise<bigint> {
|
|
1406
|
+
const [epochDuration, proofSubmissionEpochs] = await Promise.all([
|
|
1407
|
+
this.getEpochDuration(),
|
|
1408
|
+
this.getProofSubmissionEpochs(),
|
|
1409
|
+
]);
|
|
1410
|
+
return this.computeTempCheckpointLogStorageSlot(checkpointNumber, field, { epochDuration, proofSubmissionEpochs });
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
private computeTempCheckpointLogStorageSlot(
|
|
1414
|
+
checkpointNumber: CheckpointNumber,
|
|
1415
|
+
field: TempCheckpointLogField,
|
|
1416
|
+
constants: { epochDuration: number; proofSubmissionEpochs: number },
|
|
1417
|
+
): bigint {
|
|
1418
|
+
const fieldOffset = BigInt(field);
|
|
1419
|
+
const { epochDuration, proofSubmissionEpochs } = constants;
|
|
1420
|
+
const roundaboutSize = BigInt(epochDuration) * (BigInt(proofSubmissionEpochs) + 1n) + 1n;
|
|
1421
|
+
const tempCheckpointLogsBase = BigInt(RollupContract.stfStorageSlot) + 2n;
|
|
1422
|
+
const circularIndex = BigInt(checkpointNumber) % roundaboutSize;
|
|
1423
|
+
const entryBase = BigInt(
|
|
1424
|
+
keccak256(
|
|
1425
|
+
encodeAbiParameters([{ type: 'uint256' }, { type: 'uint256' }], [circularIndex, tempCheckpointLogsBase]),
|
|
1426
|
+
),
|
|
1427
|
+
);
|
|
1428
|
+
return entryBase + fieldOffset;
|
|
1429
|
+
}
|
|
1093
1430
|
}
|