@aztec/ethereum 0.0.1-commit.993d52e → 0.0.1-commit.9a89641
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 +27 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +60 -13
- 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 +135 -35
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +226 -15
- package/dest/contracts/governance_proposer.d.ts +33 -4
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +52 -13
- package/dest/contracts/gse.d.ts +8 -2
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/gse.js +11 -2
- 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 +130 -13
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +203 -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 +5423 -27
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +396 -73
- package/dest/contracts/slashing_proposer.d.ts +170 -0
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/slashing_proposer.js +748 -0
- package/dest/deploy_aztec_l1_contracts.d.ts +18 -10
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +28 -17
- package/dest/foundry_binary.d.ts +13 -0
- package/dest/foundry_binary.d.ts.map +1 -0
- package/dest/foundry_binary.js +52 -0
- package/dest/l1_artifacts.d.ts +14943 -16270
- 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/config.js +3 -3
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +23 -4
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_fee_analyzer.js +65 -3
- 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 +138 -57
- 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 +10 -5
- 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/l1_tx_utils/types.d.ts +27 -1
- package/dest/l1_tx_utils/types.d.ts.map +1 -1
- package/dest/l1_tx_utils/types.js +10 -0
- package/dest/publisher_manager.d.ts +34 -8
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +119 -8
- package/dest/queries.d.ts +13 -2
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +69 -4
- package/dest/test/blob_kzg_warmup.d.ts +19 -0
- package/dest/test/blob_kzg_warmup.d.ts.map +1 -0
- package/dest/test/blob_kzg_warmup.js +64 -0
- package/dest/test/chain_monitor.d.ts +55 -4
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +104 -3
- package/dest/test/eth_cheat_codes.d.ts +37 -6
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +89 -41
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -0
- package/dest/test/rollup_cheat_codes.d.ts +60 -3
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +86 -7
- package/dest/test/start_anvil.d.ts +23 -3
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +182 -32
- package/dest/utils.d.ts +9 -2
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +48 -16
- package/package.json +6 -9
- package/src/client.ts +66 -2
- package/src/config.ts +83 -17
- 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 +310 -10
- package/src/contracts/governance_proposer.ts +56 -13
- package/src/contracts/gse.ts +19 -2
- package/src/contracts/inbox.ts +13 -5
- package/src/contracts/index.ts +2 -2
- package/src/contracts/multicall.ts +247 -106
- package/src/contracts/outbox.ts +42 -8
- package/src/contracts/rollup.ts +447 -80
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +91 -30
- package/src/deploy_aztec_l1_contracts.ts +32 -18
- package/src/foundry_binary.ts +57 -0
- 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/config.ts +3 -3
- package/src/l1_tx_utils/l1_fee_analyzer.ts +75 -3
- package/src/l1_tx_utils/l1_tx_utils.ts +122 -48
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +10 -5
- package/src/l1_tx_utils/tx_delayer.ts +16 -7
- package/src/l1_tx_utils/types.ts +32 -0
- package/src/publisher_manager.ts +143 -12
- package/src/queries.ts +76 -4
- package/src/test/blob_kzg_warmup.ts +65 -0
- package/src/test/chain_monitor.ts +148 -3
- package/src/test/eth_cheat_codes.ts +82 -45
- package/src/test/index.ts +1 -0
- package/src/test/rollup_cheat_codes.ts +115 -6
- package/src/test/start_anvil.ts +212 -32
- package/src/utils.ts +45 -18
- 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 +0 -140
- package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/tally_slashing_proposer.js +0 -320
- package/dest/generated/l1-contracts-defaults.d.ts +0 -30
- package/dest/generated/l1-contracts-defaults.d.ts.map +0 -1
- package/dest/generated/l1-contracts-defaults.js +0 -30
- package/src/contracts/empire_slashing_proposer.ts +0 -265
- package/src/generated/l1-contracts-defaults.ts +0 -32
package/dest/contracts/rollup.js
CHANGED
|
@@ -376,25 +376,20 @@ import { Buffer32 } from '@aztec/foundation/buffer';
|
|
|
376
376
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
377
377
|
import { memoize } from '@aztec/foundation/decorators';
|
|
378
378
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
379
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
379
380
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
381
|
+
import { getErrorCause } from '@aztec/foundation/types';
|
|
380
382
|
import { EscapeHatchAbi } from '@aztec/l1-artifacts/EscapeHatchAbi';
|
|
381
383
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
382
384
|
import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
|
|
383
385
|
import chunk from 'lodash.chunk';
|
|
384
|
-
import { encodeFunctionData, getContract, hexToBigInt, keccak256 } from 'viem';
|
|
386
|
+
import { ContractFunctionRevertedError, RpcRequestError, decodeErrorResult, encodeAbiParameters, encodeFunctionData, getContract, hexToBigInt, keccak256 } from 'viem';
|
|
385
387
|
import { getPublicClient } from '../client.js';
|
|
386
388
|
import { formatViemError } from '../utils.js';
|
|
387
|
-
import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
|
|
388
389
|
import { GSEContract } from './gse.js';
|
|
389
390
|
import { SlasherContract } from './slasher_contract.js';
|
|
390
|
-
import {
|
|
391
|
+
import { SlashingProposerContract } from './slashing_proposer.js';
|
|
391
392
|
import { checkBlockTag } from './utils.js';
|
|
392
|
-
export var SlashingProposerType = /*#__PURE__*/ function(SlashingProposerType) {
|
|
393
|
-
SlashingProposerType[SlashingProposerType["None"] = 0] = "None";
|
|
394
|
-
SlashingProposerType[SlashingProposerType["Tally"] = 1] = "Tally";
|
|
395
|
-
SlashingProposerType[SlashingProposerType["Empire"] = 2] = "Empire";
|
|
396
|
-
return SlashingProposerType;
|
|
397
|
-
}({});
|
|
398
393
|
/**
|
|
399
394
|
* Status of a validator/attester in the staking system.
|
|
400
395
|
* Matches the Status enum in StakingLib.sol
|
|
@@ -405,6 +400,37 @@ export var SlashingProposerType = /*#__PURE__*/ function(SlashingProposerType) {
|
|
|
405
400
|
AttesterStatus[AttesterStatus["EXITING"] = 3] = "EXITING";
|
|
406
401
|
return AttesterStatus;
|
|
407
402
|
}({});
|
|
403
|
+
/** Field offsets within the CompressedTempCheckpointLog struct in Solidity storage. */ export var TempCheckpointLogField = /*#__PURE__*/ function(TempCheckpointLogField) {
|
|
404
|
+
TempCheckpointLogField[TempCheckpointLogField["HeaderHash"] = 0] = "HeaderHash";
|
|
405
|
+
TempCheckpointLogField[TempCheckpointLogField["BlobCommitmentsHash"] = 1] = "BlobCommitmentsHash";
|
|
406
|
+
TempCheckpointLogField[TempCheckpointLogField["OutHash"] = 2] = "OutHash";
|
|
407
|
+
TempCheckpointLogField[TempCheckpointLogField["AttestationsHash"] = 3] = "AttestationsHash";
|
|
408
|
+
TempCheckpointLogField[TempCheckpointLogField["PayloadDigest"] = 4] = "PayloadDigest";
|
|
409
|
+
TempCheckpointLogField[TempCheckpointLogField["SlotNumber"] = 5] = "SlotNumber";
|
|
410
|
+
TempCheckpointLogField[TempCheckpointLogField["FeeHeader"] = 6] = "FeeHeader";
|
|
411
|
+
return TempCheckpointLogField;
|
|
412
|
+
}({});
|
|
413
|
+
const INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR = 'ValidatorSelection__InsufficientValidatorSetSize';
|
|
414
|
+
function isValidatorSelectionError(err, errorName) {
|
|
415
|
+
return getErrorCause(err, ContractFunctionRevertedError)?.data?.errorName === errorName || decodeRpcRequestErrorName(err) === errorName;
|
|
416
|
+
}
|
|
417
|
+
function decodeRpcRequestErrorName(err) {
|
|
418
|
+
const data = getErrorCause(err, RpcRequestError)?.data;
|
|
419
|
+
if (!isHexString(data)) {
|
|
420
|
+
return undefined;
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
return decodeErrorResult({
|
|
424
|
+
abi: RollupAbi,
|
|
425
|
+
data
|
|
426
|
+
}).errorName;
|
|
427
|
+
} catch {
|
|
428
|
+
return undefined;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
function isHexString(value) {
|
|
432
|
+
return typeof value === 'string' && value.startsWith('0x');
|
|
433
|
+
}
|
|
408
434
|
export class RollupContract {
|
|
409
435
|
client;
|
|
410
436
|
static{
|
|
@@ -499,6 +525,16 @@ export class RollupContract {
|
|
|
499
525
|
2,
|
|
500
526
|
"getGenesisArchiveTreeRoot"
|
|
501
527
|
],
|
|
528
|
+
[
|
|
529
|
+
memoize,
|
|
530
|
+
2,
|
|
531
|
+
"getVkTreeRoot"
|
|
532
|
+
],
|
|
533
|
+
[
|
|
534
|
+
memoize,
|
|
535
|
+
2,
|
|
536
|
+
"getProtocolContractsHash"
|
|
537
|
+
],
|
|
502
538
|
[
|
|
503
539
|
memoize,
|
|
504
540
|
2,
|
|
@@ -507,6 +543,7 @@ export class RollupContract {
|
|
|
507
543
|
], []));
|
|
508
544
|
}
|
|
509
545
|
rollup;
|
|
546
|
+
logger;
|
|
510
547
|
static cachedStfStorageSlot;
|
|
511
548
|
cachedEscapeHatch;
|
|
512
549
|
static get checkBlobStorageSlot() {
|
|
@@ -525,12 +562,12 @@ export class RollupContract {
|
|
|
525
562
|
}
|
|
526
563
|
static getFromConfig(config) {
|
|
527
564
|
const client = getPublicClient(config);
|
|
528
|
-
const address = config.
|
|
565
|
+
const address = config.rollupAddress.toString();
|
|
529
566
|
return new RollupContract(client, address);
|
|
530
567
|
}
|
|
531
568
|
constructor(client, address){
|
|
532
569
|
this.client = client;
|
|
533
|
-
_initProto(this);
|
|
570
|
+
this.logger = (_initProto(this), createLogger('ethereum:rollup'));
|
|
534
571
|
if (address instanceof EthAddress) {
|
|
535
572
|
address = address.toString();
|
|
536
573
|
}
|
|
@@ -555,34 +592,10 @@ export class RollupContract {
|
|
|
555
592
|
return undefined;
|
|
556
593
|
}
|
|
557
594
|
const proposerAddress = await slasher.getProposer();
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
type: 'function',
|
|
561
|
-
name: 'SLASHING_PROPOSER_TYPE',
|
|
562
|
-
inputs: [],
|
|
563
|
-
outputs: [
|
|
564
|
-
{
|
|
565
|
-
name: '',
|
|
566
|
-
type: 'uint8',
|
|
567
|
-
internalType: 'enum SlasherFlavor'
|
|
568
|
-
}
|
|
569
|
-
],
|
|
570
|
-
stateMutability: 'view'
|
|
571
|
-
}
|
|
572
|
-
];
|
|
573
|
-
const proposer = getContract({
|
|
574
|
-
address: proposerAddress.toString(),
|
|
575
|
-
abi: proposerAbi,
|
|
576
|
-
client: this.client
|
|
577
|
-
});
|
|
578
|
-
const proposerType = await proposer.read.SLASHING_PROPOSER_TYPE();
|
|
579
|
-
if (proposerType === 1..valueOf()) {
|
|
580
|
-
return new TallySlashingProposerContract(this.client, proposerAddress);
|
|
581
|
-
} else if (proposerType === 2..valueOf()) {
|
|
582
|
-
return new EmpireSlashingProposerContract(this.client, proposerAddress);
|
|
583
|
-
} else {
|
|
584
|
-
throw new Error(`Unknown slashing proposer type: ${proposerType}`);
|
|
595
|
+
if (proposerAddress.isZero()) {
|
|
596
|
+
return undefined;
|
|
585
597
|
}
|
|
598
|
+
return new SlashingProposerContract(this.client, proposerAddress);
|
|
586
599
|
}
|
|
587
600
|
getL1StartBlock() {
|
|
588
601
|
return this.rollup.read.L1_BLOCK_AT_GENESIS();
|
|
@@ -640,18 +653,35 @@ export class RollupContract {
|
|
|
640
653
|
0n
|
|
641
654
|
]));
|
|
642
655
|
}
|
|
656
|
+
async getVkTreeRoot() {
|
|
657
|
+
const slot = BigInt(RollupContract.stfStorageSlot) + 3n;
|
|
658
|
+
const value = await this.client.getStorageAt({
|
|
659
|
+
address: this.address,
|
|
660
|
+
slot: `0x${slot.toString(16)}`
|
|
661
|
+
});
|
|
662
|
+
return Fr.fromString(value ?? '0x0');
|
|
663
|
+
}
|
|
664
|
+
async getProtocolContractsHash() {
|
|
665
|
+
const slot = BigInt(RollupContract.stfStorageSlot) + 4n;
|
|
666
|
+
const value = await this.client.getStorageAt({
|
|
667
|
+
address: this.address,
|
|
668
|
+
slot: `0x${slot.toString(16)}`
|
|
669
|
+
});
|
|
670
|
+
return Fr.fromString(value ?? '0x0');
|
|
671
|
+
}
|
|
643
672
|
/**
|
|
644
673
|
* Returns rollup constants used for epoch queries.
|
|
645
674
|
* Return type is `L1RollupConstants` which is defined in stdlib,
|
|
646
675
|
* so we cant reference it until we move this contract to that package.
|
|
647
676
|
*/ async getRollupConstants() {
|
|
648
|
-
const [l1StartBlock, l1GenesisTime, slotDuration, epochDuration, proofSubmissionEpochs, targetCommitteeSize] = await Promise.all([
|
|
677
|
+
const [l1StartBlock, l1GenesisTime, slotDuration, epochDuration, proofSubmissionEpochs, targetCommitteeSize, rollupManaLimit] = await Promise.all([
|
|
649
678
|
this.getL1StartBlock(),
|
|
650
679
|
this.getL1GenesisTime(),
|
|
651
680
|
this.getSlotDuration(),
|
|
652
681
|
this.getEpochDuration(),
|
|
653
682
|
this.getProofSubmissionEpochs(),
|
|
654
|
-
this.getTargetCommitteeSize()
|
|
683
|
+
this.getTargetCommitteeSize(),
|
|
684
|
+
this.getManaLimit()
|
|
655
685
|
]);
|
|
656
686
|
return {
|
|
657
687
|
l1StartBlock,
|
|
@@ -659,7 +689,8 @@ export class RollupContract {
|
|
|
659
689
|
slotDuration,
|
|
660
690
|
epochDuration: Number(epochDuration),
|
|
661
691
|
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
662
|
-
targetCommitteeSize
|
|
692
|
+
targetCommitteeSize,
|
|
693
|
+
rollupManaLimit: Number(rollupManaLimit)
|
|
663
694
|
};
|
|
664
695
|
}
|
|
665
696
|
async getSlasherAddress() {
|
|
@@ -705,7 +736,11 @@ export class RollupContract {
|
|
|
705
736
|
BigInt(epoch)
|
|
706
737
|
]);
|
|
707
738
|
return isOpen;
|
|
708
|
-
} catch
|
|
739
|
+
} catch (err) {
|
|
740
|
+
this.logger.warn('isEscapeHatchOpen failed (treating as closed); RPC or contract error may cause liveness risk', {
|
|
741
|
+
epoch: Number(epoch),
|
|
742
|
+
error: err
|
|
743
|
+
});
|
|
709
744
|
return false;
|
|
710
745
|
}
|
|
711
746
|
}
|
|
@@ -721,8 +756,17 @@ export class RollupContract {
|
|
|
721
756
|
async getOwner() {
|
|
722
757
|
return EthAddress.fromString(await this.rollup.read.owner());
|
|
723
758
|
}
|
|
724
|
-
async getActiveAttesterCount() {
|
|
725
|
-
|
|
759
|
+
async getActiveAttesterCount(options) {
|
|
760
|
+
await checkBlockTag(options?.blockNumber, this.client);
|
|
761
|
+
return Number(await this.rollup.read.getActiveAttesterCount(options));
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Number of attesters that were staked at the given (historical) L1 timestamp. This is the count that
|
|
765
|
+
* validator-set sampling uses to decide whether an epoch gets a committee, and the historical counterpart
|
|
766
|
+
* of {@link getActiveAttesterCount} (which reads at the latest L1 block).
|
|
767
|
+
*/ async getAttesterCountAtTime(timestamp, options) {
|
|
768
|
+
const gse = new GSEContract(this.client, await this.getGSE());
|
|
769
|
+
return gse.getAttesterCountAtTime(this.address, timestamp, options);
|
|
726
770
|
}
|
|
727
771
|
async getSlashingProposerAddress() {
|
|
728
772
|
const slasher = await this.getSlasherContract();
|
|
@@ -734,24 +778,40 @@ export class RollupContract {
|
|
|
734
778
|
getCheckpointReward() {
|
|
735
779
|
return this.rollup.read.getCheckpointReward();
|
|
736
780
|
}
|
|
737
|
-
async getCheckpointNumber() {
|
|
738
|
-
|
|
781
|
+
async getCheckpointNumber(options) {
|
|
782
|
+
await checkBlockTag(options?.blockNumber, this.client);
|
|
783
|
+
return CheckpointNumber.fromBigInt(await this.rollup.read.getPendingCheckpointNumber(options));
|
|
739
784
|
}
|
|
740
|
-
async getProvenCheckpointNumber() {
|
|
741
|
-
|
|
785
|
+
async getProvenCheckpointNumber(options) {
|
|
786
|
+
await checkBlockTag(options?.blockNumber, this.client);
|
|
787
|
+
return CheckpointNumber.fromBigInt(await this.rollup.read.getProvenCheckpointNumber(options));
|
|
742
788
|
}
|
|
743
|
-
async getSlotNumber() {
|
|
744
|
-
|
|
789
|
+
async getSlotNumber(options) {
|
|
790
|
+
await checkBlockTag(options?.blockNumber, this.client);
|
|
791
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot(options));
|
|
745
792
|
}
|
|
746
|
-
async getL1FeesAt(timestamp) {
|
|
793
|
+
async getL1FeesAt(timestamp, options) {
|
|
794
|
+
await checkBlockTag(options?.blockNumber, this.client);
|
|
747
795
|
const result = await this.rollup.read.getL1FeesAt([
|
|
748
796
|
timestamp
|
|
749
|
-
]);
|
|
797
|
+
], options);
|
|
750
798
|
return {
|
|
751
799
|
baseFee: result.baseFee,
|
|
752
800
|
blobFee: result.blobFee
|
|
753
801
|
};
|
|
754
802
|
}
|
|
803
|
+
async getFeeHeader(checkpointNumber) {
|
|
804
|
+
const result = await this.rollup.read.getFeeHeader([
|
|
805
|
+
checkpointNumber
|
|
806
|
+
]);
|
|
807
|
+
return {
|
|
808
|
+
excessMana: result.excessMana,
|
|
809
|
+
manaUsed: result.manaUsed,
|
|
810
|
+
ethPerFeeAsset: result.ethPerFeeAsset,
|
|
811
|
+
congestionCost: result.congestionCost,
|
|
812
|
+
proverCost: result.proverCost
|
|
813
|
+
};
|
|
814
|
+
}
|
|
755
815
|
getEthPerFeeAsset() {
|
|
756
816
|
return this.rollup.read.getEthPerFeeAsset();
|
|
757
817
|
}
|
|
@@ -764,7 +824,7 @@ export class RollupContract {
|
|
|
764
824
|
timestamp
|
|
765
825
|
]
|
|
766
826
|
}).catch((e)=>{
|
|
767
|
-
if (e
|
|
827
|
+
if (isValidatorSelectionError(e, INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR)) {
|
|
768
828
|
return {
|
|
769
829
|
result: undefined
|
|
770
830
|
};
|
|
@@ -791,7 +851,7 @@ export class RollupContract {
|
|
|
791
851
|
functionName: 'getCurrentEpochCommittee',
|
|
792
852
|
args: []
|
|
793
853
|
}).catch((e)=>{
|
|
794
|
-
if (e
|
|
854
|
+
if (isValidatorSelectionError(e, INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR)) {
|
|
795
855
|
return {
|
|
796
856
|
result: undefined
|
|
797
857
|
};
|
|
@@ -820,10 +880,11 @@ export class RollupContract {
|
|
|
820
880
|
});
|
|
821
881
|
return EthAddress.fromString(result);
|
|
822
882
|
}
|
|
823
|
-
async getCheckpoint(checkpointNumber) {
|
|
883
|
+
async getCheckpoint(checkpointNumber, options) {
|
|
884
|
+
await checkBlockTag(options?.blockNumber, this.client);
|
|
824
885
|
const result = await this.rollup.read.getCheckpoint([
|
|
825
886
|
BigInt(checkpointNumber)
|
|
826
|
-
]);
|
|
887
|
+
], options);
|
|
827
888
|
return {
|
|
828
889
|
archive: Fr.fromString(result.archive),
|
|
829
890
|
headerHash: Buffer32.fromString(result.headerHash),
|
|
@@ -853,6 +914,28 @@ export class RollupContract {
|
|
|
853
914
|
0.5
|
|
854
915
|
]));
|
|
855
916
|
}
|
|
917
|
+
/**
|
|
918
|
+
* Returns the effective pending checkpoint, accounting for potential prunes.
|
|
919
|
+
* When a prune can happen, the L1 contract uses the proven checkpoint instead of the pending one.
|
|
920
|
+
* This mirrors the behavior of getEffectivePendingCheckpointNumber in STFLib.sol.
|
|
921
|
+
* @param atTimestamp - The timestamp to evaluate pruneability at. Defaults to the current L1 block timestamp.
|
|
922
|
+
* @param options - Optional L1 block number to pin the queries to.
|
|
923
|
+
*/ getEffectivePendingCheckpoint(atTimestamp, options) {
|
|
924
|
+
return retry(async ()=>{
|
|
925
|
+
const timestamp = atTimestamp ?? (await this.client.getBlock()).timestamp;
|
|
926
|
+
const canPrune = await this.canPruneAtTime(timestamp, options);
|
|
927
|
+
if (canPrune) {
|
|
928
|
+
const provenCheckpointNumber = await this.getProvenCheckpointNumber(options);
|
|
929
|
+
return await this.getCheckpoint(provenCheckpointNumber, options);
|
|
930
|
+
}
|
|
931
|
+
const pendingCheckpointNumber = await this.getCheckpointNumber(options);
|
|
932
|
+
return await this.getCheckpoint(pendingCheckpointNumber, options);
|
|
933
|
+
}, 'getting effective pending checkpoint', makeBackoff([
|
|
934
|
+
0.5,
|
|
935
|
+
0.5,
|
|
936
|
+
0.5
|
|
937
|
+
]));
|
|
938
|
+
}
|
|
856
939
|
async getTips() {
|
|
857
940
|
const { pending, proven } = await this.rollup.read.getTips();
|
|
858
941
|
return {
|
|
@@ -937,9 +1020,8 @@ export class RollupContract {
|
|
|
937
1020
|
* @return [slot, checkpointNumber, timeOfNextL1Slot] - If you can propose, the L2 slot number, checkpoint number and
|
|
938
1021
|
* timestamp of the next L1 block
|
|
939
1022
|
* @throws otherwise
|
|
940
|
-
*/ async
|
|
941
|
-
const
|
|
942
|
-
const timeOfNextL1Slot = latestBlock.timestamp + BigInt(slotDuration);
|
|
1023
|
+
*/ async canProposeAt(archive, account, timestamp, stateOverride = []) {
|
|
1024
|
+
const timeOfNextL1Slot = timestamp;
|
|
943
1025
|
const who = typeof account === 'string' ? account : account.address;
|
|
944
1026
|
try {
|
|
945
1027
|
const { result: [slot, checkpointNumber] } = await this.client.simulateContract({
|
|
@@ -952,7 +1034,7 @@ export class RollupContract {
|
|
|
952
1034
|
who
|
|
953
1035
|
],
|
|
954
1036
|
account,
|
|
955
|
-
stateOverride
|
|
1037
|
+
stateOverride
|
|
956
1038
|
});
|
|
957
1039
|
return {
|
|
958
1040
|
slot: SlotNumber.fromBigInt(slot),
|
|
@@ -964,11 +1046,15 @@ export class RollupContract {
|
|
|
964
1046
|
}
|
|
965
1047
|
}
|
|
966
1048
|
/**
|
|
967
|
-
* Returns a state override that sets the pending
|
|
968
|
-
*
|
|
969
|
-
*
|
|
970
|
-
|
|
971
|
-
|
|
1049
|
+
* Returns a state override that sets the pending and/or proven checkpoint numbers. Useful for simulations.
|
|
1050
|
+
* Both values share a single storage slot (pending in the upper 128 bits, proven in the lower 128 bits), so
|
|
1051
|
+
* a single combined override is emitted to avoid the second state-diff clobbering the first. The current live
|
|
1052
|
+
* value is read once to preserve any half not being overridden. Returns an empty override if neither is set.
|
|
1053
|
+
*
|
|
1054
|
+
* Throws if the resulting `proven > pending`, which would crash the simulation: `STFLib.canPruneAtTime` calls
|
|
1055
|
+
* `getEpochForCheckpoint(proven + 1)` whenever `pending != proven`, and that asserts `_n <= tips.pending`.
|
|
1056
|
+
*/ async makeChainTipsOverride(override) {
|
|
1057
|
+
if (override.pending === undefined && override.proven === undefined) {
|
|
972
1058
|
return [];
|
|
973
1059
|
}
|
|
974
1060
|
const slot = RollupContract.stfStorageSlot;
|
|
@@ -976,8 +1062,15 @@ export class RollupContract {
|
|
|
976
1062
|
address: this.address,
|
|
977
1063
|
slot
|
|
978
1064
|
});
|
|
979
|
-
const
|
|
980
|
-
const
|
|
1065
|
+
const currentRaw = currentValue ? hexToBigInt(currentValue) : 0n;
|
|
1066
|
+
const currentPending = currentRaw >> 128n;
|
|
1067
|
+
const currentProven = currentRaw & (1n << 128n) - 1n;
|
|
1068
|
+
const newPending = override.pending !== undefined ? BigInt(override.pending) : currentPending;
|
|
1069
|
+
const newProven = override.proven !== undefined ? BigInt(override.proven) : currentProven;
|
|
1070
|
+
if (newProven > newPending) {
|
|
1071
|
+
throw new Error(`Invalid chain tips override: proven (${newProven}) > pending (${newPending})`);
|
|
1072
|
+
}
|
|
1073
|
+
const newValue = newPending << 128n | newProven;
|
|
981
1074
|
return [
|
|
982
1075
|
{
|
|
983
1076
|
address: this.address,
|
|
@@ -990,6 +1083,161 @@ export class RollupContract {
|
|
|
990
1083
|
}
|
|
991
1084
|
];
|
|
992
1085
|
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Returns a state override that patches `tempCheckpointLogs[checkpointNumber]` with every field that
|
|
1088
|
+
* the L1 contract reads during `propose()` for the checkpoint that builds on top of it (proposer
|
|
1089
|
+
* pipelining simulation). Mirrors the writes done by `ProposeLib.addTempCheckpointLog`.
|
|
1090
|
+
*
|
|
1091
|
+
* `blobCommitmentsHash` and `attestationsHash` are intentionally not exposed here — the propose path
|
|
1092
|
+
* never asserts against them, so leaving them at storage zero is harmless.
|
|
1093
|
+
*/ async makeTempCheckpointLogOverride(checkpointNumber, fields) {
|
|
1094
|
+
const constants = await this.getRollupConstants();
|
|
1095
|
+
const slotAt = (field)=>`0x${this.computeTempCheckpointLogStorageSlot(checkpointNumber, field, constants).toString(16).padStart(64, '0')}`;
|
|
1096
|
+
const word = (v)=>`0x${v.toString(16).padStart(64, '0')}`;
|
|
1097
|
+
const stateDiff = [];
|
|
1098
|
+
if (fields.headerHash) {
|
|
1099
|
+
stateDiff.push({
|
|
1100
|
+
slot: slotAt(0),
|
|
1101
|
+
value: fields.headerHash.toString()
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
if (fields.outHash) {
|
|
1105
|
+
stateDiff.push({
|
|
1106
|
+
slot: slotAt(2),
|
|
1107
|
+
value: fields.outHash.toString()
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
if (fields.payloadDigest) {
|
|
1111
|
+
stateDiff.push({
|
|
1112
|
+
slot: slotAt(4),
|
|
1113
|
+
value: fields.payloadDigest.toString()
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
if (fields.slotNumber !== undefined) {
|
|
1117
|
+
// CompressedSlot is uint32 on L1 (SafeCast.toUint32 reverts on overflow). Match that behavior here
|
|
1118
|
+
// so a malformed override surfaces immediately rather than silently truncating into a wrong slot.
|
|
1119
|
+
const slotNumber = BigInt(fields.slotNumber);
|
|
1120
|
+
if (slotNumber < 0n || slotNumber > 0xffffffffn) {
|
|
1121
|
+
throw new Error(`slotNumber ${slotNumber} does not fit in uint32`);
|
|
1122
|
+
}
|
|
1123
|
+
stateDiff.push({
|
|
1124
|
+
slot: slotAt(5),
|
|
1125
|
+
value: word(slotNumber)
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
if (fields.feeHeader) {
|
|
1129
|
+
stateDiff.push({
|
|
1130
|
+
slot: slotAt(6),
|
|
1131
|
+
value: word(RollupContract.compressFeeHeader(fields.feeHeader))
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
if (stateDiff.length === 0) {
|
|
1135
|
+
return [];
|
|
1136
|
+
}
|
|
1137
|
+
return [
|
|
1138
|
+
{
|
|
1139
|
+
address: this.address,
|
|
1140
|
+
stateDiff
|
|
1141
|
+
}
|
|
1142
|
+
];
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Returns a state override that sets archives[checkpointNumber] to the given archive value.
|
|
1146
|
+
* Used when simulating a canProposeAtTime call where the local archive differs from L1
|
|
1147
|
+
* (e.g. pipelining where the parent checkpoint hasn't landed on L1 yet).
|
|
1148
|
+
*/ makeArchiveOverride(checkpointNumber, archive) {
|
|
1149
|
+
const archivesMappingBase = hexToBigInt(RollupContract.stfStorageSlot) + 1n;
|
|
1150
|
+
const archiveSlot = hexToBigInt(keccak256(encodeAbiParameters([
|
|
1151
|
+
{
|
|
1152
|
+
type: 'uint256'
|
|
1153
|
+
},
|
|
1154
|
+
{
|
|
1155
|
+
type: 'uint256'
|
|
1156
|
+
}
|
|
1157
|
+
], [
|
|
1158
|
+
BigInt(checkpointNumber),
|
|
1159
|
+
archivesMappingBase
|
|
1160
|
+
])));
|
|
1161
|
+
return [
|
|
1162
|
+
{
|
|
1163
|
+
address: this.address,
|
|
1164
|
+
stateDiff: [
|
|
1165
|
+
{
|
|
1166
|
+
slot: `0x${archiveSlot.toString(16).padStart(64, '0')}`,
|
|
1167
|
+
value: archive.toString()
|
|
1168
|
+
}
|
|
1169
|
+
]
|
|
1170
|
+
}
|
|
1171
|
+
];
|
|
1172
|
+
}
|
|
1173
|
+
/** Merges multiple StateOverride arrays, combining stateDiff entries for the same address. */ static mergeStateOverrides(...overrides) {
|
|
1174
|
+
const byAddress = new Map();
|
|
1175
|
+
for (const override of overrides){
|
|
1176
|
+
for (const entry of override){
|
|
1177
|
+
const key = entry.address.toLowerCase();
|
|
1178
|
+
const existing = byAddress.get(key);
|
|
1179
|
+
if (existing) {
|
|
1180
|
+
existing.stateDiff.push(...entry.stateDiff ?? []);
|
|
1181
|
+
if (entry.balance !== undefined) {
|
|
1182
|
+
existing.balance = entry.balance;
|
|
1183
|
+
}
|
|
1184
|
+
} else {
|
|
1185
|
+
byAddress.set(key, {
|
|
1186
|
+
address: entry.address,
|
|
1187
|
+
balance: entry.balance,
|
|
1188
|
+
stateDiff: [
|
|
1189
|
+
...entry.stateDiff ?? []
|
|
1190
|
+
]
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return [
|
|
1196
|
+
...byAddress.values()
|
|
1197
|
+
];
|
|
1198
|
+
}
|
|
1199
|
+
/** Compresses a FeeHeader into a uint256 matching FeeHeaderLib.compress() in FeeStructs.sol. */ static compressFeeHeader(feeHeader) {
|
|
1200
|
+
const MASK_48_BITS = (1n << 48n) - 1n;
|
|
1201
|
+
const MASK_64_BITS = (1n << 64n) - 1n;
|
|
1202
|
+
const MASK_63_BITS = (1n << 63n) - 1n;
|
|
1203
|
+
let value = BigInt(feeHeader.manaUsed) & (1n << 32n) - 1n; // bits [0:31]
|
|
1204
|
+
value |= (feeHeader.excessMana < MASK_48_BITS ? feeHeader.excessMana : MASK_48_BITS) << 32n; // bits [32:79]
|
|
1205
|
+
value |= (BigInt(feeHeader.ethPerFeeAsset) & MASK_48_BITS) << 80n; // bits [80:127]
|
|
1206
|
+
value |= (feeHeader.congestionCost < MASK_64_BITS ? feeHeader.congestionCost : MASK_64_BITS) << 128n; // bits [128:191]
|
|
1207
|
+
value |= (feeHeader.proverCost < MASK_63_BITS ? feeHeader.proverCost : MASK_63_BITS) << 192n; // bits [192:254]
|
|
1208
|
+
value |= 1n << 255n; // preheat flag
|
|
1209
|
+
return value;
|
|
1210
|
+
}
|
|
1211
|
+
/** Computes the fee header for a child checkpoint given parent fee header and child data.
|
|
1212
|
+
* Must stay in sync with Solidity FeeLib.sol (computeNewEthPerFeeAsset, clampedAdd). */ static computeChildFeeHeader(parentFeeHeader, childManaUsed, feeAssetPriceModifier, manaTarget) {
|
|
1213
|
+
const MIN_ETH_PER_FEE_ASSET = 100n;
|
|
1214
|
+
const MAX_ETH_PER_FEE_ASSET = 100_000_000_000_000n; // 1e14, matches FeeLib.sol
|
|
1215
|
+
// excessMana = clampedAdd(parent.excessMana + parent.manaUsed, -manaTarget)
|
|
1216
|
+
const sum = parentFeeHeader.excessMana + parentFeeHeader.manaUsed;
|
|
1217
|
+
const excessMana = sum > manaTarget ? sum - manaTarget : 0n;
|
|
1218
|
+
// ethPerFeeAsset = computeNewEthPerFeeAsset(max(parent.ethPerFeeAsset, MIN), modifier)
|
|
1219
|
+
const parentPrice = parentFeeHeader.ethPerFeeAsset > MIN_ETH_PER_FEE_ASSET ? parentFeeHeader.ethPerFeeAsset : MIN_ETH_PER_FEE_ASSET;
|
|
1220
|
+
let newPrice;
|
|
1221
|
+
if (feeAssetPriceModifier >= 0n) {
|
|
1222
|
+
newPrice = parentPrice * (10_000n + feeAssetPriceModifier) / 10_000n;
|
|
1223
|
+
} else {
|
|
1224
|
+
const absMod = -feeAssetPriceModifier;
|
|
1225
|
+
newPrice = parentPrice * (10_000n - absMod) / 10_000n;
|
|
1226
|
+
}
|
|
1227
|
+
if (newPrice < MIN_ETH_PER_FEE_ASSET) {
|
|
1228
|
+
newPrice = MIN_ETH_PER_FEE_ASSET;
|
|
1229
|
+
}
|
|
1230
|
+
if (newPrice > MAX_ETH_PER_FEE_ASSET) {
|
|
1231
|
+
newPrice = MAX_ETH_PER_FEE_ASSET;
|
|
1232
|
+
}
|
|
1233
|
+
return {
|
|
1234
|
+
excessMana,
|
|
1235
|
+
manaUsed: childManaUsed,
|
|
1236
|
+
ethPerFeeAsset: newPrice,
|
|
1237
|
+
congestionCost: 0n,
|
|
1238
|
+
proverCost: 0n
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
993
1241
|
/** Creates a request to Rollup#invalidateBadAttestation to be simulated or sent */ buildInvalidateBadAttestationRequest(checkpointNumber, attestationsAndSigners, committee, invalidIndex) {
|
|
994
1242
|
return {
|
|
995
1243
|
to: this.address,
|
|
@@ -1031,11 +1279,25 @@ export class RollupContract {
|
|
|
1031
1279
|
prover
|
|
1032
1280
|
]);
|
|
1033
1281
|
}
|
|
1034
|
-
getManaMinFeeAt(timestamp, inFeeAsset) {
|
|
1282
|
+
getManaMinFeeAt(timestamp, inFeeAsset, stateOverride) {
|
|
1035
1283
|
return this.rollup.read.getManaMinFeeAt([
|
|
1036
1284
|
timestamp,
|
|
1037
1285
|
inFeeAsset
|
|
1286
|
+
], {
|
|
1287
|
+
stateOverride
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
async getManaMinFeeComponentsAt(timestamp, inFeeAsset) {
|
|
1291
|
+
const result = await this.rollup.read.getManaMinFeeComponentsAt([
|
|
1292
|
+
timestamp,
|
|
1293
|
+
inFeeAsset
|
|
1038
1294
|
]);
|
|
1295
|
+
return {
|
|
1296
|
+
sequencerCost: result.sequencerCost,
|
|
1297
|
+
proverCost: result.proverCost,
|
|
1298
|
+
congestionCost: result.congestionCost,
|
|
1299
|
+
congestionMultiplier: result.congestionMultiplier
|
|
1300
|
+
};
|
|
1039
1301
|
}
|
|
1040
1302
|
async getSlotAt(timestamp) {
|
|
1041
1303
|
return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([
|
|
@@ -1086,15 +1348,24 @@ export class RollupContract {
|
|
|
1086
1348
|
prover
|
|
1087
1349
|
]);
|
|
1088
1350
|
}
|
|
1089
|
-
async getAttesters() {
|
|
1090
|
-
|
|
1351
|
+
async getAttesters(timestamp) {
|
|
1352
|
+
// Pin every read to a single L1 block so the attester count and the chunked index reads
|
|
1353
|
+
// observe a consistent set. Without this, the count and each chunk default to `latest` and
|
|
1354
|
+
// can straddle a block boundary (or reorg), yielding an inconsistent or truncated set.
|
|
1355
|
+
const block = await this.client.getBlock();
|
|
1356
|
+
const blockNumber = block.number ?? undefined;
|
|
1357
|
+
const ts = timestamp ?? block.timestamp;
|
|
1358
|
+
const attesterSize = await this.getActiveAttesterCount({
|
|
1359
|
+
blockNumber
|
|
1360
|
+
});
|
|
1091
1361
|
const gse = new GSEContract(this.client, await this.getGSE());
|
|
1092
|
-
const ts = (await this.client.getBlock()).timestamp;
|
|
1093
1362
|
const indices = Array.from({
|
|
1094
1363
|
length: attesterSize
|
|
1095
1364
|
}, (_, i)=>BigInt(i));
|
|
1096
1365
|
const chunks = chunk(indices, 1000);
|
|
1097
|
-
const results = await Promise.all(chunks.map((chunk)=>gse.getAttestersFromIndicesAtTime(this.address, ts, chunk
|
|
1366
|
+
const results = await Promise.all(chunks.map((chunk)=>gse.getAttestersFromIndicesAtTime(this.address, ts, chunk, {
|
|
1367
|
+
blockNumber
|
|
1368
|
+
})));
|
|
1098
1369
|
return results.flat().map((addr)=>EthAddress.fromString(addr));
|
|
1099
1370
|
}
|
|
1100
1371
|
async getAttesterView(address) {
|
|
@@ -1195,7 +1466,8 @@ export class RollupContract {
|
|
|
1195
1466
|
const args = log.args;
|
|
1196
1467
|
if (args.checkpointNumber !== undefined) {
|
|
1197
1468
|
callback({
|
|
1198
|
-
checkpointNumber: CheckpointNumber.fromBigInt(args.checkpointNumber)
|
|
1469
|
+
checkpointNumber: CheckpointNumber.fromBigInt(args.checkpointNumber),
|
|
1470
|
+
event: log
|
|
1199
1471
|
});
|
|
1200
1472
|
}
|
|
1201
1473
|
}
|
|
@@ -1226,6 +1498,18 @@ export class RollupContract {
|
|
|
1226
1498
|
}
|
|
1227
1499
|
});
|
|
1228
1500
|
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Fetches OwnershipTransferred events emitted on the L1 block this rollup was deployed on.
|
|
1503
|
+
* The Rollup inherits from Ownable and emits this event in its constructor, so the event
|
|
1504
|
+
* is guaranteed to exist on `l1StartBlock` for any correctly deployed rollup. Used as a
|
|
1505
|
+
* probe to detect RPC nodes that prune historical logs.
|
|
1506
|
+
*/ async getOwnershipTransferredEventsAtDeploy() {
|
|
1507
|
+
const l1StartBlock = await this.getL1StartBlock();
|
|
1508
|
+
return await this.rollup.getEvents.OwnershipTransferred({}, {
|
|
1509
|
+
fromBlock: l1StartBlock,
|
|
1510
|
+
toBlock: l1StartBlock
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1229
1513
|
/** Fetches CheckpointProposed events within the given block range. */ async getCheckpointProposedEvents(fromBlock, toBlock) {
|
|
1230
1514
|
const logs = await this.rollup.getEvents.CheckpointProposed({}, {
|
|
1231
1515
|
fromBlock,
|
|
@@ -1254,4 +1538,43 @@ export class RollupContract {
|
|
|
1254
1538
|
}
|
|
1255
1539
|
}));
|
|
1256
1540
|
}
|
|
1541
|
+
/** Packs pending and proven checkpoint numbers into the chain tips storage format. */ static packChainTips(pendingCheckpointNumber, provenCheckpointNumber) {
|
|
1542
|
+
return pendingCheckpointNumber << 128n | provenCheckpointNumber & (1n << 128n) - 1n;
|
|
1543
|
+
}
|
|
1544
|
+
/** Storage slot for the chain tips (offset 0 within the STF storage struct). */ static get chainTipsStorageSlot() {
|
|
1545
|
+
return BigInt(RollupContract.stfStorageSlot);
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Computes the storage slot for a field within a tempCheckpointLog entry.
|
|
1549
|
+
* @param checkpointNumber - The checkpoint number
|
|
1550
|
+
* @param field - The field within the CompressedTempCheckpointLog struct
|
|
1551
|
+
*/ async getTempCheckpointLogStorageSlot(checkpointNumber, field) {
|
|
1552
|
+
const [epochDuration, proofSubmissionEpochs] = await Promise.all([
|
|
1553
|
+
this.getEpochDuration(),
|
|
1554
|
+
this.getProofSubmissionEpochs()
|
|
1555
|
+
]);
|
|
1556
|
+
return this.computeTempCheckpointLogStorageSlot(checkpointNumber, field, {
|
|
1557
|
+
epochDuration,
|
|
1558
|
+
proofSubmissionEpochs
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
computeTempCheckpointLogStorageSlot(checkpointNumber, field, constants) {
|
|
1562
|
+
const fieldOffset = BigInt(field);
|
|
1563
|
+
const { epochDuration, proofSubmissionEpochs } = constants;
|
|
1564
|
+
const roundaboutSize = BigInt(epochDuration) * (BigInt(proofSubmissionEpochs) + 1n) + 1n;
|
|
1565
|
+
const tempCheckpointLogsBase = BigInt(RollupContract.stfStorageSlot) + 2n;
|
|
1566
|
+
const circularIndex = BigInt(checkpointNumber) % roundaboutSize;
|
|
1567
|
+
const entryBase = BigInt(keccak256(encodeAbiParameters([
|
|
1568
|
+
{
|
|
1569
|
+
type: 'uint256'
|
|
1570
|
+
},
|
|
1571
|
+
{
|
|
1572
|
+
type: 'uint256'
|
|
1573
|
+
}
|
|
1574
|
+
], [
|
|
1575
|
+
circularIndex,
|
|
1576
|
+
tempCheckpointLogsBase
|
|
1577
|
+
])));
|
|
1578
|
+
return entryBase + fieldOffset;
|
|
1579
|
+
}
|
|
1257
1580
|
}
|