mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-16 16:38:07 +00:00
Add nim-kzg4844 and use it in validate_blobs (#4732)
This commit is contained in:
parent
fc1f9a2065
commit
635a924e8c
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -203,3 +203,6 @@
|
|||||||
[submodule "vendor/withdrawals-testnets"]
|
[submodule "vendor/withdrawals-testnets"]
|
||||||
path = vendor/withdrawals-testnets
|
path = vendor/withdrawals-testnets
|
||||||
url = https://github.com/ethpandaops/withdrawals-testnet.git
|
url = https://github.com/ethpandaops/withdrawals-testnet.git
|
||||||
|
[submodule "vendor/nim-kzg4844"]
|
||||||
|
path = vendor/nim-kzg4844
|
||||||
|
url = https://github.com/status-im/nim-kzg4844/
|
||||||
|
@ -26,7 +26,6 @@ from ../consensus_object_pools/block_quarantine import
|
|||||||
from ../validators/validator_monitor import
|
from ../validators/validator_monitor import
|
||||||
MsgSource, ValidatorMonitor, registerAttestationInBlock, registerBeaconBlock,
|
MsgSource, ValidatorMonitor, registerAttestationInBlock, registerBeaconBlock,
|
||||||
registerSyncAggregateInBlock
|
registerSyncAggregateInBlock
|
||||||
from ../spec/state_transition_block import validate_blobs_sidecar
|
|
||||||
|
|
||||||
export sszdump, signatures_batch
|
export sszdump, signatures_batch
|
||||||
|
|
||||||
|
@ -24,7 +24,9 @@ import
|
|||||||
../digest,
|
../digest,
|
||||||
"."/[base, phase0, altair, bellatrix, capella]
|
"."/[base, phase0, altair, bellatrix, capella]
|
||||||
|
|
||||||
export json_serialization, base
|
from ../../vendor/nim-kzg4844/kzg4844 import KZGCommitment, KZGProof
|
||||||
|
|
||||||
|
export json_serialization, base, kzg4844
|
||||||
|
|
||||||
const
|
const
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/deneb/polynomial-commitments.md#constants
|
# 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
|
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS* = 4096'u64
|
||||||
|
|
||||||
type
|
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]
|
KZGCommitments* = List[KZGCommitment, Limit MAX_BLOBS_PER_BLOCK]
|
||||||
Blobs* = List[Blob, Limit MAX_BLOBS_PER_BLOCK]
|
Blobs* = List[Blob, Limit MAX_BLOBS_PER_BLOCK]
|
||||||
|
|
||||||
|
@ -22,8 +22,9 @@
|
|||||||
import
|
import
|
||||||
chronicles, metrics,
|
chronicles, metrics,
|
||||||
../extras,
|
../extras,
|
||||||
./datatypes/[phase0, altair, bellatrix],
|
./datatypes/[phase0, altair, bellatrix, deneb],
|
||||||
"."/[beaconstate, eth2_merkleization, helpers, validator, signatures]
|
"."/[beaconstate, eth2_merkleization, helpers, validator, signatures],
|
||||||
|
kzg4844/kzg_abi, kzg4844/kzg_ex
|
||||||
|
|
||||||
from std/algorithm import fill, sorted
|
from std/algorithm import fill, sorted
|
||||||
from std/sequtils import count, filterIt, mapIt
|
from std/sequtils import count, filterIt, mapIt
|
||||||
@ -751,23 +752,19 @@ func process_blob_kzg_commitments(
|
|||||||
else:
|
else:
|
||||||
return err("process_blob_kzg_commitments: verify_kzg_commitments_against_transactions failed")
|
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
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/deneb/fork-choice.md#validate_blobs
|
||||||
proc validate_blobs_sidecar*(slot: Slot, root: Eth2Digest,
|
proc validate_blobs*(expected_kzg_commitments: seq[KZGCommitment],
|
||||||
expected_kzg_commitments: seq[deneb.KZGCommitment],
|
blobs: seq[KzgBlob],
|
||||||
blobs_sidecar: deneb.BlobsSidecar):
|
proofs: seq[KZGProof]):
|
||||||
Result[void, cstring] =
|
Result[void, cstring] =
|
||||||
if slot != blobs_sidecar.beacon_block_slot:
|
if expected_kzg_commitments.len != blobs.len:
|
||||||
return err("validate_blobs_sidecar: different slot in block and sidecar")
|
return err("validate_blobs: different commitment and blob lengths")
|
||||||
|
|
||||||
if root != blobs_sidecar.beacon_block_root:
|
if proofs.len != blobs.len:
|
||||||
return err("validate_blobs_sidecar: different root in block and sidecar")
|
return err("validate_blobs: different proof and blob lengths")
|
||||||
|
|
||||||
if expected_kzg_commitments.len != blobs_sidecar.blobs.len:
|
if verifyProofs(blobs, expected_kzg_commitments, proofs).isErr():
|
||||||
return err("validate_blobs_sidecar: different commitment lengths")
|
return err("validate_blobs: proof verification failed")
|
||||||
|
|
||||||
# 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")
|
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
|
@ -193,6 +193,9 @@ switch("hint", "XCannotRaiseY:off")
|
|||||||
# Useful for Chronos metrics.
|
# Useful for Chronos metrics.
|
||||||
#--define:chronosFutureTracking
|
#--define:chronosFutureTracking
|
||||||
|
|
||||||
|
--define:kzgExternalBlst
|
||||||
|
--define:kzgExternalBlstNoSha256
|
||||||
|
|
||||||
# ############################################################
|
# ############################################################
|
||||||
#
|
#
|
||||||
# No LTO for crypto
|
# No LTO for crypto
|
||||||
|
1
vendor/nim-kzg4844
vendored
Submodule
1
vendor/nim-kzg4844
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 95978add33f743efcd46725c38fc074d96f7b5fb
|
Loading…
x
Reference in New Issue
Block a user