Skip to content

Commit 7ad42c0

Browse files
committed
Suggestions from code review
1 parent 3ed7201 commit 7ad42c0

File tree

9 files changed

+43
-51
lines changed

9 files changed

+43
-51
lines changed

l1-contracts/src/core/Rollup.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ contract Rollup is IStaking, IValidatorSelection, IRollup, RollupCore {
102102
* @param _blobsHash - The blobs hash for this block
103103
* @param _flags - The flags to validate
104104
*/
105-
function validateHeader(
105+
function validateHeaderWithAttestations(
106106
ProposedHeader calldata _header,
107107
CommitteeAttestations memory _attestations,
108108
address[] calldata _signers,
@@ -111,7 +111,7 @@ contract Rollup is IStaking, IValidatorSelection, IRollup, RollupCore {
111111
BlockHeaderValidationFlags memory _flags
112112
) external override(IRollup) {
113113
Timestamp currentTime = Timestamp.wrap(block.timestamp);
114-
ExtRollupLib.validateHeader(
114+
ExtRollupLib.validateHeaderWithAttestations(
115115
ValidateHeaderArgs({
116116
header: _header,
117117
digest: _digest,

l1-contracts/src/core/interfaces/IRollup.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ interface IRollupCore {
146146
}
147147

148148
interface IRollup is IRollupCore, IHaveVersion {
149-
function validateHeader(
149+
function validateHeaderWithAttestations(
150150
ProposedHeader calldata _header,
151151
CommitteeAttestations memory _attestations,
152152
address[] memory _signers,

l1-contracts/src/core/libraries/rollup/EpochProofLib.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
IRollupCore,
99
RollupStore
1010
} from "@aztec/core/interfaces/IRollup.sol";
11-
import {TempBlockLog} from "@aztec/core/libraries/compressed-data/BlockLog.sol";
11+
import {CompressedTempBlockLog} from "@aztec/core/libraries/compressed-data/BlockLog.sol";
1212
import {ChainTipsLib, CompressedChainTips} from "@aztec/core/libraries/compressed-data/Tips.sol";
1313
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
1414
import {Errors} from "@aztec/core/libraries/Errors.sol";
@@ -18,6 +18,7 @@ import {RewardLib} from "@aztec/core/libraries/rollup/RewardLib.sol";
1818
import {STFLib} from "@aztec/core/libraries/rollup/STFLib.sol";
1919
import {ValidatorSelectionLib} from "@aztec/core/libraries/rollup/ValidatorSelectionLib.sol";
2020
import {Timestamp, Slot, Epoch, TimeLib} from "@aztec/core/libraries/TimeLib.sol";
21+
import {CompressedSlot, CompressedTimeMath} from "@aztec/shared/libraries/CompressedTimeMath.sol";
2122
import {CommitteeAttestations, SignatureLib} from "@aztec/shared/libraries/SignatureLib.sol";
2223
import {Math} from "@oz/utils/math/Math.sol";
2324
import {SafeCast} from "@oz/utils/math/SafeCast.sol";
@@ -30,6 +31,7 @@ library EpochProofLib {
3031
using SafeCast for uint256;
3132
using ChainTipsLib for CompressedChainTips;
3233
using SignatureLib for CommitteeAttestations;
34+
using CompressedTimeMath for CompressedSlot;
3335

3436
// This is a temporary struct to avoid stack too deep errors
3537
struct BlobVarsTemp {
@@ -224,7 +226,7 @@ library EpochProofLib {
224226
CommitteeAttestations memory _attestations
225227
) private {
226228
// Get the stored attestation hash and payload digest for the last block
227-
TempBlockLog memory blockLog = STFLib.getTempBlockLog(_endBlockNumber);
229+
CompressedTempBlockLog storage blockLog = STFLib.getStorageTempBlockLog(_endBlockNumber);
228230

229231
// Verify that the provided attestations match the stored hash
230232
bytes32 providedAttestationsHash = keccak256(abi.encode(_attestations));
@@ -233,10 +235,10 @@ library EpochProofLib {
233235
);
234236

235237
// Get the slot and epoch for the last block
236-
Slot slot = blockLog.slotNumber;
238+
Slot slot = blockLog.slotNumber.decompress();
237239
Epoch epoch = STFLib.getEpochForBlock(_endBlockNumber);
238240

239-
ValidatorSelectionLib.verify(slot, epoch, _attestations, blockLog.payloadDigest);
241+
ValidatorSelectionLib.verifyAttestations(slot, epoch, _attestations, blockLog.payloadDigest);
240242
}
241243

242244
function assertAcceptable(uint256 _start, uint256 _end) private view returns (Epoch) {

l1-contracts/src/core/libraries/rollup/ExtRollupLib.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ library ExtRollupLib {
2929
EpochProofLib.submitEpochRootProof(_args);
3030
}
3131

32-
function validateHeader(
32+
function validateHeaderWithAttestations(
3333
ValidateHeaderArgs calldata _args,
3434
CommitteeAttestations calldata _attestations,
3535
address[] calldata _signers
@@ -41,7 +41,7 @@ library ExtRollupLib {
4141

4242
Slot slot = _args.header.slotNumber;
4343
Epoch epoch = slot.epochFromSlot();
44-
ValidatorSelectionLib.verify(slot, epoch, _attestations, _args.digest);
44+
ValidatorSelectionLib.verifyAttestations(slot, epoch, _attestations, _args.digest);
4545
ValidatorSelectionLib.verifyProposer(slot, epoch, _attestations, _signers, _args.digest);
4646
}
4747

l1-contracts/src/core/libraries/rollup/InvalidateLib.sol

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ library InvalidateLib {
5858
revert Errors.Rollup__AttestationsAreValid();
5959
}
6060

61-
// Reset the pending block number to remove this block and all subsequent blocks
62-
RollupStore storage rollupStore = STFLib.getStorage();
63-
rollupStore.tips = rollupStore.tips.updatePendingBlockNumber(_blockNumber - 1);
64-
6561
_invalidateBlock(_blockNumber);
6662
}
6763

l1-contracts/src/core/libraries/rollup/ValidatorSelectionLib.sol

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ library ValidatorSelectionLib {
4040
uint256 needed;
4141
uint256 signaturesRecovered;
4242
address[] reconstructedCommittee;
43-
bool proposerVerified;
4443
}
4544

4645
bytes32 private constant VALIDATOR_SELECTION_STORAGE_POSITION =
@@ -98,32 +97,38 @@ library ValidatorSelectionLib {
9897
address[] memory _signers,
9998
bytes32 _digest
10099
) internal {
101-
// Load the committee commitment for the epoch
102-
(bytes32 committeeCommitment, uint256 committeeSize) = getCommitteeCommitmentAt(_epochNumber);
100+
// Try load the proposer from cache
101+
(address proposer, uint256 proposerIndex) = getCachedProposer(_slot);
103102

104-
// If the target committee size is 0, we skip the validation
105-
if (committeeSize == 0) {
106-
return;
107-
}
103+
// If not in cache, grab from the committee, reconstructed from the attestations and signers
104+
if (proposer == address(0)) {
105+
// Load the committee commitment for the epoch
106+
(bytes32 committeeCommitment, uint256 committeeSize) = getCommitteeCommitmentAt(_epochNumber);
108107

109-
// Reconstruct the committee from the attestations and signers
110-
address[] memory committee =
111-
_attestations.reconstructCommitteeFromSigners(_signers, committeeSize);
108+
// If the target committee size is 0, we skip the validation
109+
if (committeeSize == 0) {
110+
return;
111+
}
112112

113-
// Check it matches the expected one
114-
bytes32 reconstructedCommitment = computeCommitteeCommitment(committee);
115-
if (reconstructedCommitment != committeeCommitment) {
116-
revert Errors.ValidatorSelection__InvalidCommitteeCommitment(
117-
reconstructedCommitment, committeeCommitment
118-
);
119-
}
113+
// Reconstruct the committee from the attestations and signers
114+
address[] memory committee =
115+
_attestations.reconstructCommitteeFromSigners(_signers, committeeSize);
120116

121-
// Get the proposer from the committee based on the epoch, slot, and sample seed
122-
uint224 sampleSeed = getSampleSeed(_epochNumber);
123-
uint256 proposerIndex = computeProposerIndex(_epochNumber, _slot, sampleSeed, committeeSize);
124-
address proposer = committee[proposerIndex];
117+
// Check it matches the expected one
118+
bytes32 reconstructedCommitment = computeCommitteeCommitment(committee);
119+
if (reconstructedCommitment != committeeCommitment) {
120+
revert Errors.ValidatorSelection__InvalidCommitteeCommitment(
121+
reconstructedCommitment, committeeCommitment
122+
);
123+
}
125124

126-
setCachedProposer(_slot, proposer, proposerIndex);
125+
// Get the proposer from the committee based on the epoch, slot, and sample seed
126+
uint224 sampleSeed = getSampleSeed(_epochNumber);
127+
proposerIndex = computeProposerIndex(_epochNumber, _slot, sampleSeed, committeeSize);
128+
proposer = committee[proposerIndex];
129+
130+
setCachedProposer(_slot, proposer, proposerIndex);
131+
}
127132

128133
// If the proposer is who sent the tx, we're good
129134
if (proposer == msg.sender) {
@@ -145,20 +150,18 @@ library ValidatorSelectionLib {
145150
/**
146151
* @notice Propose a pending block from the point-of-view of sequencer selection. Will:
147152
* - Setup the epoch if needed (if epoch committee is empty skips the rest)
148-
* - Validate that the proposer has signed with its own key
149153
* - Validate that the signatures for attestations are indeed from the validatorset
150154
* - Validate that the number of valid attestations is sufficient
151155
*
152156
* @dev Cases where errors are thrown:
153157
* - If the epoch is not setup
154-
* - If the proposer is not the real proposer AND the proposer is not open
155158
* - If the number of valid attestations is insufficient
156159
*
157160
* @param _slot - The slot of the block
158161
* @param _attestations - The signatures (or empty; just address is provided) of the committee members
159162
* @param _digest - The digest of the block
160163
*/
161-
function verify(
164+
function verifyAttestations(
162165
Slot _slot,
163166
Epoch _epochNumber,
164167
CommitteeAttestations memory _attestations,
@@ -181,8 +184,7 @@ library ValidatorSelectionLib {
181184
needed: (targetCommitteeSize << 1) / 3 + 1, // targetCommitteeSize * 2 / 3 + 1, but cheaper
182185
index: 0,
183186
signaturesRecovered: 0,
184-
reconstructedCommittee: new address[](targetCommitteeSize),
185-
proposerVerified: false
187+
reconstructedCommittee: new address[](targetCommitteeSize)
186188
});
187189

188190
bytes32 digest = _digest.toEthSignedMessageHash();
@@ -213,10 +215,6 @@ library ValidatorSelectionLib {
213215

214216
++stack.signaturesRecovered;
215217
stack.reconstructedCommittee[i] = ECDSA.recover(digest, v, r, s);
216-
217-
if (i == stack.proposerIndex) {
218-
stack.proposerVerified = true;
219-
}
220218
} else {
221219
address addr;
222220
assembly {
@@ -230,10 +228,6 @@ library ValidatorSelectionLib {
230228

231229
address proposer = stack.reconstructedCommittee[stack.proposerIndex];
232230

233-
require(
234-
stack.proposerVerified, Errors.ValidatorSelection__InvalidProposer(proposer, address(0))
235-
);
236-
237231
require(
238232
stack.signaturesRecovered >= stack.needed,
239233
Errors.ValidatorSelection__InsufficientAttestations(stack.needed, stack.signaturesRecovered)

l1-contracts/test/Rollup.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ contract RollupTest is RollupBase {
864864
end: _end,
865865
args: args,
866866
fees: fees,
867-
attestations: CommitteeAttestations({signatureIndices: "", signaturesOrAddresses: ""}), // TODO(palla): Add unit tests with non-empty attestations
867+
attestations: CommitteeAttestations({signatureIndices: "", signaturesOrAddresses: ""}),
868868
blobInputs: _blobInputs,
869869
proof: ""
870870
})

yarn-project/ethereum/src/contracts/rollup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export class RollupContract {
405405
await this.client.simulateContract({
406406
address: this.address,
407407
abi: RollupAbi,
408-
functionName: 'validateHeader',
408+
functionName: 'validateHeaderWithAttestations',
409409
args,
410410
account,
411411
});

yarn-project/sequencer-client/src/publisher/sequencer-publisher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export class SequencerPublisher {
344344
await this.l1TxUtils.simulate(
345345
{
346346
to: this.rollupContract.address,
347-
data: encodeFunctionData({ abi: RollupAbi, functionName: 'validateHeader', args }),
347+
data: encodeFunctionData({ abi: RollupAbi, functionName: 'validateHeaderWithAttestations', args }),
348348
from: MULTI_CALL_3_ADDRESS,
349349
},
350350
{

0 commit comments

Comments
 (0)