-
Notifications
You must be signed in to change notification settings - Fork 389
Enforce progressive-list soft limits at network decode time #11263
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
tbenr
wants to merge
1
commit into
Consensys-Incorporated:master
Choose a base branch
from
tbenr:Enforce-progressive-list-soft-limits-at-network-decode-time
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.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,11 @@ | |
| package tech.pegasys.teku.spec.datastructures.blocks; | ||
|
|
||
| import it.unimi.dsi.fastutil.longs.LongList; | ||
| import java.util.Optional; | ||
| import java.util.OptionalLong; | ||
| import tech.pegasys.teku.bls.BLSSignature; | ||
| import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2; | ||
| import tech.pegasys.teku.infrastructure.ssz.schema.SszNetworkValidator; | ||
| import tech.pegasys.teku.infrastructure.ssz.tree.GIndexUtil; | ||
| import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; | ||
| import tech.pegasys.teku.spec.datastructures.type.SszSignature; | ||
|
|
@@ -27,21 +29,24 @@ public class SignedBeaconBlockSchema | |
| implements SignedBlockContainerSchema<SignedBeaconBlock> { | ||
|
|
||
| private final OptionalLong networkSszLengthBytesUpperBound; | ||
| private final Optional<SszNetworkValidator<SignedBeaconBlock>> networkSszValidator; | ||
|
|
||
| public SignedBeaconBlockSchema( | ||
| final BeaconBlockSchema beaconBlockSchema, final String containerName) { | ||
| this(beaconBlockSchema, containerName, OptionalLong.empty()); | ||
| this(beaconBlockSchema, containerName, OptionalLong.empty(), Optional.empty()); | ||
| } | ||
|
|
||
| public SignedBeaconBlockSchema( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add Javadocs to different constructors, something like validation required starting from Gloas or smth like that |
||
| final BeaconBlockSchema beaconBlockSchema, | ||
| final String containerName, | ||
| final OptionalLong networkSszLengthBytesUpperBound) { | ||
| final OptionalLong networkSszLengthBytesUpperBound, | ||
| final Optional<SszNetworkValidator<SignedBeaconBlock>> networkSszValidator) { | ||
| super( | ||
| containerName, | ||
| namedSchema(SignedBeaconBlockFields.MESSAGE, beaconBlockSchema), | ||
| namedSchema(SignedBeaconBlockFields.SIGNATURE, SszSignatureSchema.INSTANCE)); | ||
| this.networkSszLengthBytesUpperBound = networkSszLengthBytesUpperBound; | ||
| this.networkSszValidator = networkSszValidator; | ||
| validateNetworkSszLengthBytesUpperBound(); | ||
| } | ||
|
|
||
|
|
@@ -50,6 +55,11 @@ public OptionalLong getNetworkSszLengthBytesUpperBound() { | |
| return networkSszLengthBytesUpperBound; | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<SszNetworkValidator<SignedBeaconBlock>> getNetworkSszValidator() { | ||
| return networkSszValidator; | ||
| } | ||
|
|
||
| public SignedBeaconBlock create(final BeaconBlock message, final BLSSignature signature) { | ||
| return new SignedBeaconBlock(this, message, signature); | ||
| } | ||
|
|
||
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
194 changes: 194 additions & 0 deletions
194
...eum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/util/GloasNetworkLimits.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,194 @@ | ||
| /* | ||
| * 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.spec.datastructures.util; | ||
|
|
||
| import java.util.Optional; | ||
| import tech.pegasys.teku.infrastructure.ssz.schema.SszNetworkValidator; | ||
| import tech.pegasys.teku.infrastructure.ssz.sos.SszDeserializeException; | ||
| import tech.pegasys.teku.spec.config.SpecConfigGloas; | ||
| import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; | ||
| import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.gloas.BeaconBlockBodyGloas; | ||
| import tech.pegasys.teku.spec.datastructures.epbs.versions.gloas.ExecutionPayloadEnvelope; | ||
| import tech.pegasys.teku.spec.datastructures.epbs.versions.gloas.SignedExecutionPayloadEnvelope; | ||
| import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload; | ||
| import tech.pegasys.teku.spec.datastructures.execution.versions.capella.ExecutionPayloadCapella; | ||
| import tech.pegasys.teku.spec.datastructures.execution.versions.gloas.ExecutionRequestsGloas; | ||
|
|
||
| /** | ||
| * Count limits that Gloas no longer expresses in SSZ (EIP-7688 progressive lists) and that the spec | ||
| * allows to be enforced when deserializing network messages. Shared by the network decoders | ||
| * (through the wire-level schema validators) and by the gossip validators, which also see locally | ||
| * published messages that never crossed the wire. | ||
| */ | ||
| public final class GloasNetworkLimits { | ||
|
|
||
| /** Subject used in violation messages for a block's {@code parent_execution_requests}. */ | ||
| public static final String PARENT_EXECUTION_REQUESTS_SUBJECT = "Parent execution requests"; | ||
|
|
||
| /** Subject used in violation messages for an execution payload envelope. */ | ||
| public static final String EXECUTION_PAYLOAD_ENVELOPE_SUBJECT = "Execution payload envelope"; | ||
|
|
||
| private GloasNetworkLimits() {} | ||
|
|
||
| /** | ||
| * Validator for blocks decoded from the network: spec {@code verify_block_body_operation_limits} | ||
| * and {@code verify_execution_requests_limits} on the parent execution requests. | ||
| */ | ||
| public static SszNetworkValidator<SignedBeaconBlock> signedBeaconBlockNetworkValidator( | ||
| final SpecConfigGloas config) { | ||
| return block -> { | ||
| final BeaconBlockBodyGloas body = BeaconBlockBodyGloas.required(block.getMessage().getBody()); | ||
| verifyBlockBodyOperationLimits(body, config) | ||
| .or( | ||
| () -> | ||
| verifyExecutionRequestsLimits( | ||
| PARENT_EXECUTION_REQUESTS_SUBJECT, | ||
| ExecutionRequestsGloas.required(body.getParentExecutionRequests()), | ||
| config)) | ||
| .ifPresent(GloasNetworkLimits::rejectDecoded); | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Validator for execution payload envelopes decoded from the network: the execution request and | ||
| * withdrawal count limits of {@code validate_execution_payload_envelope_gossip}. | ||
| */ | ||
| public static SszNetworkValidator<SignedExecutionPayloadEnvelope> | ||
| signedExecutionPayloadEnvelopeNetworkValidator(final SpecConfigGloas config) { | ||
| return signedEnvelope -> { | ||
| final ExecutionPayloadEnvelope envelope = signedEnvelope.getMessage(); | ||
| verifyExecutionRequestsLimits( | ||
| EXECUTION_PAYLOAD_ENVELOPE_SUBJECT, | ||
| ExecutionRequestsGloas.required(envelope.getExecutionRequests()), | ||
| config) | ||
| .or( | ||
| () -> | ||
| verifyWithdrawalsLimit( | ||
| EXECUTION_PAYLOAD_ENVELOPE_SUBJECT, envelope.getPayload(), config)) | ||
| .ifPresent(GloasNetworkLimits::rejectDecoded); | ||
| }; | ||
| } | ||
|
|
||
| private static void rejectDecoded(final LimitViolation violation) { | ||
| throw new SszDeserializeException(violation.describe()); | ||
| } | ||
|
|
||
| /** The first count that exceeds its limit. A zero limit means the list must be empty. */ | ||
| public record LimitViolation(String subject, String description, int count, int limit) { | ||
| public String describe() { | ||
| if (limit == 0) { | ||
| return String.format("%s must not contain %s, found %d", subject, description, count); | ||
| } | ||
| return String.format("%s has %d %s, max allowed %d", subject, count, description, limit); | ||
| } | ||
| } | ||
|
|
||
| /** Spec {@code verify_block_body_operation_limits}. */ | ||
| public static Optional<LimitViolation> verifyBlockBodyOperationLimits( | ||
| final BeaconBlockBodyGloas body, final SpecConfigGloas config) { | ||
| final String subject = "Block"; | ||
| return check( | ||
| subject, | ||
| "proposer slashings", | ||
| body.getProposerSlashings().size(), | ||
| config.getMaxProposerSlashings()) | ||
| .or( | ||
| () -> | ||
| check( | ||
| subject, | ||
| "attester slashings", | ||
| body.getAttesterSlashings().size(), | ||
| config.getMaxAttesterSlashingsElectra())) | ||
| .or( | ||
| () -> | ||
| check( | ||
| subject, | ||
| "attestations", | ||
| body.getAttestations().size(), | ||
| config.getMaxAttestationsElectra())) | ||
| .or(() -> check(subject, "deposits", body.getDeposits().size(), 0)) | ||
| .or( | ||
| () -> | ||
| check( | ||
| subject, | ||
| "voluntary exits", | ||
| body.getVoluntaryExits().size(), | ||
| config.getMaxVoluntaryExits())) | ||
| .or( | ||
| () -> | ||
| check( | ||
| subject, | ||
| "bls to execution changes", | ||
| body.getBlsToExecutionChanges().size(), | ||
| config.getMaxBlsToExecutionChanges())) | ||
| .or( | ||
| () -> | ||
| check( | ||
| subject, | ||
| "payload attestations", | ||
| body.getPayloadAttestations().size(), | ||
| config.getMaxPayloadAttestations())); | ||
| } | ||
|
|
||
| /** Spec {@code verify_execution_requests_limits}. Deposit requests have no Gloas limit. */ | ||
| public static Optional<LimitViolation> verifyExecutionRequestsLimits( | ||
| final String subject, final ExecutionRequestsGloas requests, final SpecConfigGloas config) { | ||
| return check( | ||
| subject, | ||
| "withdrawal requests", | ||
| requests.getWithdrawals().size(), | ||
| config.getMaxWithdrawalRequestsPerPayload()) | ||
| .or( | ||
| () -> | ||
| check( | ||
| subject, | ||
| "consolidation requests", | ||
| requests.getConsolidations().size(), | ||
| config.getMaxConsolidationRequestsPerPayload())) | ||
| .or( | ||
| () -> | ||
| check( | ||
| subject, | ||
| "builder deposit requests", | ||
| requests.getBuilderDeposits().size(), | ||
| config.getMaxBuilderDepositRequestsPerPayload())) | ||
| .or( | ||
| () -> | ||
| check( | ||
| subject, | ||
| "builder exit requests", | ||
| requests.getBuilderExits().size(), | ||
| config.getMaxBuilderExitRequestsPerPayload())); | ||
| } | ||
|
|
||
| /** | ||
| * The {@code MAX_WITHDRAWALS_PER_PAYLOAD} rule of {@code | ||
| * validate_execution_payload_envelope_gossip}. | ||
| */ | ||
| public static Optional<LimitViolation> verifyWithdrawalsLimit( | ||
| final String subject, final ExecutionPayload payload, final SpecConfigGloas config) { | ||
| return check( | ||
| subject, | ||
| "withdrawals", | ||
| ExecutionPayloadCapella.required(payload).getWithdrawals().size(), | ||
| config.getMaxWithdrawalsPerPayload()); | ||
| } | ||
|
|
||
| private static Optional<LimitViolation> check( | ||
| final String subject, final String description, final int count, final int limit) { | ||
| return count > limit | ||
| ? Optional.of(new LimitViolation(subject, description, count, limit)) | ||
| : Optional.empty(); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now any
MalformedDataExceptioncauses up to 12 hours peer ban which includes for exampleMessageTruncatedException. I'd carefully review list affected exception and also add JavaDoc tomarkAsInvalid()so everyone knows which kind of penalty is it.