Merge branch 'dev/etan/im-base' into feat_eip-7688

This commit is contained in:
Etan Kissling 2024-05-26 15:22:12 +02:00
commit fe058f9f04
No known key found for this signature in database
GPG Key ID: B21DA824C5A3D03D
14 changed files with 115 additions and 115 deletions

View File

@ -84,15 +84,6 @@ type
## effectively making the cost of clearing the cache higher than the typical
## gains
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/altair/beacon-chain.md#syncaggregate
SyncAggregate* = object
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
sync_committee_signature*: ValidatorSig
TrustedSyncAggregate* = object
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
sync_committee_signature*: TrustedSig
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/altair/beacon-chain.md#synccommittee
SyncCommittee* = object
pubkeys*: HashArray[Limit SYNC_COMMITTEE_SIZE, ValidatorPubKey]
@ -529,8 +520,6 @@ type
SigVerifiedBeaconBlockBody |
TrustedBeaconBlockBody
SomeSyncAggregate* = SyncAggregate | TrustedSyncAggregate
SyncSubcommitteeIndex* = distinct uint8
IndexInSyncCommittee* = distinct uint16
@ -630,23 +619,6 @@ func shortLog*(v: SyncCommitteeMessage): auto =
signature: shortLog(v.signature)
)
func init*(T: type SyncAggregate): SyncAggregate =
SyncAggregate(sync_committee_signature: ValidatorSig.infinity)
func num_active_participants*(v: SomeSyncAggregate): int =
countOnes(v.sync_committee_bits)
func hasSupermajoritySyncParticipation*(
num_active_participants: uint64): bool =
const max_active_participants = SYNC_COMMITTEE_SIZE.uint64
num_active_participants * 3 >= static(max_active_participants * 2)
func hasSupermajoritySyncParticipation*(v: SomeSyncAggregate): bool =
hasSupermajoritySyncParticipation(v.num_active_participants.uint64)
func shortLog*(v: SyncAggregate): auto =
$(v.sync_committee_bits)
func shortLog*(v: ContributionAndProof): auto =
(
aggregator_index: v.aggregator_index,
@ -741,7 +713,3 @@ template asTrusted*(
SigVerifiedSignedBeaconBlock |
MsgTrustedSignedBeaconBlock): TrustedSignedBeaconBlock =
isomorphicCast[TrustedSignedBeaconBlock](x)
template asTrusted*(
x: SyncAggregate): TrustedSyncAggregate =
isomorphicCast[TrustedSyncAggregate](x)

View File

@ -224,6 +224,11 @@ type
CommitteeValidatorsBits* = BitList[Limit MAX_VALIDATORS_PER_COMMITTEE]
ElectraCommitteeValidatorsBits* =
BitList[Limit MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT]
AttestationCommitteeBits* = BitArray[MAX_COMMITTEES_PER_SLOT.int]
ForkDigest* = distinct array[4, byte]
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#forkdata
@ -281,6 +286,7 @@ type
SomeProposerSlashing* = ProposerSlashing | TrustedProposerSlashing
SomeSignedBeaconBlockHeader* = SignedBeaconBlockHeader | TrustedSignedBeaconBlockHeader
SomeSignedVoluntaryExit* = SignedVoluntaryExit | TrustedSignedVoluntaryExit
SomeSyncAggregate* = SyncAggregate | TrustedSyncAggregate
# Legacy database type, see BeaconChainDB
ImmutableValidatorData* = object
@ -363,6 +369,52 @@ type
message*: VoluntaryExit
signature*: TrustedSig
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/altair/beacon-chain.md#syncaggregate
SyncAggregate* = object
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
sync_committee_signature*: ValidatorSig
TrustedSyncAggregate* = object
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
sync_committee_signature*: TrustedSig
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/bellatrix/beacon-chain.md#custom-types
Transaction* = List[byte, Limit MAX_BYTES_PER_TRANSACTION]
ExecutionAddress* = object
data*: array[20, byte] # TODO there's a network_metadata type, but the import hierarchy's inconvenient
BloomLogs* = object
data*: array[BYTES_PER_LOGS_BLOOM, byte]
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/capella/beacon-chain.md#withdrawal
Withdrawal* = object
index*: WithdrawalIndex
validator_index*: uint64
address*: ExecutionAddress
amount*: Gwei
# https://github.com/ethereum/consensus-specs/blob/94a0b6c581f2809aa8aca4ef7ee6fbb63f9d74e9/specs/electra/beacon-chain.md#depositreceipt
DepositReceipt* = object
pubkey*: ValidatorPubKey
withdrawal_credentials*: Eth2Digest
amount*: Gwei
signature*: ValidatorSig
index*: uint64
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/electra/beacon-chain.md#executionlayerwithdrawalrequest
ExecutionLayerWithdrawalRequest* = object
source_address*: ExecutionAddress
validator_pubkey*: ValidatorPubKey
amount*: Gwei
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/capella/beacon-chain.md#historicalsummary
HistoricalSummary* = object
# `HistoricalSummary` matches the components of the phase0
# `HistoricalBatch` making the two hash_tree_root-compatible.
block_summary_root*: Eth2Digest
state_summary_root*: Eth2Digest
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#beaconblockheader
BeaconBlockHeader* = object
slot*: Slot
@ -806,6 +858,51 @@ func shortLog*(v: SomeSignedVoluntaryExit): auto =
signature: shortLog(v.signature)
)
func shortLog*(v: SomeSyncAggregate): auto =
$(v.sync_committee_bits)
func init*(T: type SyncAggregate): SyncAggregate =
SyncAggregate(sync_committee_signature: ValidatorSig.infinity)
template asTrusted*(
x: SyncAggregate): TrustedSyncAggregate =
isomorphicCast[TrustedSyncAggregate](x)
func num_active_participants*(v: SomeSyncAggregate): int =
countOnes(v.sync_committee_bits)
func hasSupermajoritySyncParticipation*(
num_active_participants: uint64): bool =
const max_active_participants = SYNC_COMMITTEE_SIZE.uint64
num_active_participants * 3 >= static(max_active_participants * 2)
func hasSupermajoritySyncParticipation*(v: SomeSyncAggregate): bool =
hasSupermajoritySyncParticipation(v.num_active_participants.uint64)
func fromHex*(
T: typedesc[BloomLogs], s: string): T {.raises: [ValueError].} =
hexToByteArray(s, result.data)
func fromHex*(
T: typedesc[ExecutionAddress], s: string): T {.raises: [ValueError].} =
hexToByteArray(s, result.data)
proc writeValue*(
writer: var JsonWriter, value: ExecutionAddress) {.raises: [IOError].} =
writer.writeValue to0xHex(value.data)
proc readValue*(
reader: var JsonReader,
value: var ExecutionAddress) {.raises: [IOError, SerializationError].} =
try:
hexToByteArray(reader.readValue(string), value.data)
except ValueError:
reader.raiseUnexpectedValue(
"ExecutionAddress value should be a valid hex string")
func `$`*(v: ExecutionAddress): string =
v.data.toHex()
chronicles.formatIt AttestationData: it.shortLog
chronicles.formatIt Checkpoint: it.shortLog

