Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UnsignedBeaconBlockHeader #495

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 2 additions & 4 deletions beacon_chain/spec/beaconstate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,10 @@ func initialize_beacon_state_from_eth1*(
eth1_data:
Eth1Data(block_hash: eth1_block_hash, deposit_count: uint64(len(deposits))),
latest_block_header:
BeaconBlockHeader(
UnsignedBeaconBlockHeader(
body_root: hash_tree_root(BeaconBlockBody(
randao_reveal: BlsValue[Signature](kind: OpaqueBlob)
)),
# TODO - Pure BLSSig cannot be zero: https://github.com/status-im/nim-beacon-chain/issues/374
signature: BlsValue[Signature](kind: OpaqueBlob)
))
)
)

Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/spec/crypto.nim
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export
export
blscurve.init, blscurve.getBytes, blscurve.combine,
blscurve.`$`, blscurve.`==`,
blscurve.Signature
blscurve.Signature, blscurve.RawSignatureSize

type
BlsValueType* = enum
Expand Down
14 changes: 13 additions & 1 deletion beacon_chain/spec/datatypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ type
body_root*: Eth2Digest
signature*: ValidatorSig

# This is a variation on BeaconBlockHeader used when the signature is not yet
# available, such as in the BeaconState - this simplifies loading and saving
# states since the expectation is that this signatures is serialized to
# all-zeroes and never a valid signature serialization (all-zeroes is not valid)
UnsignedBeaconBlockHeader* = object
slot*: Slot
parent_root*: Eth2Digest
state_root*: Eth2Digest
body_root*: Eth2Digest
signature*: array[RawSignatureSize, byte] # always 0

# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#beaconblockbody
BeaconBlockBody* = object
randao_reveal*: ValidatorSig
Expand All @@ -257,7 +268,7 @@ type
fork*: Fork

# History
latest_block_header*: BeaconBlockHeader ##\
latest_block_header*: UnsignedBeaconBlockHeader ##\
## `latest_block_header.state_root == ZERO_HASH` temporarily

block_roots*: array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\
Expand Down Expand Up @@ -421,6 +432,7 @@ template foreachSpecType*(op: untyped) =
op BeaconBlock
op BeaconBlockBody
op BeaconBlockHeader
op UnsignedBeaconBlockHeader
op BeaconState
op Crosslink
op Deposit
Expand Down
8 changes: 2 additions & 6 deletions beacon_chain/spec/state_transition_block.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,13 @@ proc process_block_header*(
return false

# Save current block as the new latest block
state.latest_block_header = BeaconBlockHeader(
state.latest_block_header = UnsignedBeaconBlockHeader(
slot: blck.slot,
parent_root: blck.parent_root,
# state_root: zeroed, overwritten in the next `process_slot` call
body_root: hash_tree_root(blck.body),
# signature is always zeroed
# TODO - Pure BLSSig cannot be zero: https://github.com/status-im/nim-beacon-chain/issues/374
signature: BlsValue[Signature](kind: OpaqueBlob)
body_root: hash_tree_root(blck.body)
)


# Verify proposer is not slashed
let proposer =
state.validators[get_beacon_proposer_index(state, stateCache)]
Expand Down