@@ -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)
0 commit comments