-
Notifications
You must be signed in to change notification settings - Fork 389
Validate a bid coming from the Builder API (Gloas) #11260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
StefanBratanov
wants to merge
4
commits into
Consensys-Incorporated:master
Choose a base branch
from
StefanBratanov:bid_validation_builder
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+560
−18
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...sition/src/main/java/tech/pegasys/teku/statetransition/execution/BuilderBidValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /* | ||
| * Copyright Consensys Software Inc., 2026 | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package tech.pegasys.teku.statetransition.execution; | ||
|
|
||
| import java.util.Optional; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
| import tech.pegasys.teku.spec.Spec; | ||
| import tech.pegasys.teku.spec.SpecVersion; | ||
| import tech.pegasys.teku.spec.datastructures.epbs.versions.gloas.ExecutionPayloadBid; | ||
| import tech.pegasys.teku.spec.datastructures.epbs.versions.gloas.ProposerPreferences; | ||
| import tech.pegasys.teku.spec.datastructures.epbs.versions.gloas.SignedExecutionPayloadBid; | ||
| import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; | ||
| import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.gloas.BeaconStateGloas; | ||
| import tech.pegasys.teku.spec.logic.versions.gloas.helpers.BeaconStateAccessorsGloas; | ||
| import tech.pegasys.teku.spec.logic.versions.gloas.helpers.PredicatesGloas; | ||
| import tech.pegasys.teku.statetransition.validation.ExecutionPayloadBidGossipValidator; | ||
|
|
||
| public class BuilderBidValidator { | ||
|
|
||
| private static final Logger LOG = LogManager.getLogger(); | ||
|
|
||
| private final Spec spec; | ||
| private final ProposerPreferencesManager proposerPreferencesManager; | ||
|
|
||
| public BuilderBidValidator( | ||
| final Spec spec, final ProposerPreferencesManager proposerPreferencesManager) { | ||
| this.spec = spec; | ||
| this.proposerPreferencesManager = proposerPreferencesManager; | ||
| } | ||
|
|
||
| /** | ||
| * Validates a bid coming from the Builder API | ||
| * | ||
| * <p><a | ||
| * href="https://github.com/ethereum/builder-specs/blob/main/specs/gloas/validator.md#validating-a-signedexecutionpayloadbid">Validating | ||
| * a SignedExecutionPayloadBid</a> | ||
| * | ||
| * @param signedBid the signed bid to validate | ||
| * @param state the current beacon state | ||
| * @return true if the bid is valid, false otherwise | ||
| */ | ||
| public boolean validateBid(final SignedExecutionPayloadBid signedBid, final BeaconState state) { | ||
| final ExecutionPayloadBid bid = signedBid.getMessage(); | ||
| final UInt64 slot = bid.getSlot(); | ||
| final SpecVersion specVersion = spec.atSlot(slot); | ||
|
|
||
| final PredicatesGloas predicates = PredicatesGloas.required(specVersion.predicates()); | ||
| final BeaconStateAccessorsGloas beaconStateAccessors = | ||
| BeaconStateAccessorsGloas.required(specVersion.beaconStateAccessors()); | ||
| final BeaconStateGloas stateGloas = BeaconStateGloas.required(state); | ||
|
|
||
| if (!predicates.isActiveBuilder(state, bid.getBuilderIndex())) { | ||
| LOG.warn("Bid rejected: builder {} is not active", bid.getBuilderIndex()); | ||
| return false; | ||
| } | ||
|
|
||
| if (!slot.equals(state.getSlot())) { | ||
| LOG.warn("Bid rejected: bid slot {} does not match state slot {}", slot, state.getSlot()); | ||
| return false; | ||
| } | ||
|
|
||
| if (!bid.getParentBlockHash().equals(stateGloas.getLatestExecutionPayloadBid().getBlockHash()) | ||
| && !bid.getParentBlockHash().equals(stateGloas.getLatestBlockHash())) { | ||
| LOG.warn("Bid rejected: parent block hash does not extend a known parent"); | ||
| return false; | ||
| } | ||
|
|
||
| if (!bid.getParentBlockRoot().equals(state.getLatestBlockHeader().hashTreeRoot())) { | ||
| LOG.warn("Bid rejected: parent block root mismatch"); | ||
| return false; | ||
| } | ||
|
|
||
| if (!bid.getPrevRandao() | ||
| .equals( | ||
| beaconStateAccessors.getRandaoMix( | ||
| state, beaconStateAccessors.getCurrentEpoch(state)))) { | ||
| LOG.warn("Bid rejected: prev_randao mismatch"); | ||
| return false; | ||
| } | ||
|
|
||
| final Optional<ProposerPreferences> proposerPreferences = | ||
| proposerPreferencesManager.getProposerPreferences(slot); | ||
|
|
||
| if (proposerPreferences.isPresent()) { | ||
| if (bid.getFeeRecipient().equals(proposerPreferences.get().getFeeRecipient())) { | ||
| LOG.warn("Bid rejected: fee recipient mismatch"); | ||
| return false; | ||
| } | ||
| final UInt64 parentGasLimit = stateGloas.getLatestExecutionPayloadBid().getGasLimit(); | ||
| if (!ExecutionPayloadBidGossipValidator.isGasLimitTargetCompatible( | ||
| parentGasLimit, bid.getGasLimit(), proposerPreferences.get().getTargetGasLimit())) { | ||
| LOG.warn("Bid rejected: gas limit {} is not compatible with target", bid.getGasLimit()); | ||
| return false; | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| if (bid.getValue().isGreaterThan(UInt64.ZERO) | ||
| && !beaconStateAccessors.canBuilderCoverBid(state, bid.getBuilderIndex(), bid.getValue())) { | ||
| LOG.warn("Bid rejected: builder {} cannot cover bid value", bid.getBuilderIndex()); | ||
| return false; | ||
| } | ||
|
|
||
| if (!specVersion | ||
| .operationSignatureVerifier() | ||
| .verifyExecutionPayloadBidSignature( | ||
| state, signedBid, specVersion.getConfig().getBLSSignatureVerifier())) { | ||
| LOG.debug("Bid rejected: invalid signature"); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.