|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// Copyright 2024 Aztec Labs. |
| 3 | +pragma solidity >=0.8.27; |
| 4 | + |
| 5 | +import {DecoderBase} from "../base/DecoderBase.sol"; |
| 6 | + |
| 7 | +import {Registry} from "@aztec/governance/Registry.sol"; |
| 8 | +import {FeeJuicePortal} from "@aztec/core/messagebridge/FeeJuicePortal.sol"; |
| 9 | +import {TestERC20} from "@aztec/mock/TestERC20.sol"; |
| 10 | +import {TestConstants} from "../harnesses/TestConstants.sol"; |
| 11 | +import {RewardDistributor} from "@aztec/governance/RewardDistributor.sol"; |
| 12 | +import {ProposeArgs, ProposeLib} from "@aztec/core/libraries/rollup/ProposeLib.sol"; |
| 13 | + |
| 14 | +import {Timestamp, Slot, Epoch, TimeLib} from "@aztec/core/libraries/TimeLib.sol"; |
| 15 | + |
| 16 | +import {Errors} from "@aztec/core/libraries/Errors.sol"; |
| 17 | +import {ProposeArgs, ProposePayload, OracleInput, ProposeLib} from "@aztec/core/libraries/rollup/ProposeLib.sol"; |
| 18 | + |
| 19 | +import {RollupBase, IInstance} from "../base/RollupBase.sol"; |
| 20 | +import {RollupBuilder} from "../builder/RollupBuilder.sol"; |
| 21 | +import {TimeCheater} from "../staking/TimeCheater.sol"; |
| 22 | +import {Bps, BpsLib} from "@aztec/core/libraries/rollup/RewardLib.sol"; |
| 23 | +import { |
| 24 | + AttestationLib, |
| 25 | + Signature, |
| 26 | + CommitteeAttestation, |
| 27 | + CommitteeAttestations |
| 28 | +} from "@aztec/core/libraries/rollup/AttestationLib.sol"; |
| 29 | +import {Constants} from "@aztec/core/libraries/ConstantsGen.sol"; |
| 30 | +import {ProposedHeader} from "@aztec/core/libraries/rollup/ProposedHeaderLib.sol"; |
| 31 | +import {SafeCast} from "@oz/utils/math/SafeCast.sol"; |
| 32 | +import {AttestationLibHelper} from "@test/helper_libraries/AttestationLibHelper.sol"; |
| 33 | +import {Ownable} from "@oz/access/Ownable.sol"; |
| 34 | +import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol"; |
| 35 | +// solhint-disable comprehensive-interface |
| 36 | + |
| 37 | +struct Block { |
| 38 | + ProposeArgs proposeArgs; |
| 39 | + bytes blobInputs; |
| 40 | + CommitteeAttestation[] attestations; |
| 41 | + address[] signers; |
| 42 | +} |
| 43 | + |
| 44 | +/** |
| 45 | + * Blocks are generated using the `integration_l1_publisher.test.ts` tests. |
| 46 | + * Main use of these test is shorter cycles when updating the decoder contract. |
| 47 | + */ |
| 48 | +contract Tmnt223Test is RollupBase { |
| 49 | + using ProposeLib for ProposeArgs; |
| 50 | + using TimeLib for Timestamp; |
| 51 | + using TimeLib for Slot; |
| 52 | + using TimeLib for Epoch; |
| 53 | + |
| 54 | + Registry internal registry; |
| 55 | + TestERC20 internal testERC20; |
| 56 | + FeeJuicePortal internal feeJuicePortal; |
| 57 | + RewardDistributor internal rewardDistributor; |
| 58 | + TimeCheater internal timeCheater; |
| 59 | + |
| 60 | + uint256 internal SLOT_DURATION; |
| 61 | + uint256 internal EPOCH_DURATION; |
| 62 | + uint256 internal PROOF_SUBMISSION_EPOCHS; |
| 63 | + uint256 internal MANA_TARGET = 0; |
| 64 | + |
| 65 | + address internal sequencer = address(bytes20("sequencer")); |
| 66 | + |
| 67 | + DecoderBase.Full internal full; |
| 68 | + |
| 69 | + /** |
| 70 | + * @notice Set up the contracts needed for the tests with time aligned to the provided block name |
| 71 | + */ |
| 72 | + modifier setUpFor(string memory _name) { |
| 73 | + { |
| 74 | + full = load(_name); |
| 75 | + Slot slotNumber = full.block.header.slotNumber; |
| 76 | + uint256 initialTime = Timestamp.unwrap(full.block.header.timestamp) - Slot.unwrap(slotNumber) * SLOT_DURATION; |
| 77 | + vm.warp(initialTime); |
| 78 | + } |
| 79 | + |
| 80 | + TimeLib.initialize( |
| 81 | + block.timestamp, |
| 82 | + TestConstants.AZTEC_SLOT_DURATION, |
| 83 | + TestConstants.AZTEC_EPOCH_DURATION, |
| 84 | + TestConstants.AZTEC_PROOF_SUBMISSION_EPOCHS |
| 85 | + ); |
| 86 | + SLOT_DURATION = TestConstants.AZTEC_SLOT_DURATION; |
| 87 | + EPOCH_DURATION = TestConstants.AZTEC_EPOCH_DURATION; |
| 88 | + PROOF_SUBMISSION_EPOCHS = TestConstants.AZTEC_PROOF_SUBMISSION_EPOCHS; |
| 89 | + timeCheater = |
| 90 | + new TimeCheater(address(this), block.timestamp, SLOT_DURATION, EPOCH_DURATION, PROOF_SUBMISSION_EPOCHS); |
| 91 | + |
| 92 | + RollupBuilder builder = new RollupBuilder(address(this)).setManaTarget(MANA_TARGET).setTargetCommitteeSize(0); |
| 93 | + builder.deploy(); |
| 94 | + |
| 95 | + rollup = IInstance(address(builder.getConfig().rollup)); |
| 96 | + testERC20 = builder.getConfig().testERC20; |
| 97 | + registry = builder.getConfig().registry; |
| 98 | + |
| 99 | + feeJuicePortal = FeeJuicePortal(address(rollup.getFeeAssetPortal())); |
| 100 | + rewardDistributor = RewardDistributor(address(registry.getRewardDistributor())); |
| 101 | + |
| 102 | + _; |
| 103 | + } |
| 104 | + |
| 105 | + function test_deadlock() public setUpFor("empty_block_1") { |
| 106 | + skipBlobCheck(address(rollup)); |
| 107 | + timeCheater.cheat__progressSlot(); |
| 108 | + |
| 109 | + for (uint256 i = 0; i < 10; i++) { |
| 110 | + Block memory l2Block = getBlock(); |
| 111 | + rollup.propose( |
| 112 | + l2Block.proposeArgs, |
| 113 | + AttestationLibHelper.packAttestations(l2Block.attestations), |
| 114 | + l2Block.signers, |
| 115 | + l2Block.blobInputs |
| 116 | + ); |
| 117 | + timeCheater.cheat__progressSlot(); |
| 118 | + } |
| 119 | + |
| 120 | + // Now say that we alter the mana limit! Ensure that we can still produce blocks! |
| 121 | + MANA_TARGET = 1e6; |
| 122 | + vm.expectEmit(true, true, true, true, address(rollup.getInbox())); |
| 123 | + emit IInbox.InboxSynchronized(12); |
| 124 | + vm.prank(Ownable(address(rollup)).owner()); |
| 125 | + rollup.updateManaTarget(MANA_TARGET); |
| 126 | + |
| 127 | + Block memory nonEmptyBlock = getBlock(); |
| 128 | + rollup.propose( |
| 129 | + nonEmptyBlock.proposeArgs, |
| 130 | + AttestationLibHelper.packAttestations(nonEmptyBlock.attestations), |
| 131 | + nonEmptyBlock.signers, |
| 132 | + nonEmptyBlock.blobInputs |
| 133 | + ); |
| 134 | + |
| 135 | + assertEq(rollup.getPendingBlockNumber(), 11); |
| 136 | + assertEq(rollup.getInbox().getInProgress(), 13); |
| 137 | + } |
| 138 | + |
| 139 | + function getBlock() internal view returns (Block memory) { |
| 140 | + // We will be using the genesis for both before and after. This will be impossible |
| 141 | + // to prove, but we don't need to prove anything here. |
| 142 | + bytes32 archiveRoot = bytes32(Constants.GENESIS_ARCHIVE_ROOT); |
| 143 | + |
| 144 | + ProposedHeader memory header = full.block.header; |
| 145 | + |
| 146 | + Slot slotNumber = rollup.getCurrentSlot(); |
| 147 | + Timestamp ts = rollup.getTimestampForSlot(slotNumber); |
| 148 | + |
| 149 | + // Updating the header with important information! |
| 150 | + header.lastArchiveRoot = archiveRoot; |
| 151 | + header.slotNumber = slotNumber; |
| 152 | + header.timestamp = ts; |
| 153 | + header.coinbase = address(bytes20("coinbase")); |
| 154 | + header.feeRecipient = bytes32(0); |
| 155 | + header.gasFees.feePerL2Gas = SafeCast.toUint128(rollup.getManaBaseFeeAt(Timestamp.wrap(block.timestamp), true)); |
| 156 | + if (MANA_TARGET > 0) { |
| 157 | + header.totalManaUsed = MANA_TARGET; |
| 158 | + } else { |
| 159 | + header.totalManaUsed = 0; |
| 160 | + } |
| 161 | + |
| 162 | + ProposeArgs memory proposeArgs = ProposeArgs({ |
| 163 | + header: header, |
| 164 | + archive: archiveRoot, |
| 165 | + stateReference: EMPTY_STATE_REFERENCE, |
| 166 | + oracleInput: OracleInput({feeAssetPriceModifier: 0}) |
| 167 | + }); |
| 168 | + |
| 169 | + CommitteeAttestation[] memory attestations = new CommitteeAttestation[](0); |
| 170 | + address[] memory signers = new address[](0); |
| 171 | + |
| 172 | + return Block({ |
| 173 | + proposeArgs: proposeArgs, |
| 174 | + blobInputs: full.block.blobCommitments, |
| 175 | + attestations: attestations, |
| 176 | + signers: signers |
| 177 | + }); |
| 178 | + } |
| 179 | +} |
0 commit comments