View File

@ -35,15 +35,6 @@ const
NEWPAYLOAD_TIMEOUT* = 8.seconds
type
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/bellatrix/beacon-chain.md#custom-types
Transaction* = List[byte, Limit MAX_BYTES_PER_TRANSACTION]
ExecutionAddress* = object
data*: array[20, byte] # TODO there's a network_metadata type, but the import hierarchy's inconvenient
BloomLogs* = object
data*: array[BYTES_PER_LOGS_BLOOM, byte]
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/bellatrix/beacon-chain.md#executionpayload
ExecutionPayload* = object
# Execution block header fields
@ -361,29 +352,6 @@ type
func initHashedBeaconState*(s: BeaconState): HashedBeaconState =
HashedBeaconState(data: s)
func fromHex*(T: typedesc[BloomLogs], s: string): T {.
raises: [ValueError].} =
hexToByteArray(s, result.data)
func fromHex*(T: typedesc[ExecutionAddress], s: string): T {.
raises: [ValueError].} =
hexToByteArray(s, result.data)
proc writeValue*(
writer: var JsonWriter, value: ExecutionAddress) {.raises: [IOError].} =
writer.writeValue to0xHex(value.data)
proc readValue*(reader: var JsonReader, value: var ExecutionAddress) {.
raises: [IOError, SerializationError].} =
try:
hexToByteArray(reader.readValue(string), value.data)
except ValueError:
raiseUnexpectedValue(reader,
"ExecutionAddress value should be a valid hex string")
func `$`*(v: ExecutionAddress): string =
v.data.toHex()
func shortLog*(v: SomeBeaconBlock): auto =
(
slot: shortLog(v.slot),

View File

@ -39,13 +39,6 @@ type
SignedBLSToExecutionChangeList* =
List[SignedBLSToExecutionChange, Limit MAX_BLS_TO_EXECUTION_CHANGES]
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/capella/beacon-chain.md#withdrawal
Withdrawal* = object
index*: WithdrawalIndex
validator_index*: uint64
address*: ExecutionAddress
amount*: Gwei
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/capella/beacon-chain.md#blstoexecutionchange
BLSToExecutionChange* = object
validator_index*: uint64
@ -57,13 +50,6 @@ type
message*: BLSToExecutionChange
signature*: ValidatorSig
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/capella/beacon-chain.md#historicalsummary
HistoricalSummary* = object
# `HistoricalSummary` matches the components of the phase0
# `HistoricalBatch` making the two hash_tree_root-compatible.
block_summary_root*: Eth2Digest
state_summary_root*: Eth2Digest
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/capella/beacon-chain.md#executionpayload
ExecutionPayload* = object
# Execution block header fields

View File

@ -56,25 +56,6 @@ const
MAX_BEACON_STATE_FIELDS* = 128
type
ElectraCommitteeValidatorsBits* =
BitList[Limit MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT]
AttestationCommitteeBits* = BitArray[MAX_COMMITTEES_PER_SLOT.int]
# https://github.com/ethereum/consensus-specs/blob/94a0b6c581f2809aa8aca4ef7ee6fbb63f9d74e9/specs/electra/beacon-chain.md#depositreceipt
DepositReceipt* = object
pubkey*: ValidatorPubKey
withdrawal_credentials*: Eth2Digest
amount*: Gwei
signature*: ValidatorSig
index*: uint64
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/electra/beacon-chain.md#executionlayerwithdrawalrequest
ExecutionLayerWithdrawalRequest* = object
source_address*: ExecutionAddress
validator_pubkey*: ValidatorPubKey
amount*: Gwei
# https://eips.ethereum.org/EIPS/eip-7688
StableAttestation* {.
sszStableContainer: MAX_ATTESTATION_FIELDS.} = object

View File

@ -1360,19 +1360,19 @@ func readSszForkedHashedBeaconState*(cfg: RuntimeConfig, data: openArray[byte]):
ForkedHashedBeaconState {.raises: [SerializationError].} =
## Read a state picking the right fork by first reading the slot from the byte
## source
if data.len() < sizeof(BeaconStateHeader):
raise (ref MalformedSszError)(msg: "Not enough data for BeaconState header")
const numHeaderBytes = fixedPortionSize(BeaconStateHeader)
if data.len() < numHeaderBytes:
raise (ref MalformedSszError)(msg: "Incomplete BeaconState header")
let header = SSZ.decode(
data.toOpenArray(0, sizeof(BeaconStateHeader) - 1),
BeaconStateHeader)
data.toOpenArray(0, numHeaderBytes - 1), BeaconStateHeader)
# TODO https://github.com/nim-lang/Nim/issues/19357
result = readSszForkedHashedBeaconState(cfg, header.slot, data)
type
ForkedBeaconBlockHeader = object
message*: uint32 # message offset
signature*: ValidatorSig
message: uint32 # message offset
signature: ValidatorSig
slot: Slot # start of BeaconBlock
func readSszForkedSignedBeaconBlock*(
@ -1380,11 +1380,11 @@ func readSszForkedSignedBeaconBlock*(
ForkedSignedBeaconBlock {.raises: [SerializationError].} =
## Helper to read a header from bytes when it's not certain what kind of block
## it is
if data.len() < sizeof(ForkedBeaconBlockHeader):
raise (ref MalformedSszError)(msg: "Not enough data for SignedBeaconBlock header")
const numHeaderBytes = fixedPortionSize(ForkedBeaconBlockHeader)
if data.len() < numHeaderBytes:
raise (ref MalformedSszError)(msg: "Incomplete SignedBeaconBlock header")
let header = SSZ.decode(
data.toOpenArray(0, sizeof(ForkedBeaconBlockHeader) - 1),
ForkedBeaconBlockHeader)
data.toOpenArray(0, numHeaderBytes - 1), ForkedBeaconBlockHeader)
# TODO https://github.com/nim-lang/Nim/issues/19357
result = ForkedSignedBeaconBlock(

View File

@ -21,7 +21,7 @@ source "${SCRIPTS_DIR}/bash_utils.sh"
download_geth_stable() {
if [[ ! -e "${STABLE_GETH_BINARY}" ]]; then
GETH_VERSION="1.14.0-87246f3c" # https://geth.ethereum.org/downloads
GETH_VERSION="1.14.3-ab48ba42" # https://geth.ethereum.org/downloads
GETH_URL="https://gethstore.blob.core.windows.net/builds/"
case "${OS}-${ARCH}" in

@ -1 +1 @@
Subproject commit c115f3688c19eb6153e22c1e76477db4ed27fae3
Subproject commit 9ed6c63314899d17e2c3f669adbe2bc915610982

@ -1 +1 @@
Subproject commit 1ac1d69f9512d55d15e8218a9dbdff129bf96ddb
Subproject commit 4d0b0662ed960ab2c5a1ddbd08f77048bac13ae7

2
vendor/nim-kzg4844 vendored

@ -1 +1 @@
Subproject commit 4fbcfbe4c452313bd440936318a87ed708987d8b
Subproject commit f12616d0675d9f6346141ca95f0840ab227eb213

@ -1 +1 @@
Subproject commit 4c4fc6f1436b5e0468a6b3a7929bb603f0b43f33
Subproject commit 54bf8aa2913e8550463779beeae4b469941e039c

2
vendor/nim-snappy vendored

@ -1 +1 @@
Subproject commit aaef74113cadaaca690c6144eae0cf2c2a10db28
Subproject commit 913c426d571cf82601452642e01cd11ea26f7ac6

2
vendor/nim-stint vendored

@ -1 +1 @@
Subproject commit 3c238df6cd4b9c1f37a9f103383e7d2bbd420c13
Subproject commit 9d2b382c5dc34f0d6bbd93b2a5d65dde85067e0f

2
vendor/nim-web3 vendored

@ -1 +1 @@
Subproject commit 9aed14a7373f51715730712adfde39546708296f
Subproject commit 46b4b4c8bc42013196a6290ee53029131f97931a