From caa3b73dbb05bd4f061cd529a8cf3ebd4f8c0e47 Mon Sep 17 00:00:00 2001 From: tersec Date: Sun, 21 Apr 2024 01:17:02 +0000 Subject: [PATCH] move AttesterSlashing and IndexedAttestation from base to phase0 (#6223) --- beacon_chain/spec/datatypes/base.nim | 51 ------------------------ beacon_chain/spec/datatypes/phase0.nim | 53 +++++++++++++++++++++++++ beacon_chain/spec/mev/bellatrix_mev.nim | 2 +- beacon_chain/spec/mev/capella_mev.nim | 2 +- beacon_chain/spec/mev/deneb_mev.nim | 2 +- beacon_chain/spec/mev/electra_mev.nim | 2 +- 6 files changed, 57 insertions(+), 55 deletions(-) diff --git a/beacon_chain/spec/datatypes/base.nim b/beacon_chain/spec/datatypes/base.nim index e00a2a8cd..e1663f180 100644 --- a/beacon_chain/spec/datatypes/base.nim +++ b/beacon_chain/spec/datatypes/base.nim @@ -222,32 +222,6 @@ type signed_header_1*: TrustedSignedBeaconBlockHeader signed_header_2*: TrustedSignedBeaconBlockHeader - # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/phase0/beacon-chain.md#attesterslashing - AttesterSlashing* = object - attestation_1*: IndexedAttestation - attestation_2*: IndexedAttestation - - TrustedAttesterSlashing* = object - # The Trusted version, at the moment, implies that the cryptographic signature was checked. - # It DOES NOT imply that the state transition was verified. - # Currently the code MUST verify the state transition as soon as the signature is verified - attestation_1*: TrustedIndexedAttestation - attestation_2*: TrustedIndexedAttestation - - # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#indexedattestation - IndexedAttestation* = object - attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE] - data*: AttestationData - signature*: ValidatorSig - - TrustedIndexedAttestation* = object - # The Trusted version, at the moment, implies that the cryptographic signature was checked. - # It DOES NOT imply that the state transition was verified. - # Currently the code MUST verify the state transition as soon as the signature is verified - attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE] - data*: AttestationData - signature*: TrustedSig - CommitteeValidatorsBits* = BitList[Limit MAX_VALIDATORS_PER_COMMITTEE] ForkDigest* = distinct array[4, byte] @@ -304,9 +278,7 @@ type ## Earliest epoch when voluntary exit can be processed validator_index*: uint64 # `ValidatorIndex` after validation - SomeIndexedAttestation* = IndexedAttestation | TrustedIndexedAttestation SomeProposerSlashing* = ProposerSlashing | TrustedProposerSlashing - SomeAttesterSlashing* = AttesterSlashing | TrustedAttesterSlashing SomeSignedBeaconBlockHeader* = SignedBeaconBlockHeader | TrustedSignedBeaconBlockHeader SomeSignedVoluntaryExit* = SignedVoluntaryExit | TrustedSignedVoluntaryExit @@ -816,29 +788,6 @@ func shortLog*(v: PendingAttestation): auto = proposer_index: v.proposer_index ) -func shortLog*(v: SomeIndexedAttestation): auto = - ( - attestating_indices: v.attesting_indices, - data: shortLog(v.data), - signature: shortLog(v.signature) - ) - -iterator getValidatorIndices*(attester_slashing: SomeAttesterSlashing): uint64 = - template attestation_1(): auto = attester_slashing.attestation_1 - template attestation_2(): auto = attester_slashing.attestation_2 - - let attestation_2_indices = toHashSet(attestation_2.attesting_indices.asSeq) - for validator_index in attestation_1.attesting_indices.asSeq: - if validator_index notin attestation_2_indices: - continue - yield validator_index - -func shortLog*(v: SomeAttesterSlashing): auto = - ( - attestation_1: shortLog(v.attestation_1), - attestation_2: shortLog(v.attestation_2), - ) - func shortLog*(v: SomeProposerSlashing): auto = ( signed_header_1: shortLog(v.signed_header_1), diff --git a/beacon_chain/spec/datatypes/phase0.nim b/beacon_chain/spec/datatypes/phase0.nim index 9bd72a457..061cd690c 100644 --- a/beacon_chain/spec/datatypes/phase0.nim +++ b/beacon_chain/spec/datatypes/phase0.nim @@ -19,6 +19,8 @@ import chronicles, ./base +from std/sets import toHashSet + export base type @@ -257,6 +259,32 @@ type root* {.dontSerialize.}: Eth2Digest # cached root of signed beacon block + # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/phase0/beacon-chain.md#attesterslashing + AttesterSlashing* = object + attestation_1*: IndexedAttestation + attestation_2*: IndexedAttestation + + TrustedAttesterSlashing* = object + # The Trusted version, at the moment, implies that the cryptographic signature was checked. + # It DOES NOT imply that the state transition was verified. + # Currently the code MUST verify the state transition as soon as the signature is verified + attestation_1*: TrustedIndexedAttestation + attestation_2*: TrustedIndexedAttestation + + # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#indexedattestation + IndexedAttestation* = object + attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE] + data*: AttestationData + signature*: ValidatorSig + + TrustedIndexedAttestation* = object + # The Trusted version, at the moment, implies that the cryptographic signature was checked. + # It DOES NOT imply that the state transition was verified. + # Currently the code MUST verify the state transition as soon as the signature is verified + attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE] + data*: AttestationData + signature*: TrustedSig + # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#attestation Attestation* = object aggregation_bits*: CommitteeValidatorsBits @@ -282,6 +310,8 @@ type message*: AggregateAndProof signature*: ValidatorSig + SomeIndexedAttestation* = IndexedAttestation | TrustedIndexedAttestation + SomeAttesterSlashing* = AttesterSlashing | TrustedAttesterSlashing SomeSignedBeaconBlock* = SignedBeaconBlock | SigVerifiedSignedBeaconBlock | @@ -309,6 +339,29 @@ func clear*(info: var EpochInfo) = info.validators.setLen(0) info.balances = TotalBalances() +func shortLog*(v: SomeIndexedAttestation): auto = + ( + attestating_indices: v.attesting_indices, + data: shortLog(v.data), + signature: shortLog(v.signature) + ) + +iterator getValidatorIndices*(attester_slashing: SomeAttesterSlashing): uint64 = + template attestation_1(): auto = attester_slashing.attestation_1 + template attestation_2(): auto = attester_slashing.attestation_2 + + let attestation_2_indices = toHashSet(attestation_2.attesting_indices.asSeq) + for validator_index in attestation_1.attesting_indices.asSeq: + if validator_index notin attestation_2_indices: + continue + yield validator_index + +func shortLog*(v: SomeAttesterSlashing): auto = + ( + attestation_1: shortLog(v.attestation_1), + attestation_2: shortLog(v.attestation_2), + ) + func shortLog*(v: SomeBeaconBlock): auto = ( slot: shortLog(v.slot), diff --git a/beacon_chain/spec/mev/bellatrix_mev.nim b/beacon_chain/spec/mev/bellatrix_mev.nim index bece01f85..029f156c5 100644 --- a/beacon_chain/spec/mev/bellatrix_mev.nim +++ b/beacon_chain/spec/mev/bellatrix_mev.nim @@ -8,7 +8,7 @@ {.push raises: [].} import ".."/datatypes/altair -from ".."/datatypes/phase0 import Attestation +from ".."/datatypes/phase0 import Attestation, AttesterSlashing from ".."/datatypes/bellatrix import ExecutionPayloadHeader from ".."/eth2_merkleization import hash_tree_root diff --git a/beacon_chain/spec/mev/capella_mev.nim b/beacon_chain/spec/mev/capella_mev.nim index 08e5066c8..4a5dfa98d 100644 --- a/beacon_chain/spec/mev/capella_mev.nim +++ b/beacon_chain/spec/mev/capella_mev.nim @@ -8,7 +8,7 @@ {.push raises: [].} import ".."/datatypes/[altair, capella] -from ".."/datatypes/phase0 import Attestation +from ".."/datatypes/phase0 import Attestation, AttesterSlashing from stew/byteutils import to0xHex from ../eth2_merkleization import fromSszBytes, hash_tree_root, toSszType diff --git a/beacon_chain/spec/mev/deneb_mev.nim b/beacon_chain/spec/mev/deneb_mev.nim index 23a289461..961e73645 100644 --- a/beacon_chain/spec/mev/deneb_mev.nim +++ b/beacon_chain/spec/mev/deneb_mev.nim @@ -10,7 +10,7 @@ import ".."/datatypes/[altair, deneb] from stew/byteutils import to0xHex -from ".."/datatypes/phase0 import Attestation +from ".."/datatypes/phase0 import Attestation, AttesterSlashing from ../datatypes/bellatrix import ExecutionAddress from ".."/datatypes/capella import SignedBLSToExecutionChange from ".."/eth2_merkleization import hash_tree_root diff --git a/beacon_chain/spec/mev/electra_mev.nim b/beacon_chain/spec/mev/electra_mev.nim index 39f1e48ba..a99ac6389 100644 --- a/beacon_chain/spec/mev/electra_mev.nim +++ b/beacon_chain/spec/mev/electra_mev.nim @@ -10,7 +10,7 @@ import ".."/datatypes/[altair, electra] from stew/byteutils import to0xHex -from ".."/datatypes/phase0 import Attestation +from ".."/datatypes/phase0 import Attestation, AttesterSlashing from ../datatypes/bellatrix import ExecutionAddress from ".."/datatypes/capella import SignedBLSToExecutionChange from ".."/datatypes/deneb import BlobsBundle, KzgCommitments