Add nim-kzg4844 and use it in validate_blobs (#4732)

This commit is contained in:
henridf 2023-03-23 10:47:04 +01:00 committed by GitHub
parent fc1f9a2065
commit 635a924e8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 24 deletions

3
.gitmodules vendored
View File

@ -203,3 +203,6 @@
[submodule "vendor/withdrawals-testnets"]
path = vendor/withdrawals-testnets
url = https://github.com/ethpandaops/withdrawals-testnet.git
[submodule "vendor/nim-kzg4844"]
path = vendor/nim-kzg4844
url = https://github.com/status-im/nim-kzg4844/

View File

@ -26,7 +26,6 @@ from ../consensus_object_pools/block_quarantine import
from ../validators/validator_monitor import
MsgSource, ValidatorMonitor, registerAttestationInBlock, registerBeaconBlock,
registerSyncAggregateInBlock
from ../spec/state_transition_block import validate_blobs_sidecar
export sszdump, signatures_batch

View File

@ -24,7 +24,9 @@ import
../digest,
"."/[base, phase0, altair, bellatrix, capella]
export json_serialization, base
from ../../vendor/nim-kzg4844/kzg4844 import KZGCommitment, KZGProof
export json_serialization, base, kzg4844
const
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/deneb/polynomial-commitments.md#constants
@ -39,11 +41,6 @@ const
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS* = 4096'u64
type
# this block belongs elsewhere - will figure out after implementing c-kzg bindings
KZGCommitment* = array[48, byte]
KZGProof* = array[48, byte]
BLSFieldElement* = array[32, byte]
KZGCommitments* = List[KZGCommitment, Limit MAX_BLOBS_PER_BLOCK]
Blobs* = List[Blob, Limit MAX_BLOBS_PER_BLOCK]

View File

@ -22,8 +22,9 @@
import
chronicles, metrics,
../extras,
./datatypes/[phase0, altair, bellatrix],
"."/[beaconstate, eth2_merkleization, helpers, validator, signatures]
./datatypes/[phase0, altair, bellatrix, deneb],
"."/[beaconstate, eth2_merkleization, helpers, validator, signatures],
kzg4844/kzg_abi, kzg4844/kzg_ex
from std/algorithm import fill, sorted
from std/sequtils import count, filterIt, mapIt
@ -751,23 +752,19 @@ func process_blob_kzg_commitments(
else:
return err("process_blob_kzg_commitments: verify_kzg_commitments_against_transactions failed")
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.2/specs/eip4844/beacon-chain.md#validate_blobs_sidecar
proc validate_blobs_sidecar*(slot: Slot, root: Eth2Digest,
expected_kzg_commitments: seq[deneb.KZGCommitment],
blobs_sidecar: deneb.BlobsSidecar):
Result[void, cstring] =
if slot != blobs_sidecar.beacon_block_slot:
return err("validate_blobs_sidecar: different slot in block and sidecar")
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/deneb/fork-choice.md#validate_blobs
proc validate_blobs*(expected_kzg_commitments: seq[KZGCommitment],
blobs: seq[KzgBlob],
proofs: seq[KZGProof]):
Result[void, cstring] =
if expected_kzg_commitments.len != blobs.len:
return err("validate_blobs: different commitment and blob lengths")
if root != blobs_sidecar.beacon_block_root:
return err("validate_blobs_sidecar: different root in block and sidecar")
if proofs.len != blobs.len:
return err("validate_blobs: different proof and blob lengths")
if expected_kzg_commitments.len != blobs_sidecar.blobs.len:
return err("validate_blobs_sidecar: different commitment lengths")
# TODO
# if not kzg_4844.verify_aggregate_kzg_proof(asSeq(blobs_sidecar.blobs), expected_kzg_commitments, blobs_sidecar.kzg_aggregated_proof):
# return err("validate_blobs_sidecar: aggregated kzg proof verification failed")
if verifyProofs(blobs, expected_kzg_commitments, proofs).isErr():
return err("validate_blobs: proof verification failed")
ok()

View File

@ -193,6 +193,9 @@ switch("hint", "XCannotRaiseY:off")
# Useful for Chronos metrics.
#--define:chronosFutureTracking
--define:kzgExternalBlst
--define:kzgExternalBlstNoSha256
# ############################################################
#
# No LTO for crypto

1
vendor/nim-kzg4844 vendored Submodule

@ -0,0 +1 @@
Subproject commit 95978add33f743efcd46725c38fc074d96f7b5fb