-
Notifications
You must be signed in to change notification settings - Fork 303
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
Improve isDataAvailable
checks
#7575
Changes from 1 commit
9de14bc
e516cea
c326d5e
7b454d0
e884f3e
21e46b3
bedcf74
9bae8a2
a1a15cb
a1086d2
bb5abbe
194f481
e9c8edb
2084294
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,10 @@ | |
import static com.google.common.base.Preconditions.checkArgument; | ||
import static tech.pegasys.teku.spec.config.SpecConfigDeneb.VERSIONED_HASH_VERSION_KZG; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.IntStream; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.infrastructure.crypto.Hash; | ||
|
@@ -65,26 +67,43 @@ private static KZG initKZG(final SpecConfigDeneb config) { | |
public boolean isDataAvailable( | ||
final UInt64 slot, | ||
final Bytes32 beaconBlockRoot, | ||
final List<KZGCommitment> kzgCommitments, | ||
final List<KZGCommitment> kzgCommitmentsFromBlock, | ||
final List<BlobSidecar> blobSidecars) { | ||
blobSidecars.forEach( | ||
blobSidecar -> { | ||
checkArgument( | ||
slot.equals(blobSidecar.getSlot()), | ||
"Blob sidecar slot %s does not match block slot %s", | ||
blobSidecar.getSlot(), | ||
slot); | ||
checkArgument( | ||
beaconBlockRoot.equals(blobSidecar.getBlockRoot()), | ||
"Blob sidecar block root %s does not match block root %s", | ||
blobSidecar.getBlockRoot(), | ||
beaconBlockRoot); | ||
}); | ||
final List<Bytes> blobs = | ||
blobSidecars.stream().map(BlobSidecar::getBlob).map(Blob::getBytes).toList(); | ||
final List<KZGProof> proofs = blobSidecars.stream().map(BlobSidecar::getKZGProof).toList(); | ||
|
||
return kzg.verifyBlobKzgProofBatch(blobs, kzgCommitments, proofs); | ||
checkArgument( | ||
blobSidecars.size() == kzgCommitmentsFromBlock.size(), | ||
"Blob sidecars count %s does not match KZG commitments count %s", | ||
blobSidecars.size(), | ||
kzgCommitmentsFromBlock.size()); | ||
|
||
final List<Bytes> blobs = new ArrayList<>(); | ||
final List<KZGProof> proofs = new ArrayList<>(); | ||
|
||
IntStream.range(0, blobSidecars.size()) | ||
.forEach( | ||
index -> { | ||
final BlobSidecar blobSidecar = blobSidecars.get(index); | ||
|
||
checkArgument( | ||
slot.equals(blobSidecar.getSlot()), | ||
"Blob sidecar slot %s does not match block slot %s", | ||
blobSidecar.getSlot(), | ||
slot); | ||
checkArgument( | ||
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. You could also add parent root check (but it will require changes in interface) 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. I started thinking that these checks could leave in the 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. thinking more about it, an early refetch might be undesirable here. If the proposer is doing something strange, is better to do nothing, skip the block import, vote on previous head, and then lookup only if next block builds on top of this (which might be not the case most times, unless next proposer is under control of the same malicious\buggy entity) 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. so 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. I decided to move the validation back to miscHelper but on a dedicated method. This simplified the tests in |
||
beaconBlockRoot.equals(blobSidecar.getBlockRoot()), | ||
"Blob sidecar block root %s does not match block root %s", | ||
blobSidecar.getBlockRoot(), | ||
beaconBlockRoot); | ||
checkArgument( | ||
kzgCommitmentsFromBlock.get(index).equals(blobSidecar.getKZGCommitment()), | ||
"Blob sidecar KZG commitment %s does not match block KZG commitment %s", | ||
blobSidecar.getKZGCommitment(), | ||
kzgCommitmentsFromBlock.get(index)); | ||
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. similar to above, adding slot at a minimum would be helpful |
||
|
||
blobs.add(blobSidecar.getBlob().getBytes()); | ||
proofs.add(blobSidecar.getKZGProof()); | ||
}); | ||
|
||
return kzg.verifyBlobKzgProofBatch(blobs, kzgCommitmentsFromBlock, proofs); | ||
} | ||
|
||
/** | ||
|
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.
maybe
match block KZG commitments
to be more clearThere 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.
would this be more helpful to report if we had the actual block slot or something associating it to the block in the message?
It'll be very hard for anyone to understand what this relates to because there's nothing tying it into data we can understand, so from the perspective of a node op, this will be a 'useless message' as it stands.
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.
right!