@aztec/ethereum 0.0.1-commit.e2b2873ed → 0.0.1-commit.e304674f1
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 +10 -2
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +13 -7
- package/dest/config.d.ts +8 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +14 -10
- package/dest/contracts/empire_base.d.ts +3 -1
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/fee_asset_price_oracle.d.ts +101 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +651 -0
- package/dest/contracts/governance.js +3 -3
- package/dest/contracts/governance_proposer.d.ts +3 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +9 -0
- package/dest/contracts/inbox.d.ts +3 -3
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +5 -6
- 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 +51 -2
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +85 -0
- package/dest/contracts/registry.d.ts +3 -1
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/registry.js +30 -1
- package/dest/contracts/rollup.d.ts +48 -18
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +213 -52
- 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 +4 -8
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +35 -23
- package/dest/deploy_l1_contract.js +3 -3
- package/dest/generated/l1-contracts-defaults.d.ts +2 -2
- package/dest/generated/l1-contracts-defaults.js +2 -2
- package/dest/l1_artifacts.d.ts +9214 -15208
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_artifacts.js +9 -24
- package/dest/l1_contract_addresses.d.ts +1 -5
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +0 -6
- package/dest/l1_reader.d.ts +3 -1
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +6 -1
- package/dest/l1_tx_utils/config.d.ts +7 -1
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +14 -1
- package/dest/l1_tx_utils/factory.d.ts +18 -10
- package/dest/l1_tx_utils/factory.d.ts.map +1 -1
- package/dest/l1_tx_utils/factory.js +17 -7
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +15 -15
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +9 -15
- package/dest/l1_tx_utils/index-blobs.d.ts +3 -3
- package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -1
- package/dest/l1_tx_utils/index-blobs.js +2 -2
- package/dest/l1_tx_utils/index.d.ts +2 -1
- package/dest/l1_tx_utils/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/index.js +1 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +20 -7
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +75 -51
- 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 +8 -4
- package/dest/l1_tx_utils/tx_delayer.d.ts +56 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/{test → l1_tx_utils}/tx_delayer.js +62 -34
- 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.js +3 -3
- package/dest/test/chain_monitor.d.ts +22 -3
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +33 -2
- package/dest/test/eth_cheat_codes.d.ts +6 -4
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +6 -4
- package/dest/test/index.d.ts +1 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -2
- 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 +143 -29
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/utils.d.ts +1 -1
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +16 -12
- package/package.json +5 -7
- package/src/client.ts +10 -2
- package/src/config.ts +23 -14
- package/src/contracts/empire_base.ts +2 -0
- package/src/contracts/fee_asset_price_oracle.ts +280 -0
- package/src/contracts/governance.ts +3 -3
- package/src/contracts/governance_proposer.ts +6 -0
- package/src/contracts/inbox.ts +4 -4
- package/src/contracts/index.ts +2 -2
- package/src/contracts/multicall.ts +65 -1
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +250 -59
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +14 -16
- package/src/deploy_aztec_l1_contracts.ts +57 -34
- package/src/deploy_l1_contract.ts +3 -3
- package/src/generated/l1-contracts-defaults.ts +2 -2
- package/src/l1_artifacts.ts +12 -35
- package/src/l1_contract_addresses.ts +0 -7
- package/src/l1_reader.ts +13 -1
- package/src/l1_tx_utils/config.ts +20 -0
- package/src/l1_tx_utils/factory.ts +31 -31
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +43 -54
- package/src/l1_tx_utils/index-blobs.ts +2 -2
- package/src/l1_tx_utils/index.ts +1 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +68 -30
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +8 -4
- package/src/{test → l1_tx_utils}/tx_delayer.ts +78 -50
- package/src/publisher_manager.ts +105 -10
- package/src/queries.ts +3 -3
- package/src/test/chain_monitor.ts +60 -3
- package/src/test/eth_cheat_codes.ts +6 -4
- package/src/test/index.ts +0 -2
- package/src/test/start_anvil.ts +177 -29
- package/src/test/upgrade_utils.ts +2 -2
- package/src/utils.ts +17 -14
- package/dest/contracts/empire_slashing_proposer.d.ts +0 -67
- package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/empire_slashing_proposer.js +0 -207
- package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
- package/dest/test/delayed_tx_utils.d.ts +0 -13
- package/dest/test/delayed_tx_utils.d.ts.map +0 -1
- package/dest/test/delayed_tx_utils.js +0 -28
- package/dest/test/tx_delayer.d.ts +0 -36
- package/dest/test/tx_delayer.d.ts.map +0 -1
- package/src/contracts/empire_slashing_proposer.ts +0 -259
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
- package/src/test/delayed_tx_utils.ts +0 -52
package/src/contracts/rollup.ts
CHANGED
|
@@ -4,6 +4,7 @@ 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';
|
|
8
9
|
import { EscapeHatchAbi } from '@aztec/l1-artifacts/EscapeHatchAbi';
|
|
9
10
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
type Hex,
|
|
17
18
|
type StateOverride,
|
|
18
19
|
type WatchContractEventReturnType,
|
|
20
|
+
encodeAbiParameters,
|
|
19
21
|
encodeFunctionData,
|
|
20
22
|
getContract,
|
|
21
23
|
hexToBigInt,
|
|
@@ -29,11 +31,10 @@ import type { L1ReaderConfig } from '../l1_reader.js';
|
|
|
29
31
|
import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
|
|
30
32
|
import type { ViemClient } from '../types.js';
|
|
31
33
|
import { formatViemError } from '../utils.js';
|
|
32
|
-
import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
|
|
33
34
|
import { GSEContract } from './gse.js';
|
|
34
35
|
import type { L1EventLog } from './log.js';
|
|
35
36
|
import { SlasherContract } from './slasher_contract.js';
|
|
36
|
-
import {
|
|
37
|
+
import { SlashingProposerContract } from './slashing_proposer.js';
|
|
37
38
|
import { checkBlockTag } from './utils.js';
|
|
38
39
|
|
|
39
40
|
export type ViemCommitteeAttestation = {
|
|
@@ -55,7 +56,6 @@ export type L1RollupContractAddresses = Pick<
|
|
|
55
56
|
| 'feeJuiceAddress'
|
|
56
57
|
| 'stakingAssetAddress'
|
|
57
58
|
| 'rewardDistributorAddress'
|
|
58
|
-
| 'slashFactoryAddress'
|
|
59
59
|
| 'gseAddress'
|
|
60
60
|
>;
|
|
61
61
|
|
|
@@ -85,12 +85,6 @@ export type ViemGasFees = {
|
|
|
85
85
|
feePerL2Gas: bigint;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
export enum SlashingProposerType {
|
|
89
|
-
None = 0,
|
|
90
|
-
Tally = 1,
|
|
91
|
-
Empire = 2,
|
|
92
|
-
}
|
|
93
|
-
|
|
94
88
|
/**
|
|
95
89
|
* Status of a validator/attester in the staking system.
|
|
96
90
|
* Matches the Status enum in StakingLib.sol
|
|
@@ -134,6 +128,14 @@ export type L1FeeData = {
|
|
|
134
128
|
blobFee: bigint;
|
|
135
129
|
};
|
|
136
130
|
|
|
131
|
+
/** Components of the minimum fee per mana, as returned by the L1 rollup contract. */
|
|
132
|
+
export type ManaMinFeeComponents = {
|
|
133
|
+
sequencerCost: bigint;
|
|
134
|
+
proverCost: bigint;
|
|
135
|
+
congestionCost: bigint;
|
|
136
|
+
congestionMultiplier: bigint;
|
|
137
|
+
};
|
|
138
|
+
|
|
137
139
|
/**
|
|
138
140
|
* Reward configuration for the rollup
|
|
139
141
|
*/
|
|
@@ -193,10 +195,10 @@ export type CheckpointProposedArgs = {
|
|
|
193
195
|
checkpointNumber: CheckpointNumber;
|
|
194
196
|
archive: Fr;
|
|
195
197
|
versionedBlobHashes: Buffer[];
|
|
196
|
-
/** Hash of attestations
|
|
197
|
-
attestationsHash
|
|
198
|
-
/** Digest of the payload
|
|
199
|
-
payloadDigest
|
|
198
|
+
/** Hash of attestations emitted in the CheckpointProposed event. */
|
|
199
|
+
attestationsHash: Buffer32;
|
|
200
|
+
/** Digest of the payload emitted in the CheckpointProposed event. */
|
|
201
|
+
payloadDigest: Buffer32;
|
|
200
202
|
};
|
|
201
203
|
|
|
202
204
|
/** Log type for CheckpointProposed events. */
|
|
@@ -204,6 +206,7 @@ export type CheckpointProposedLog = L1EventLog<CheckpointProposedArgs>;
|
|
|
204
206
|
|
|
205
207
|
export class RollupContract {
|
|
206
208
|
private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
|
|
209
|
+
private readonly logger = createLogger('ethereum:rollup');
|
|
207
210
|
|
|
208
211
|
private static cachedStfStorageSlot: Hex | undefined;
|
|
209
212
|
private cachedEscapeHatch?: {
|
|
@@ -259,34 +262,18 @@ export class RollupContract {
|
|
|
259
262
|
return this.rollup;
|
|
260
263
|
}
|
|
261
264
|
|
|
262
|
-
public async getSlashingProposer(): Promise<
|
|
263
|
-
EmpireSlashingProposerContract | TallySlashingProposerContract | undefined
|
|
264
|
-
> {
|
|
265
|
+
public async getSlashingProposer(): Promise<SlashingProposerContract | undefined> {
|
|
265
266
|
const slasher = await this.getSlasherContract();
|
|
266
267
|
if (!slasher) {
|
|
267
268
|
return undefined;
|
|
268
269
|
}
|
|
269
270
|
|
|
270
271
|
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}`);
|
|
272
|
+
if (proposerAddress.isZero()) {
|
|
273
|
+
return undefined;
|
|
289
274
|
}
|
|
275
|
+
|
|
276
|
+
return new SlashingProposerContract(this.client, proposerAddress);
|
|
290
277
|
}
|
|
291
278
|
|
|
292
279
|
@memoize
|
|
@@ -379,6 +366,20 @@ export class RollupContract {
|
|
|
379
366
|
return Fr.fromString(await this.rollup.read.archiveAt([0n]));
|
|
380
367
|
}
|
|
381
368
|
|
|
369
|
+
@memoize
|
|
370
|
+
async getVkTreeRoot(): Promise<Fr> {
|
|
371
|
+
const slot = BigInt(RollupContract.stfStorageSlot) + 3n;
|
|
372
|
+
const value = await this.client.getStorageAt({ address: this.address, slot: `0x${slot.toString(16)}` });
|
|
373
|
+
return Fr.fromString(value ?? '0x0');
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
@memoize
|
|
377
|
+
async getProtocolContractsHash(): Promise<Fr> {
|
|
378
|
+
const slot = BigInt(RollupContract.stfStorageSlot) + 4n;
|
|
379
|
+
const value = await this.client.getStorageAt({ address: this.address, slot: `0x${slot.toString(16)}` });
|
|
380
|
+
return Fr.fromString(value ?? '0x0');
|
|
381
|
+
}
|
|
382
|
+
|
|
382
383
|
/**
|
|
383
384
|
* Returns rollup constants used for epoch queries.
|
|
384
385
|
* Return type is `L1RollupConstants` which is defined in stdlib,
|
|
@@ -392,16 +393,25 @@ export class RollupContract {
|
|
|
392
393
|
epochDuration: number;
|
|
393
394
|
proofSubmissionEpochs: number;
|
|
394
395
|
targetCommitteeSize: number;
|
|
396
|
+
rollupManaLimit: number;
|
|
395
397
|
}> {
|
|
396
|
-
const [
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
398
|
+
const [
|
|
399
|
+
l1StartBlock,
|
|
400
|
+
l1GenesisTime,
|
|
401
|
+
slotDuration,
|
|
402
|
+
epochDuration,
|
|
403
|
+
proofSubmissionEpochs,
|
|
404
|
+
targetCommitteeSize,
|
|
405
|
+
rollupManaLimit,
|
|
406
|
+
] = await Promise.all([
|
|
407
|
+
this.getL1StartBlock(),
|
|
408
|
+
this.getL1GenesisTime(),
|
|
409
|
+
this.getSlotDuration(),
|
|
410
|
+
this.getEpochDuration(),
|
|
411
|
+
this.getProofSubmissionEpochs(),
|
|
412
|
+
this.getTargetCommitteeSize(),
|
|
413
|
+
this.getManaLimit(),
|
|
414
|
+
]);
|
|
405
415
|
return {
|
|
406
416
|
l1StartBlock,
|
|
407
417
|
l1GenesisTime,
|
|
@@ -409,6 +419,7 @@ export class RollupContract {
|
|
|
409
419
|
epochDuration: Number(epochDuration),
|
|
410
420
|
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
411
421
|
targetCommitteeSize,
|
|
422
|
+
rollupManaLimit: Number(rollupManaLimit),
|
|
412
423
|
};
|
|
413
424
|
}
|
|
414
425
|
|
|
@@ -463,7 +474,11 @@ export class RollupContract {
|
|
|
463
474
|
|
|
464
475
|
const [isOpen] = await escapeHatch.read.isHatchOpen([BigInt(epoch)]);
|
|
465
476
|
return isOpen;
|
|
466
|
-
} catch {
|
|
477
|
+
} catch (err) {
|
|
478
|
+
this.logger.warn('isEscapeHatchOpen failed (treating as closed); RPC or contract error may cause liveness risk', {
|
|
479
|
+
epoch: Number(epoch),
|
|
480
|
+
error: err,
|
|
481
|
+
});
|
|
467
482
|
return false;
|
|
468
483
|
}
|
|
469
484
|
}
|
|
@@ -503,8 +518,9 @@ export class RollupContract {
|
|
|
503
518
|
return CheckpointNumber.fromBigInt(await this.rollup.read.getPendingCheckpointNumber());
|
|
504
519
|
}
|
|
505
520
|
|
|
506
|
-
async getProvenCheckpointNumber(): Promise<CheckpointNumber> {
|
|
507
|
-
|
|
521
|
+
async getProvenCheckpointNumber(options?: { blockNumber?: bigint }): Promise<CheckpointNumber> {
|
|
522
|
+
await checkBlockTag(options?.blockNumber, this.client);
|
|
523
|
+
return CheckpointNumber.fromBigInt(await this.rollup.read.getProvenCheckpointNumber(options));
|
|
508
524
|
}
|
|
509
525
|
|
|
510
526
|
async getSlotNumber(): Promise<SlotNumber> {
|
|
@@ -745,16 +761,23 @@ export class RollupContract {
|
|
|
745
761
|
* timestamp of the next L1 block
|
|
746
762
|
* @throws otherwise
|
|
747
763
|
*/
|
|
748
|
-
public async
|
|
764
|
+
public async canProposeAt(
|
|
749
765
|
archive: Buffer,
|
|
750
766
|
account: `0x${string}` | Account,
|
|
751
|
-
|
|
752
|
-
opts: {
|
|
767
|
+
timestamp: bigint,
|
|
768
|
+
opts: {
|
|
769
|
+
forcePendingCheckpointNumber?: CheckpointNumber;
|
|
770
|
+
forceArchive?: { checkpointNumber: CheckpointNumber; archive: Fr };
|
|
771
|
+
} = {},
|
|
753
772
|
): Promise<{ slot: SlotNumber; checkpointNumber: CheckpointNumber; timeOfNextL1Slot: bigint }> {
|
|
754
|
-
const
|
|
755
|
-
const timeOfNextL1Slot = latestBlock.timestamp + BigInt(slotDuration);
|
|
773
|
+
const timeOfNextL1Slot = timestamp;
|
|
756
774
|
const who = typeof account === 'string' ? account : account.address;
|
|
757
775
|
|
|
776
|
+
const stateOverride = RollupContract.mergeStateOverrides(
|
|
777
|
+
await this.makePendingCheckpointNumberOverride(opts.forcePendingCheckpointNumber),
|
|
778
|
+
opts.forceArchive ? this.makeArchiveOverride(opts.forceArchive.checkpointNumber, opts.forceArchive.archive) : [],
|
|
779
|
+
);
|
|
780
|
+
|
|
758
781
|
try {
|
|
759
782
|
const {
|
|
760
783
|
result: [slot, checkpointNumber],
|
|
@@ -764,7 +787,7 @@ export class RollupContract {
|
|
|
764
787
|
functionName: 'canProposeAtTime',
|
|
765
788
|
args: [timeOfNextL1Slot, `0x${archive.toString('hex')}`, who],
|
|
766
789
|
account,
|
|
767
|
-
stateOverride
|
|
790
|
+
stateOverride,
|
|
768
791
|
});
|
|
769
792
|
|
|
770
793
|
return {
|
|
@@ -800,6 +823,151 @@ export class RollupContract {
|
|
|
800
823
|
];
|
|
801
824
|
}
|
|
802
825
|
|
|
826
|
+
/**
|
|
827
|
+
* Returns a state override that sets tempCheckpointLogs[checkpointNumber].feeHeader to the compressed fee header.
|
|
828
|
+
* Used when simulating a propose call where the parent checkpoint hasn't landed on L1 yet (pipelining).
|
|
829
|
+
*/
|
|
830
|
+
public async makeFeeHeaderOverride(checkpointNumber: CheckpointNumber, feeHeader: FeeHeader): Promise<StateOverride> {
|
|
831
|
+
const { epochDuration, proofSubmissionEpochs } = await this.getRollupConstants();
|
|
832
|
+
const roundaboutSize = BigInt(epochDuration * (proofSubmissionEpochs + 1) + 1);
|
|
833
|
+
const circularIndex = BigInt(checkpointNumber) % roundaboutSize;
|
|
834
|
+
|
|
835
|
+
// tempCheckpointLogs is at offset 2 in RollupStore
|
|
836
|
+
const tempCheckpointLogsMappingBase = hexToBigInt(RollupContract.stfStorageSlot) + 2n;
|
|
837
|
+
|
|
838
|
+
// Solidity mapping slot: keccak256(abi.encode(key, baseSlot))
|
|
839
|
+
const structBaseSlot = hexToBigInt(
|
|
840
|
+
keccak256(
|
|
841
|
+
encodeAbiParameters([{ type: 'uint256' }, { type: 'uint256' }], [circularIndex, tempCheckpointLogsMappingBase]),
|
|
842
|
+
),
|
|
843
|
+
);
|
|
844
|
+
|
|
845
|
+
// feeHeader is the 7th field (offset 6) in CompressedTempCheckpointLog
|
|
846
|
+
const feeHeaderSlot = structBaseSlot + 6n;
|
|
847
|
+
const compressed = RollupContract.compressFeeHeader(feeHeader);
|
|
848
|
+
|
|
849
|
+
return [
|
|
850
|
+
{
|
|
851
|
+
address: this.address,
|
|
852
|
+
stateDiff: [
|
|
853
|
+
{
|
|
854
|
+
slot: `0x${feeHeaderSlot.toString(16).padStart(64, '0')}`,
|
|
855
|
+
value: `0x${compressed.toString(16).padStart(64, '0')}`,
|
|
856
|
+
},
|
|
857
|
+
],
|
|
858
|
+
},
|
|
859
|
+
];
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Returns a state override that sets archives[checkpointNumber] to the given archive value.
|
|
864
|
+
* Used when simulating a canProposeAtTime call where the local archive differs from L1
|
|
865
|
+
* (e.g. pipelining where the parent checkpoint hasn't landed on L1 yet).
|
|
866
|
+
*/
|
|
867
|
+
public makeArchiveOverride(checkpointNumber: CheckpointNumber, archive: Fr): StateOverride {
|
|
868
|
+
const archivesMappingBase = hexToBigInt(RollupContract.stfStorageSlot) + 1n;
|
|
869
|
+
const archiveSlot = hexToBigInt(
|
|
870
|
+
keccak256(
|
|
871
|
+
encodeAbiParameters(
|
|
872
|
+
[{ type: 'uint256' }, { type: 'uint256' }],
|
|
873
|
+
[BigInt(checkpointNumber), archivesMappingBase],
|
|
874
|
+
),
|
|
875
|
+
),
|
|
876
|
+
);
|
|
877
|
+
return [
|
|
878
|
+
{
|
|
879
|
+
address: this.address,
|
|
880
|
+
stateDiff: [
|
|
881
|
+
{
|
|
882
|
+
slot: `0x${archiveSlot.toString(16).padStart(64, '0')}`,
|
|
883
|
+
value: archive.toString(),
|
|
884
|
+
},
|
|
885
|
+
],
|
|
886
|
+
},
|
|
887
|
+
];
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/** Merges multiple StateOverride arrays, combining stateDiff entries for the same address. */
|
|
891
|
+
public static mergeStateOverrides(...overrides: StateOverride[]): StateOverride {
|
|
892
|
+
type StateDiffEntry = { slot: `0x${string}`; value: `0x${string}` };
|
|
893
|
+
const byAddress = new Map<string, { address: `0x${string}`; balance?: bigint; stateDiff: StateDiffEntry[] }>();
|
|
894
|
+
for (const override of overrides) {
|
|
895
|
+
for (const entry of override) {
|
|
896
|
+
const key = entry.address.toLowerCase();
|
|
897
|
+
const existing = byAddress.get(key);
|
|
898
|
+
if (existing) {
|
|
899
|
+
existing.stateDiff.push(...(entry.stateDiff ?? []));
|
|
900
|
+
if (entry.balance !== undefined) {
|
|
901
|
+
existing.balance = entry.balance;
|
|
902
|
+
}
|
|
903
|
+
} else {
|
|
904
|
+
byAddress.set(key, {
|
|
905
|
+
address: entry.address,
|
|
906
|
+
balance: entry.balance,
|
|
907
|
+
stateDiff: [...(entry.stateDiff ?? [])],
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return [...byAddress.values()];
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/** Compresses a FeeHeader into a uint256 matching FeeHeaderLib.compress() in FeeStructs.sol. */
|
|
916
|
+
public static compressFeeHeader(feeHeader: FeeHeader): bigint {
|
|
917
|
+
const MASK_48_BITS = (1n << 48n) - 1n;
|
|
918
|
+
const MASK_64_BITS = (1n << 64n) - 1n;
|
|
919
|
+
const MASK_63_BITS = (1n << 63n) - 1n;
|
|
920
|
+
|
|
921
|
+
let value = BigInt(feeHeader.manaUsed) & ((1n << 32n) - 1n); // bits [0:31]
|
|
922
|
+
value |= (feeHeader.excessMana < MASK_48_BITS ? feeHeader.excessMana : MASK_48_BITS) << 32n; // bits [32:79]
|
|
923
|
+
value |= (BigInt(feeHeader.ethPerFeeAsset) & MASK_48_BITS) << 80n; // bits [80:127]
|
|
924
|
+
value |= (feeHeader.congestionCost < MASK_64_BITS ? feeHeader.congestionCost : MASK_64_BITS) << 128n; // bits [128:191]
|
|
925
|
+
value |= (feeHeader.proverCost < MASK_63_BITS ? feeHeader.proverCost : MASK_63_BITS) << 192n; // bits [192:254]
|
|
926
|
+
value |= 1n << 255n; // preheat flag
|
|
927
|
+
return value;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/** Computes the fee header for a child checkpoint given parent fee header and child data.
|
|
931
|
+
* Must stay in sync with Solidity FeeLib.sol (computeNewEthPerFeeAsset, clampedAdd). */
|
|
932
|
+
public static computeChildFeeHeader(
|
|
933
|
+
parentFeeHeader: FeeHeader,
|
|
934
|
+
childManaUsed: bigint,
|
|
935
|
+
feeAssetPriceModifier: bigint,
|
|
936
|
+
manaTarget: bigint,
|
|
937
|
+
): FeeHeader {
|
|
938
|
+
const MIN_ETH_PER_FEE_ASSET = 100n;
|
|
939
|
+
const MAX_ETH_PER_FEE_ASSET = 100_000_000_000_000n; // 1e14, matches FeeLib.sol
|
|
940
|
+
|
|
941
|
+
// excessMana = clampedAdd(parent.excessMana + parent.manaUsed, -manaTarget)
|
|
942
|
+
const sum = parentFeeHeader.excessMana + parentFeeHeader.manaUsed;
|
|
943
|
+
const excessMana = sum > manaTarget ? sum - manaTarget : 0n;
|
|
944
|
+
|
|
945
|
+
// ethPerFeeAsset = computeNewEthPerFeeAsset(max(parent.ethPerFeeAsset, MIN), modifier)
|
|
946
|
+
const parentPrice =
|
|
947
|
+
parentFeeHeader.ethPerFeeAsset > MIN_ETH_PER_FEE_ASSET ? parentFeeHeader.ethPerFeeAsset : MIN_ETH_PER_FEE_ASSET;
|
|
948
|
+
let newPrice: bigint;
|
|
949
|
+
if (feeAssetPriceModifier >= 0n) {
|
|
950
|
+
newPrice = (parentPrice * (10_000n + feeAssetPriceModifier)) / 10_000n;
|
|
951
|
+
} else {
|
|
952
|
+
const absMod = -feeAssetPriceModifier;
|
|
953
|
+
newPrice = (parentPrice * (10_000n - absMod)) / 10_000n;
|
|
954
|
+
}
|
|
955
|
+
if (newPrice < MIN_ETH_PER_FEE_ASSET) {
|
|
956
|
+
newPrice = MIN_ETH_PER_FEE_ASSET;
|
|
957
|
+
}
|
|
958
|
+
if (newPrice > MAX_ETH_PER_FEE_ASSET) {
|
|
959
|
+
newPrice = MAX_ETH_PER_FEE_ASSET;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
return {
|
|
963
|
+
excessMana,
|
|
964
|
+
manaUsed: childManaUsed,
|
|
965
|
+
ethPerFeeAsset: newPrice,
|
|
966
|
+
congestionCost: 0n,
|
|
967
|
+
proverCost: 0n,
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
|
|
803
971
|
/** Creates a request to Rollup#invalidateBadAttestation to be simulated or sent */
|
|
804
972
|
public buildInvalidateBadAttestationRequest(
|
|
805
973
|
checkpointNumber: CheckpointNumber,
|
|
@@ -848,8 +1016,18 @@ export class RollupContract {
|
|
|
848
1016
|
return this.rollup.read.getHasSubmitted([BigInt(epochNumber), BigInt(numberOfCheckpointsInEpoch), prover]);
|
|
849
1017
|
}
|
|
850
1018
|
|
|
851
|
-
getManaMinFeeAt(timestamp: bigint, inFeeAsset: boolean): Promise<bigint> {
|
|
852
|
-
return this.rollup.read.getManaMinFeeAt([timestamp, inFeeAsset]);
|
|
1019
|
+
getManaMinFeeAt(timestamp: bigint, inFeeAsset: boolean, stateOverride?: StateOverride): Promise<bigint> {
|
|
1020
|
+
return this.rollup.read.getManaMinFeeAt([timestamp, inFeeAsset], { stateOverride });
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
async getManaMinFeeComponentsAt(timestamp: bigint, inFeeAsset: boolean): Promise<ManaMinFeeComponents> {
|
|
1024
|
+
const result = await this.rollup.read.getManaMinFeeComponentsAt([timestamp, inFeeAsset]);
|
|
1025
|
+
return {
|
|
1026
|
+
sequencerCost: result.sequencerCost,
|
|
1027
|
+
proverCost: result.proverCost,
|
|
1028
|
+
congestionCost: result.congestionCost,
|
|
1029
|
+
congestionMultiplier: result.congestionMultiplier,
|
|
1030
|
+
};
|
|
853
1031
|
}
|
|
854
1032
|
|
|
855
1033
|
async getSlotAt(timestamp: bigint): Promise<SlotNumber> {
|
|
@@ -895,11 +1073,10 @@ export class RollupContract {
|
|
|
895
1073
|
return this.rollup.read.getSpecificProverRewardsForEpoch([epoch, prover]);
|
|
896
1074
|
}
|
|
897
1075
|
|
|
898
|
-
async getAttesters(): Promise<EthAddress[]> {
|
|
1076
|
+
async getAttesters(timestamp?: bigint): Promise<EthAddress[]> {
|
|
899
1077
|
const attesterSize = await this.getActiveAttesterCount();
|
|
900
1078
|
const gse = new GSEContract(this.client, await this.getGSE());
|
|
901
|
-
const ts = (await this.client.getBlock()).timestamp;
|
|
902
|
-
|
|
1079
|
+
const ts = timestamp ?? (await this.client.getBlock()).timestamp;
|
|
903
1080
|
const indices = Array.from({ length: attesterSize }, (_, i) => BigInt(i));
|
|
904
1081
|
const chunks = chunk(indices, 1000);
|
|
905
1082
|
|
|
@@ -1060,8 +1237,22 @@ export class RollupContract {
|
|
|
1060
1237
|
checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
|
|
1061
1238
|
archive: Fr.fromString(log.args.archive!),
|
|
1062
1239
|
versionedBlobHashes: log.args.versionedBlobHashes!.map(h => Buffer.from(h.slice(2), 'hex')),
|
|
1063
|
-
attestationsHash:
|
|
1064
|
-
|
|
1240
|
+
attestationsHash: (() => {
|
|
1241
|
+
if (!log.args.attestationsHash) {
|
|
1242
|
+
throw new Error(
|
|
1243
|
+
`CheckpointProposed event missing attestationsHash for checkpoint ${log.args.checkpointNumber}`,
|
|
1244
|
+
);
|
|
1245
|
+
}
|
|
1246
|
+
return Buffer32.fromString(log.args.attestationsHash);
|
|
1247
|
+
})(),
|
|
1248
|
+
payloadDigest: (() => {
|
|
1249
|
+
if (!log.args.payloadDigest) {
|
|
1250
|
+
throw new Error(
|
|
1251
|
+
`CheckpointProposed event missing payloadDigest for checkpoint ${log.args.checkpointNumber}`,
|
|
1252
|
+
);
|
|
1253
|
+
}
|
|
1254
|
+
return Buffer32.fromString(log.args.payloadDigest);
|
|
1255
|
+
})(),
|
|
1065
1256
|
},
|
|
1066
1257
|
}));
|
|
1067
1258
|
}
|
|
@@ -7,7 +7,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
7
7
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
8
|
import { hexToBuffer } from '@aztec/foundation/string';
|
|
9
9
|
import { SlasherAbi } from '@aztec/l1-artifacts/SlasherAbi';
|
|
10
|
-
import {
|
|
10
|
+
import { SlashingProposerAbi } from '@aztec/l1-artifacts/SlashingProposerAbi';
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
13
|
type GetContractReturnType,
|
|
@@ -19,13 +19,11 @@ import {
|
|
|
19
19
|
} from 'viem';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* Wrapper around the
|
|
22
|
+
* Wrapper around the SlashingProposer contract that provides
|
|
23
23
|
* a TypeScript interface for interacting with the consensus-based slashing system.
|
|
24
24
|
*/
|
|
25
|
-
export class
|
|
26
|
-
private readonly contract: GetContractReturnType<typeof
|
|
27
|
-
|
|
28
|
-
public readonly type = 'tally' as const;
|
|
25
|
+
export class SlashingProposerContract {
|
|
26
|
+
private readonly contract: GetContractReturnType<typeof SlashingProposerAbi, ViemClient>;
|
|
29
27
|
|
|
30
28
|
constructor(
|
|
31
29
|
public readonly client: ViemClient,
|
|
@@ -33,7 +31,7 @@ export class TallySlashingProposerContract {
|
|
|
33
31
|
) {
|
|
34
32
|
this.contract = getContract({
|
|
35
33
|
address: typeof address === 'string' ? address : address.toString(),
|
|
36
|
-
abi:
|
|
34
|
+
abi: SlashingProposerAbi,
|
|
37
35
|
client,
|
|
38
36
|
});
|
|
39
37
|
}
|
|
@@ -136,12 +134,12 @@ export class TallySlashingProposerContract {
|
|
|
136
134
|
|
|
137
135
|
/** Tries to extract a VoteCast event from the given logs. */
|
|
138
136
|
public tryExtractVoteCastEvent(logs: Log[]) {
|
|
139
|
-
return tryExtractEvent(logs, this.address.toString(),
|
|
137
|
+
return tryExtractEvent(logs, this.address.toString(), SlashingProposerAbi, 'VoteCast');
|
|
140
138
|
}
|
|
141
139
|
|
|
142
140
|
/** Tries to extract a RoundExecuted event from the given logs. */
|
|
143
141
|
public tryExtractRoundExecutedEvent(logs: Log[]) {
|
|
144
|
-
return tryExtractEvent(logs, this.address.toString(),
|
|
142
|
+
return tryExtractEvent(logs, this.address.toString(), SlashingProposerAbi, 'RoundExecuted');
|
|
145
143
|
}
|
|
146
144
|
|
|
147
145
|
/**
|
|
@@ -161,9 +159,9 @@ export class TallySlashingProposerContract {
|
|
|
161
159
|
|
|
162
160
|
return {
|
|
163
161
|
to: this.contract.address,
|
|
164
|
-
abi:
|
|
162
|
+
abi: SlashingProposerAbi,
|
|
165
163
|
data: encodeFunctionData({
|
|
166
|
-
abi:
|
|
164
|
+
abi: SlashingProposerAbi,
|
|
167
165
|
functionName: 'vote',
|
|
168
166
|
args: [votes, signature.toViemSignature()],
|
|
169
167
|
}),
|
|
@@ -173,7 +171,7 @@ export class TallySlashingProposerContract {
|
|
|
173
171
|
/** Returns the typed data definition to EIP712-sign for voting */
|
|
174
172
|
public buildVoteTypedData(votes: Hex, slot: SlotNumber): TypedDataDefinition {
|
|
175
173
|
const domain = {
|
|
176
|
-
name: '
|
|
174
|
+
name: 'SlashingProposer',
|
|
177
175
|
version: '1',
|
|
178
176
|
chainId: this.client.chain.id,
|
|
179
177
|
verifyingContract: this.contract.address,
|
|
@@ -209,9 +207,9 @@ export class TallySlashingProposerContract {
|
|
|
209
207
|
public buildVoteRequestWithSignature(votes: Hex, signature: { v: number; r: Hex; s: Hex }): L1TxRequest {
|
|
210
208
|
return {
|
|
211
209
|
to: this.contract.address,
|
|
212
|
-
abi:
|
|
210
|
+
abi: SlashingProposerAbi,
|
|
213
211
|
data: encodeFunctionData({
|
|
214
|
-
abi:
|
|
212
|
+
abi: SlashingProposerAbi,
|
|
215
213
|
functionName: 'vote',
|
|
216
214
|
args: [votes, signature],
|
|
217
215
|
}),
|
|
@@ -227,9 +225,9 @@ export class TallySlashingProposerContract {
|
|
|
227
225
|
public buildExecuteRoundRequest(round: bigint, committees: EthAddress[][]): L1TxRequest {
|
|
228
226
|
return {
|
|
229
227
|
to: this.contract.address,
|
|
230
|
-
abi: mergeAbis([
|
|
228
|
+
abi: mergeAbis([SlashingProposerAbi, SlasherAbi]),
|
|
231
229
|
data: encodeFunctionData({
|
|
232
|
-
abi:
|
|
230
|
+
abi: SlashingProposerAbi,
|
|
233
231
|
functionName: 'executeRound',
|
|
234
232
|
args: [round, committees.map(c => c.map(addr => addr.toString()))],
|
|
235
233
|
}),
|