Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions beacon_chain/consensus_object_pools/blob_quarantine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ template hasSidecarImpl(
return false
true

template hasSidecarImpl(
blockRoot: Eth2Digest,
sidecarIndex: typed
): bool =
let rootRecord = quarantine.roots.getOrDefault(blockRoot)
if rootRecord.count == 0:
return false
let index = quarantine.getIndex(sidecarIndex)
(index != -1) and not rootRecord.sidecars[index].isEmpty()

func hasSidecar*(
quarantine: BlobQuarantine,
blockRoot: Eth2Digest,
Expand All @@ -423,6 +433,13 @@ func hasSidecar*(
## ``index``, ``slot`` and ``proposer_index``.
hasSidecarImpl(blockRoot, slot, proposer_index, index)

func hasSidecar*(
quarantine: ColumnQuarantine,
blockRoot: Eth2Digest,
index: ColumnIndex
): bool =
hasSidecarImpl(blockRoot, index)

func hasSidecars*(
quarantine: BlobQuarantine,
blockRoot: Eth2Digest,
Expand Down
40 changes: 35 additions & 5 deletions beacon_chain/gossip_processing/eth2_processor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ proc processBlobSidecar*(

proc processDataColumnSidecar*(
self: var Eth2Processor, src: MsgSource,
dataColumnSidecar: fulu.DataColumnSidecar | gloas.DataColumnSidecar,
dataColumnSidecar: fulu.DataColumnSidecar,
subnet_id: uint64): ValidationRes =
template block_header: untyped = dataColumnSidecar.signed_block_header.message
let
Expand Down Expand Up @@ -377,6 +377,38 @@ proc processDataColumnSidecar*(

v

proc processDataColumnSidecar*(
self: var Eth2Processor, src: MsgSource,
dataColumnSidecar: gloas.DataColumnSidecar,
subnet_id: uint64): ValidationRes =
let
block_root = dataColumnSidecar.beacon_block_root
wallTime = self.getCurrentBeaconTime()
(_, wallSlot) = wallTime.toSlot()

logScope:
dcs = shortLog(dataColumnSidecar)
wallSlot

debug "Data column received (Gloas - quarantine not implemented)"

let v = self.dag.validateDataColumnSidecar(
self.quarantine, self.dataColumnQuarantine,
dataColumnSidecar, wallTime, subnet_id)

if v.isErr():
debug "Dropping data column", error = v.error()
data_column_sidecars_dropped.inc(1, [$v.error[0]])
return v

debugGloasComment ""
# TODO: Implement quarantine logic for Gloas
# For now, just validate and drop
debug "Data column validated (not stored - quarantine TODO)"

data_column_sidecars_received.inc()
v

proc setupDoppelgangerDetection*(self: var Eth2Processor, slot: Slot) =
# When another client's already running, this is very likely to detect
# potential duplicate validators, which can trigger slashing.
Expand Down Expand Up @@ -446,10 +478,8 @@ proc processAttestation*(
await self.attestationPool.validateAttestation(
self.batchCrypto, attestation, wallTime, subnet_id, checkSignature)
else:
withConsensusFork(fork):
await self.attestationPool.validateAttestation(
self.batchCrypto, attestation, wallTime, subnet_id, checkSignature,
consensusFork)
await self.attestationPool.validateAttestation(
self.batchCrypto, attestation, wallTime, subnet_id, checkSignature, fork)

return if v.isOk():
# Due to async validation the wallTime here might have changed
Expand Down
58 changes: 57 additions & 1 deletion beacon_chain/gossip_processing/gossip_validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ func check_data_column_sidecar_inclusion_proof(
ok()

proc check_data_column_sidecar_kzg_proofs(
data_column_sidecar: fulu.DataColumnSidecar): Result[void, ValidationError] =
data_column_sidecar: fulu.DataColumnSidecar | gloas.DataColumnSidecar):
Result[void, ValidationError] =
let res = data_column_sidecar.verify_data_column_sidecar_kzg_proofs()
if res.isErr:
return errReject(res.error)
Expand Down Expand Up @@ -715,6 +716,61 @@ proc validateDataColumnSidecar*(

ok()

# https://github.com/ethereum/consensus-specs/blob/v1.6.0-beta.0/specs/gloas/p2p-interface.md#data_column_sidecar_subnet_id
proc validateDataColumnSidecar*(
dag: ChainDAGRef, quarantine: ref Quarantine,
dataColumnQuarantine: ref ColumnQuarantine,
data_column_sidecar: gloas.DataColumnSidecar,
wallTime: BeaconTime, subnet_id: uint64):
Result[void, ValidationError] =

# [REJECT] The sidecar is valid as verified by verify_data_column_sidecar
block:
let v = verify_data_column_sidecar(data_column_sidecar)
if v.isErr:
return dag.checkedReject(v.error)

# [REJECT] The sidecar is for the correct subnet
if not (compute_subnet_for_data_column_sidecar(data_column_sidecar.index) ==
subnet_id):
return dag.checkedReject("DataColumnSidecar: not for correct subnet")

# [IGNORE] Modified from Fulu: The sidecar is the first sidecar for the tuple
# (sidecar.beacon_block_root, sidecar.index) with valid kzg proof.
let block_root = data_column_sidecar.beacon_block_root
if dataColumnQuarantine[].hasSidecar(block_root, data_column_sidecar.index):
return errIgnore("DataColumnSidecar: already have valid data column")

debugGloasComment ""
# [IGNORE] The sidecar's beacon_block_root has been seen via a valid signed
# execution payload header (builder's bid).
#
# [REJECT] The hash of the sidecar's kzg_commitments matches the
# blob_kzg_commitments_root in the corresponding builder's bid for
# sidecar.beacon_block_root.
#
# TODO: Implement getExecutionPayloadBid(block_root)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks

# This requires storing bids received via execution_payload_bid gossip topic,
# indexed by the beacon block root they commit to.

# [REJECT] The sidecar's column data is valid
block:
let r = check_data_column_sidecar_kzg_proofs(data_column_sidecar)
if r.isErr:
return dag.checkedReject(r.error)

# Send notification about new data column sidecar via callback
let onDataColumnSidecarCallback =
dataColumnQuarantine[].onDataColumnSidecarCallback()

if not(isNil(onDataColumnSidecarCallback)):
onDataColumnSidecarCallback DataColumnSidecarInfoObject(
block_root: block_root,
index: data_column_sidecar.index,
kzg_commitments: data_column_sidecar.kzg_commitments)

ok()

# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/p2p-interface.md#beacon_block
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/p2p-interface.md#beacon_block
proc validateBeaconBlock*(
Expand Down
3 changes: 2 additions & 1 deletion beacon_chain/networking/eth2_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,8 @@ template gossipMaxSize(T: untyped): uint32 =
fixedPortionSize(T).uint32
elif T is bellatrix.SignedBeaconBlock or T is capella.SignedBeaconBlock or
T is deneb.SignedBeaconBlock or T is electra.SignedBeaconBlock or
T is fulu.SignedBeaconBlock or T is fulu.DataColumnSidecar:
T is fulu.SignedBeaconBlock or T is fulu.DataColumnSidecar or
T is gloas.DataColumnSidecar:
MAX_PAYLOAD_SIZE
# TODO https://github.com/status-im/nim-ssz-serialization/issues/20 for
# Attestation, AttesterSlashing, and SignedAggregateAndProof, which all
Expand Down
14 changes: 12 additions & 2 deletions beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2427,8 +2427,18 @@ proc installMessageValidators(node: BeaconNode) =
# https://github.com/ethereum/consensus-specs/blob/v1.6.0-alpha.3/specs/fulu/p2p-interface.md#data_column_sidecar_subnet_id
# https://github.com/ethereum/consensus-specs/blob/v1.6.0-beta.0/specs/gloas/p2p-interface.md#data_column_sidecar_subnet_id
when consensusFork >= ConsensusFork.Gloas:
debugGloasComment " "
elif consensusFork >= ConsensusFork.Fulu:
for it in 0'u64..<node.dag.cfg.NUMBER_OF_CUSTODY_GROUPS:
closureScope:
let subnet_id = it
node.network.addValidator(
getDataColumnSidecarTopic(digest, subnet_id), proc (
dataColumnSidecar: gloas.DataColumnSidecar,
src: PeerId
): ValidationResult =
toValidationResult(
node.processor[].processDataColumnSidecar(
MsgSource.gossip, dataColumnSidecar, subnet_id)))
elif consensusFork == ConsensusFork.Fulu:
for it in 0'u64..<node.dag.cfg.NUMBER_OF_CUSTODY_GROUPS:
closureScope:
let subnet_id = it
Expand Down
28 changes: 18 additions & 10 deletions beacon_chain/spec/datatypes/gloas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const
type
# https://github.com/ethereum/consensus-specs/blob/v1.6.0-beta.0/specs/gloas/p2p-interface.md#modified-datacolumnsidecar
DataColumnSidecar* = object
index*: ColumnIndex
index*: ColumnIndex
column*: DataColumn
kzg_commitments*: KzgCommitments
kzg_proofs*: deneb.KzgProofs
Expand Down Expand Up @@ -87,7 +87,7 @@ type
ExecutionPayloadEnvelope* = object
payload*: deneb.ExecutionPayload
execution_requests*: ExecutionRequests
builder_index*: uint64
builder_index*: uint64
beacon_block_root*: Eth2Digest
slot*: Slot
blob_kzg_commitments*: KzgCommitments
Expand Down Expand Up @@ -320,10 +320,10 @@ type
# [New in Gloas:EIP7732]
execution_payload_availability*: BitArray[int(SLOTS_PER_HISTORICAL_ROOT)]
# [New in Gloas:EIP7732]
builder_pending_payments*:
builder_pending_payments*:
HashArray[Limit 2 * SLOTS_PER_EPOCH, BuilderPendingPayment]
# [New in Gloas:EIP7732]
builder_pending_withdrawals*:
builder_pending_withdrawals*:
HashList[BuilderPendingWithdrawal, Limit BUILDER_PENDING_WITHDRAWALS_LIMIT]
# [New in Gloas:EIP7732]
latest_block_hash*: Eth2Digest
Expand Down Expand Up @@ -420,12 +420,12 @@ type
sync_aggregate*: SyncAggregate

# Execution
bls_to_execution_changes*: SignedBLSToExecutionChangeList
bls_to_execution_changes*: SignedBLSToExecutionChangeList

# [New in Gloas:EIP7732]
signed_execution_payload_bid*: SignedExecutionPayloadBid
# [New in Gloas:EIP7732]
payload_attestations*:
payload_attestations*:
List[PayloadAttestation, Limit MAX_PAYLOAD_ATTESTATIONS]

SigVerifiedBeaconBlockBody* = object
Expand Down Expand Up @@ -463,12 +463,12 @@ type
sync_aggregate*: TrustedSyncAggregate

# Execution
bls_to_execution_changes*: SignedBLSToExecutionChangeList
bls_to_execution_changes*: SignedBLSToExecutionChangeList

# [New in Gloas:EIP7732]
signed_execution_payload_bid*: SignedExecutionPayloadBid
# [New in Gloas:EIP7732]
payload_attestations*:
payload_attestations*:
List[PayloadAttestation, Limit MAX_PAYLOAD_ATTESTATIONS]

TrustedBeaconBlockBody* = object
Expand All @@ -494,12 +494,12 @@ type
sync_aggregate*: TrustedSyncAggregate

# Execution
bls_to_execution_changes*: SignedBLSToExecutionChangeList
bls_to_execution_changes*: SignedBLSToExecutionChangeList

# [New in Gloas:EIP7732]
signed_execution_payload_bid*: SignedExecutionPayloadBid
# [New in Gloas:EIP7732]
payload_attestations*:
payload_attestations*:
List[PayloadAttestation, Limit MAX_PAYLOAD_ATTESTATIONS]

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-beta.4/specs/phase0/beacon-chain.md#signedbeaconblock
Expand Down Expand Up @@ -556,6 +556,14 @@ type
func initHashedBeaconState*(s: BeaconState): HashedBeaconState =
HashedBeaconState(data: s)

func shortLog*(v: DataColumnSidecar): auto =
(
index: v.index,
kzg_commitments: v.kzg_commitments.len,
kzg_proofs: v.kzg_proofs.len,
beacon_block_root: shortLog(v.beacon_block_root),
)

func shortLog*(v: SomeBeaconBlock): auto =
(
slot: shortLog(v.slot),
Expand Down
6 changes: 4 additions & 2 deletions beacon_chain/spec/peerdas_helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ proc assemble_data_column_sidecars*(
sidecars

# https://github.com/ethereum/consensus-specs/blob/v1.6.0-alpha.3/specs/fulu/p2p-interface.md#verify_data_column_sidecar
func verify_data_column_sidecar*(sidecar: fulu.DataColumnSidecar):
func verify_data_column_sidecar*(sidecar: fulu.DataColumnSidecar |
gloas.DataColumnSidecar):
Result[void, cstring] =
## Verify if the data column sidecar is valid.

Expand Down Expand Up @@ -281,7 +282,8 @@ func verify_data_column_sidecar_inclusion_proof*(sidecar: fulu.DataColumnSidecar
ok()

# https://github.com/ethereum/consensus-specs/blob/v1.6.0-alpha.3/specs/fulu/p2p-interface.md#verify_data_column_sidecar_kzg_proofs
proc verify_data_column_sidecar_kzg_proofs*(sidecar: fulu.DataColumnSidecar):
proc verify_data_column_sidecar_kzg_proofs*(sidecar: fulu.DataColumnSidecar |
gloas.DataColumnSidecar):
Result[void, cstring] =
## Verify if the KZG proofs are correct.

Expand Down
Loading