Skip to content

Commit 20ad05d

Browse files
author
AztecBot
committed
Merge branch 'next' into merge-train/barretenberg
2 parents 4c1b16f + e162028 commit 20ad05d

File tree

6 files changed

+24
-143
lines changed

6 files changed

+24
-143
lines changed

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

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -129,49 +129,6 @@ library AttestationLib {
129129
return addr;
130130
}
131131

132-
/**
133-
* @notice Assert that the size of `_attestations` is as expected, throw otherwise
134-
*
135-
* @custom:reverts SignatureIndicesSizeMismatch if the signature indices have a wrong size
136-
* @custom:reverts SignaturesOrAddressesSizeMismatch if the signatures or addresses object has wrong size
137-
*
138-
* @param _attestations - The attestation struct
139-
* @param _expectedCount - The expected size of the validator set
140-
*/
141-
function assertSizes(CommitteeAttestations memory _attestations, uint256 _expectedCount) internal pure {
142-
// Count signatures (1s) and addresses (0s) from bitmap
143-
uint256 signatureCount = 0;
144-
uint256 addressCount = 0;
145-
uint256 bitmapBytes = (_expectedCount + 7) / 8; // Round up to nearest byte
146-
require(
147-
bitmapBytes == _attestations.signatureIndices.length,
148-
Errors.AttestationLib__SignatureIndicesSizeMismatch(bitmapBytes, _attestations.signatureIndices.length)
149-
);
150-
151-
for (uint256 i = 0; i < _expectedCount; i++) {
152-
uint256 byteIndex = i / 8;
153-
uint256 bitIndex = 7 - (i % 8);
154-
uint8 bitMask = uint8(1 << bitIndex);
155-
156-
if (uint8(_attestations.signatureIndices[byteIndex]) & bitMask != 0) {
157-
signatureCount++;
158-
} else {
159-
addressCount++;
160-
}
161-
}
162-
163-
// Calculate expected size
164-
uint256 sizeOfSignaturesAndAddresses = (signatureCount * SIGNATURE_LENGTH) + (addressCount * ADDRESS_LENGTH);
165-
166-
// Validate actual size matches expected
167-
require(
168-
sizeOfSignaturesAndAddresses == _attestations.signaturesOrAddresses.length,
169-
Errors.AttestationLib__SignaturesOrAddressesSizeMismatch(
170-
sizeOfSignaturesAndAddresses, _attestations.signaturesOrAddresses.length
171-
)
172-
);
173-
}
174-
175132
/**
176133
* Recovers the committee from the addresses in the attestations and signers.
177134
*

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,13 @@ library ProposeLib {
237237
{
238238
// Verify that the proposer is the correct one for this slot by checking their signature in the attestations
239239
ValidatorSelectionLib.verifyProposer(
240-
v.header.slotNumber, v.currentEpoch, _attestations, _signers, v.payloadDigest, _attestationsAndSignersSignature
240+
v.header.slotNumber,
241+
v.currentEpoch,
242+
_attestations,
243+
_signers,
244+
v.payloadDigest,
245+
_attestationsAndSignersSignature,
246+
true
241247
);
242248
}
243249

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ library RollupOperationsExtLib {
5353
Epoch epoch = slot.epochFromSlot();
5454
ValidatorSelectionLib.verifyAttestations(slot, epoch, _attestations, _args.digest);
5555
ValidatorSelectionLib.verifyProposer(
56-
slot, epoch, _attestations, _signers, _args.digest, _attestationsAndSignersSignature
56+
slot, epoch, _attestations, _signers, _args.digest, _attestationsAndSignersSignature, false
5757
);
5858
}
5959

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ library ValidatorSelectionLib {
193193
* to recover them from their attestations' signatures (and hence save gas). The addresses of the non-signing
194194
* committee members are directly included in the attestations.
195195
* @param _digest The digest of the block being proposed
196+
* @param _updateCache Flag to identify that the proposer should be written to transient cache.
196197
* @custom:reverts Errors.ValidatorSelection__InvalidCommitteeCommitment if reconstructed committee doesn't match
197198
* stored commitment
198199
* @custom:reverts Errors.ValidatorSelection__MissingProposerSignature if proposer hasn't signed their attestation
@@ -204,13 +205,13 @@ library ValidatorSelectionLib {
204205
CommitteeAttestations memory _attestations,
205206
address[] memory _signers,
206207
bytes32 _digest,
207-
Signature memory _attestationsAndSignersSignature
208+
Signature memory _attestationsAndSignersSignature,
209+
bool _updateCache
208210
) internal {
209-
// Try load the proposer from cache
210-
(address proposer, uint256 proposerIndex) = getCachedProposer(_slot);
211+
uint256 proposerIndex;
212+
address proposer;
211213

212-
// If not in cache, grab from the committee, reconstructed from the attestations and signers
213-
if (proposer == address(0)) {
214+
{
214215
// Load the committee commitment for the epoch
215216
(bytes32 committeeCommitment, uint256 committeeSize) = getCommitteeCommitmentAt(_epochNumber);
216217

@@ -234,12 +235,6 @@ library ValidatorSelectionLib {
234235
uint256 sampleSeed = getSampleSeed(_epochNumber);
235236
proposerIndex = computeProposerIndex(_epochNumber, _slot, sampleSeed, committeeSize);
236237
proposer = committee[proposerIndex];
237-
238-
setCachedProposer(_slot, proposer, proposerIndex);
239-
} else {
240-
// Assert that the size of the attestations is as expected, to avoid memory abuse on sizes.
241-
// These checks are also performed inside `reconstructCommitteeFromSigners`.
242-
_attestations.assertSizes(getStorage().targetCommitteeSize);
243238
}
244239

245240
// We check that the proposer agrees with the proposal by checking that he attested to it. If we fail to get
@@ -259,6 +254,10 @@ library ValidatorSelectionLib {
259254
bytes32 attestationsAndSignersDigest =
260255
_attestations.getAttestationsAndSignersDigest(_signers).toEthSignedMessageHash();
261256
SignatureLib.verify(_attestationsAndSignersSignature, proposer, attestationsAndSignersDigest);
257+
258+
if (_updateCache) {
259+
setCachedProposer(_slot, proposer, proposerIndex);
260+
}
262261
}
263262

264263
/**
@@ -349,8 +348,6 @@ library ValidatorSelectionLib {
349348
}
350349
}
351350

352-
address proposer = stack.reconstructedCommittee[stack.proposerIndex];
353-
354351
require(
355352
stack.signaturesRecovered >= stack.needed,
356353
Errors.ValidatorSelection__InsufficientAttestations(stack.needed, stack.signaturesRecovered)
@@ -361,8 +358,6 @@ library ValidatorSelectionLib {
361358
if (reconstructedCommitment != committeeCommitment) {
362359
revert Errors.ValidatorSelection__InvalidCommitteeCommitment(reconstructedCommitment, committeeCommitment);
363360
}
364-
365-
setCachedProposer(_slot, proposer, stack.proposerIndex);
366361
}
367362

368363
/**

l1-contracts/test/AttestationLib.t.sol

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ contract AttestationLibWrapper {
1717
return AttestationLib.isEmpty(_attestations);
1818
}
1919

20-
function assertSizes(CommitteeAttestations memory _attestations, uint256 _expectedCount) external pure {
21-
AttestationLib.assertSizes(_attestations, _expectedCount);
22-
}
23-
2420
function reconstructCommitteeFromSigners(
2521
CommitteeAttestations memory _attestations,
2622
address[] memory _signers,
@@ -78,52 +74,6 @@ contract AttestationLibTest is TestBase {
7874
_;
7975
}
8076

81-
function test_assertSizes(uint256 _signatureCount) public createValidAttestations(_signatureCount) {
82-
attestationLibWrapper.assertSizes($attestations, SIZE);
83-
}
84-
85-
function test_assertSizes_wrongBitmapSize(uint256 _signatureCount, bool _over)
86-
public
87-
createValidAttestations(_signatureCount)
88-
{
89-
uint256 bitmapSize = $attestations.signatureIndices.length;
90-
if (_over) {
91-
$attestations.signatureIndices = new bytes(bitmapSize + 1);
92-
} else {
93-
$attestations.signatureIndices = new bytes(bitmapSize - 1);
94-
}
95-
96-
vm.expectRevert(
97-
abi.encodeWithSelector(
98-
Errors.AttestationLib__SignatureIndicesSizeMismatch.selector, bitmapSize, $attestations.signatureIndices.length
99-
)
100-
);
101-
102-
attestationLibWrapper.assertSizes($attestations, SIZE);
103-
}
104-
105-
function test_assertSizes_wrongSignaturesOrAddressesSize(uint256 _signatureCount, bool _over)
106-
public
107-
createValidAttestations(_signatureCount)
108-
{
109-
uint256 dataSize = $attestations.signaturesOrAddresses.length;
110-
if (_over) {
111-
$attestations.signaturesOrAddresses = new bytes(dataSize + 1);
112-
} else {
113-
$attestations.signaturesOrAddresses = new bytes(dataSize - 1);
114-
}
115-
116-
vm.expectRevert(
117-
abi.encodeWithSelector(
118-
Errors.AttestationLib__SignaturesOrAddressesSizeMismatch.selector,
119-
dataSize,
120-
$attestations.signaturesOrAddresses.length
121-
)
122-
);
123-
124-
attestationLibWrapper.assertSizes($attestations, SIZE);
125-
}
126-
12777
function test_reconstructCommitteeFromSigners(uint256 _signatureCount)
12878
public
12979
createValidAttestations(_signatureCount)

l1-contracts/test/validator-selection/ValidatorSelection.t.sol

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -374,24 +374,12 @@ contract ValidatorSelectionTest is ValidatorSelectionTestBase {
374374
}
375375

376376
function testInvalidAddressAttestation() public setup(4, 4) progressEpochs(2) {
377-
ProposeTestData memory ree =
378-
_testBlock("mixed_block_1", NO_REVERT, 3, 4, TestFlagsLib.empty().invalidateAddressAttestation());
379-
380-
// We try to invalidate the count, but it got sufficient, so tx should revert
381-
_invalidateByAttestationCount(ree, Errors.ValidatorSelection__InsufficientAttestations.selector);
382-
383-
// We now invalidate the wrong attestation, no revert
384-
// https://www.youtube.com/watch?v=glN0W8WogK8
385-
_invalidateByAttestationSig(ree, ree.invalidAddressAttestationIndex, NO_REVERT);
386-
387-
// Try to prove to show that it can explode at this point, and we could not do anything before it.
388-
// This should revert but won't if we did not invalidate
389-
_proveBlocks(
390-
"mixed_block_",
391-
1,
392-
1,
393-
AttestationLibHelper.packAttestations(ree.attestations),
394-
Errors.Rollup__InvalidBlockNumber.selector
377+
_testBlock(
378+
"mixed_block_1",
379+
Errors.ValidatorSelection__InvalidCommitteeCommitment.selector,
380+
3,
381+
4,
382+
TestFlagsLib.empty().invalidateAddressAttestation()
395383
);
396384
}
397385

@@ -592,8 +580,6 @@ contract ValidatorSelectionTest is ValidatorSelectionTestBase {
592580
}
593581
}
594582

595-
// @todo figure out the attestationsAndSignersSignature
596-
597583
if (_flags.senderIsNotProposer) {
598584
ree.sender = address(uint160(uint256(keccak256(abi.encode("invalid", ree.proposer)))));
599585
}
@@ -615,19 +601,6 @@ contract ValidatorSelectionTest is ValidatorSelectionTestBase {
615601
)
616602
).signature;
617603
}
618-
619-
// By using this function we end up caching the correct proposer so we can skip the check in the real submission
620-
// Only works in the same tx.
621-
rollup.validateHeaderWithAttestations(
622-
ree.proposeArgs.header,
623-
AttestationLibHelper.packAttestations(ree.attestations),
624-
ree.signers,
625-
ree.attestationsAndSignersSignature,
626-
digest,
627-
bytes32(0),
628-
BlockHeaderValidationFlags({ignoreDA: true})
629-
);
630-
631604
// Change the last element in the committee (since it don't need a sig as we have enough earlier)
632605
// to be a random address instead of the expected one.
633606
address invalidAddress = address(uint160(uint256(keccak256(abi.encode("invalid", block.timestamp)))));

0 commit comments

Comments
 (0)