Merge pull request #2540 from Nashatyrev/fix/datacommitment-length

[Sharding] Rename `DataCommitment.length` field to `samples_count` and fix `degree_proof` validation
This commit is contained in:
Diederik Loerakker 2021-08-11 17:03:30 +02:00 committed by GitHub
commit dd58c702d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -242,7 +242,7 @@ class DataCommitment(Container):
# KZG10 commitment to the data # KZG10 commitment to the data
point: BLSCommitment point: BLSCommitment
# Length of the data in samples # Length of the data in samples
length: uint64 samples_count: uint64
``` ```
### `AttestedDataCommitment` ### `AttestedDataCommitment`
@ -266,7 +266,7 @@ Unique, signing different bodies as shard proposer for the same `(slot, shard)`
class ShardBlobBody(Container): class ShardBlobBody(Container):
# The actual data commitment # The actual data commitment
commitment: DataCommitment commitment: DataCommitment
# Proof that the degree < commitment.length # Proof that the degree < commitment.samples_count * POINTS_PER_SAMPLE
degree_proof: BLSCommitment degree_proof: BLSCommitment
# The actual data. Should match the commitment and degree proof. # The actual data. Should match the commitment and degree proof.
data: List[BLSPoint, POINTS_PER_SAMPLE * MAX_SAMPLES_PER_BLOB] data: List[BLSPoint, POINTS_PER_SAMPLE * MAX_SAMPLES_PER_BLOB]
@ -289,7 +289,7 @@ to avoid an extra network roundtrip between proposer and builder, to include the
class ShardBlobBodySummary(Container): class ShardBlobBodySummary(Container):
# The actual data commitment # The actual data commitment
commitment: DataCommitment commitment: DataCommitment
# Proof that the degree < commitment.length # Proof that the degree < commitment.samples_count * POINTS_PER_SAMPLE
degree_proof: BLSCommitment degree_proof: BLSCommitment
# Hash-tree-root as summary of the data field # Hash-tree-root as summary of the data field
data_root: Root data_root: Root
@ -719,16 +719,17 @@ def process_shard_header(state: BeaconState, signed_header: SignedShardBlobHeade
# Verify the length by verifying the degree. # Verify the length by verifying the degree.
body_summary = header.body_summary body_summary = header.body_summary
if body_summary.commitment.length == 0: points_count = body_summary.commitment.samples_count * POINTS_PER_SAMPLE
if points_count == 0:
assert body_summary.degree_proof == G1_SETUP[0] assert body_summary.degree_proof == G1_SETUP[0]
assert ( assert (
bls.Pairing(body_summary.degree_proof, G2_SETUP[0]) bls.Pairing(body_summary.degree_proof, G2_SETUP[0])
== bls.Pairing(body_summary.commitment.point, G2_SETUP[-body_summary.commitment.length]) == bls.Pairing(body_summary.commitment.point, G2_SETUP[-points_count])
) )
# Charge EIP 1559 fee, builder pays for opportunity, and is responsible for later availability, # Charge EIP 1559 fee, builder pays for opportunity, and is responsible for later availability,
# or fail to publish at their own expense. # or fail to publish at their own expense.
samples = body_summary.commitment.length samples = body_summary.commitment.samples_count
# TODO: overflows, need bigger int type # TODO: overflows, need bigger int type
max_fee = body_summary.max_fee_per_sample * samples max_fee = body_summary.max_fee_per_sample * samples