forked from Consensys/teku
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BlobSidecar by root RPC verification (Consensys#7645)
- Loading branch information
Showing
9 changed files
with
406 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 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
54 changes: 54 additions & 0 deletions
54
...tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarByRootValidator.java
This file contains 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,54 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.networking.eth2.rpc.beaconchain.methods; | ||
|
||
import static tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BlobSidecarsResponseInvalidResponseException.InvalidResponseType.BLOB_SIDECAR_KZG_VERIFICATION_FAILED; | ||
import static tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BlobSidecarsResponseInvalidResponseException.InvalidResponseType.BLOB_SIDECAR_UNEXPECTED_IDENTIFIER; | ||
|
||
import java.util.Set; | ||
import tech.pegasys.teku.kzg.KZG; | ||
import tech.pegasys.teku.networking.p2p.peer.Peer; | ||
import tech.pegasys.teku.spec.Spec; | ||
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; | ||
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BlobIdentifier; | ||
|
||
public class BlobSidecarByRootValidator extends AbstractBlobSidecarsValidator { | ||
|
||
private final Peer peer; | ||
private final Set<BlobIdentifier> expectedBlobIdentifiers; | ||
|
||
public BlobSidecarByRootValidator( | ||
final Peer peer, | ||
final Spec spec, | ||
final KZG kzg, | ||
final Set<BlobIdentifier> expectedBlobIdentifiers) { | ||
super(spec, kzg); | ||
this.peer = peer; | ||
this.expectedBlobIdentifiers = expectedBlobIdentifiers; | ||
} | ||
|
||
public void validateBlobSidecar(final BlobSidecar blobSidecar) { | ||
final BlobIdentifier blobIdentifier = | ||
new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()); | ||
if (!expectedBlobIdentifiers.contains(blobIdentifier)) { | ||
throw new BlobSidecarsResponseInvalidResponseException( | ||
peer, BLOB_SIDECAR_UNEXPECTED_IDENTIFIER); | ||
} | ||
|
||
if (!verifyBlobSidecarKzg(blobSidecar)) { | ||
throw new BlobSidecarsResponseInvalidResponseException( | ||
peer, BLOB_SIDECAR_KZG_VERIFICATION_FAILED); | ||
} | ||
} | ||
} |
This file contains 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
58 changes: 58 additions & 0 deletions
58
...ku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootListenerValidatingProxy.java
This file contains 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,58 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.networking.eth2.rpc.beaconchain.methods; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import tech.pegasys.teku.infrastructure.async.SafeFuture; | ||
import tech.pegasys.teku.kzg.KZG; | ||
import tech.pegasys.teku.networking.p2p.peer.Peer; | ||
import tech.pegasys.teku.networking.p2p.rpc.RpcResponseListener; | ||
import tech.pegasys.teku.spec.Spec; | ||
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; | ||
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BlobIdentifier; | ||
|
||
public class BlobSidecarsByRootListenerValidatingProxy implements RpcResponseListener<BlobSidecar> { | ||
|
||
private final Peer peer; | ||
private final Spec spec; | ||
private final RpcResponseListener<BlobSidecar> blobSidecarResponseListener; | ||
private final Set<BlobIdentifier> expectedBlobIdentifiers; | ||
private final KZG kzg; | ||
|
||
public BlobSidecarsByRootListenerValidatingProxy( | ||
final Peer peer, | ||
final Spec spec, | ||
final RpcResponseListener<BlobSidecar> blobSidecarResponseListener, | ||
final KZG kzg, | ||
final List<BlobIdentifier> expectedBlobIdentifiers) { | ||
this.peer = peer; | ||
this.spec = spec; | ||
this.blobSidecarResponseListener = blobSidecarResponseListener; | ||
this.kzg = kzg; | ||
this.expectedBlobIdentifiers = new HashSet<>(expectedBlobIdentifiers); | ||
} | ||
|
||
@Override | ||
public SafeFuture<?> onResponse(final BlobSidecar blobSidecar) { | ||
return SafeFuture.of( | ||
() -> { | ||
final BlobSidecarByRootValidator blobSidecarByRootValidator = | ||
new BlobSidecarByRootValidator(peer, spec, kzg, expectedBlobIdentifiers); | ||
blobSidecarByRootValidator.validateBlobSidecar(blobSidecar); | ||
return blobSidecarResponseListener.onResponse(blobSidecar); | ||
}); | ||
} | ||
} |
This file contains 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.