implement compute_signing_root() and mark some functions as 0.10.1-compatible

This commit is contained in:
Dustin Brody 2020-01-30 15:03:26 +01:00 committed by tersec
parent 0d9503ee49
commit e4922cb177
3 changed files with 14 additions and 4 deletions

View File

@ -373,7 +373,7 @@ proc is_valid_indexed_attestation*(
notice "indexed attestation: validator index beyond max validators per committee"
return false
# Verify indices are sorted
# Verify indices are sorted and unique
# TODO but why? this is a local artifact
if indices != sorted(indices, system.cmp):
notice "indexed attestation: indices not sorted"

View File

@ -13,7 +13,7 @@ import
# Third-party
blscurve, # defines Domain
# Internal
./datatypes, ./digest
./datatypes, ./digest, ../ssz
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#integer_squareroot
func integer_squareroot*(n: SomeInteger): SomeInteger =
@ -144,6 +144,16 @@ func get_domain*(
func get_domain*(state: BeaconState, domain_type: DomainType): Domain =
get_domain(state, domain_type, get_current_epoch(state))
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#compute_signing_root
func compute_signing_root*(ssz_object: auto, domain: Domain): Eth2Digest =
# Return the signing root of an object by calculating the root of the
# object-domain tree.
let domain_wrapped_object = SigningRoot(
object_root: hash_tree_root(ssz_object),
domain: domain
)
hash_tree_root(domain_wrapped_object)
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#get_seed
func get_seed*(state: BeaconState, epoch: Epoch, domain_type: DomainType): Eth2Digest =
# Return the seed at ``epoch``.

View File

@ -213,7 +213,7 @@ func is_slashable_attestation_data(
(data_1.source.epoch < data_2.source.epoch and
data_2.target.epoch < data_1.target.epoch)
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#attester-slashings
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#attester-slashings
proc process_attester_slashing*(
state: var BeaconState,
attester_slashing: AttesterSlashing,
@ -250,7 +250,7 @@ proc process_attester_slashing*(
return false
return true
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#attester-slashings
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#attester-slashings
proc processAttesterSlashings(state: var BeaconState, blck: BeaconBlock,
stateCache: var StateCache): bool {.nbench.}=
# Process ``AttesterSlashing`` operation.