mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-27 23:07:54 +00:00
Domain is now array[8, byte] instead of uint64
This commit is contained in:
parent
5619f9e4e6
commit
90b20fab52
@ -169,7 +169,7 @@ func bls_aggregate_pubkeys*(keys: openArray[ValidatorPubKey]): ValidatorPubKey =
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/bls_signature.md#bls_verify
|
||||
func bls_verify*(
|
||||
pubkey: ValidatorPubKey, msg: openArray[byte], sig: ValidatorSig,
|
||||
domain: uint64): bool =
|
||||
domain: Domain): bool =
|
||||
# name from spec!
|
||||
if sig.kind != Real:
|
||||
# Invalid signatures are possible in deposits (discussed with Danny)
|
||||
@ -185,7 +185,7 @@ func bls_verify*(
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/bls_signature.md#bls_verify_multiple
|
||||
proc bls_verify_multiple*(
|
||||
pubkeys: seq[ValidatorPubKey], message_hashes: openArray[Eth2Digest],
|
||||
sig: ValidatorSig, domain: uint64): bool =
|
||||
sig: ValidatorSig, domain: Domain): bool =
|
||||
# {.noSideEffect.} - https://github.com/status-im/nim-chronicles/issues/62
|
||||
let L = len(pubkeys)
|
||||
doAssert L == len(message_hashes)
|
||||
@ -209,7 +209,7 @@ proc bls_verify_multiple*(
|
||||
|
||||
when ValidatorPrivKey is BlsValue:
|
||||
func bls_sign*(key: ValidatorPrivKey, msg: openarray[byte],
|
||||
domain: uint64): ValidatorSig =
|
||||
domain: Domain): ValidatorSig =
|
||||
# name from spec!
|
||||
if key.kind == Real:
|
||||
ValidatorSig(kind: Real, blsValue: key.blsValue.sign(domain, msg))
|
||||
@ -217,7 +217,7 @@ when ValidatorPrivKey is BlsValue:
|
||||
ValidatorSig(kind: OpaqueBlob)
|
||||
else:
|
||||
func bls_sign*(key: ValidatorPrivKey, msg: openarray[byte],
|
||||
domain: uint64): ValidatorSig =
|
||||
domain: Domain): ValidatorSig =
|
||||
# name from spec!
|
||||
ValidatorSig(kind: Real, blsValue: key.sign(domain, msg))
|
||||
|
||||
|
@ -76,7 +76,6 @@ type
|
||||
ValidatorIndex* = range[0'u32 .. 0xFFFFFF'u32] # TODO: wrap-around
|
||||
Shard* = uint64
|
||||
Gwei* = uint64
|
||||
Domain* = uint64
|
||||
|
||||
BitList*[maxLen: static int] = distinct BitSeq
|
||||
|
||||
|
@ -7,7 +7,13 @@
|
||||
|
||||
# Uncategorized helper functions from the spec
|
||||
|
||||
import ./datatypes, ./digest, sequtils, math, endians
|
||||
import
|
||||
# Standard lib
|
||||
sequtils, math, endians,
|
||||
# Third-party
|
||||
blscurve, # defines Domain
|
||||
# Internal
|
||||
./datatypes, ./digest
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#integer_squareroot
|
||||
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
||||
@ -142,11 +148,9 @@ func int_to_bytes4*(x: uint64): array[4, byte] =
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#compute_domain
|
||||
func compute_domain*(
|
||||
domain_type: DomainType,
|
||||
fork_version: array[4, byte] = [0'u8, 0, 0, 0]): uint64 =
|
||||
var buf: array[8, byte]
|
||||
buf[0..3] = int_to_bytes4(domain_type.uint64)
|
||||
buf[4..7] = fork_version
|
||||
bytes_to_int(buf)
|
||||
fork_version: array[4, byte] = [0'u8, 0, 0, 0]): Domain =
|
||||
result[0..3] = int_to_bytes4(domain_type.uint64)
|
||||
result[4..7] = fork_version
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#get_domain
|
||||
func get_domain*(
|
||||
|
@ -16,9 +16,6 @@ import
|
||||
./fixtures_utils
|
||||
|
||||
type
|
||||
Domain = distinct uint64
|
||||
## Domains have custom hex serialization
|
||||
|
||||
BLSPrivToPub* = object
|
||||
input*: ValidatorPrivKey
|
||||
output*: ValidatorPubKey
|
||||
@ -42,12 +39,10 @@ type
|
||||
|
||||
proc readValue*(r: var JsonReader, a: var Domain) {.inline.} =
|
||||
## Custom deserializer for Domain
|
||||
## They are uint64 stored in hex values
|
||||
# Furthermore Nim parseHex doesn't support uint
|
||||
# until https://github.com/nim-lang/Nim/pull/11067
|
||||
# (0.20)
|
||||
let be_uint = hexToPaddedByteArray[8](r.readValue(string))
|
||||
bigEndian64(a.addr, be_uint.unsafeAddr)
|
||||
a = hexToPaddedByteArray[8](r.readValue(string))
|
||||
|
||||
const BLSDir = JsonTestsDir/"general"/"phase0"/"bls"
|
||||
|
||||
@ -64,7 +59,7 @@ suite "Official - BLS tests":
|
||||
let t = parseTest(file, Json, BLSSignMsg)
|
||||
let implResult = t.input.privkey.bls_sign(
|
||||
t.input.message,
|
||||
uint64(t.input.domain)
|
||||
t.input.domain
|
||||
)
|
||||
check: implResult == t.output
|
||||
|
||||
|
@ -55,7 +55,7 @@ func makeDeposit(i: int, flags: UpdateFlags): Deposit =
|
||||
privkey = makeFakeValidatorPrivKey(i)
|
||||
pubkey = privkey.pubKey()
|
||||
withdrawal_credentials = makeFakeHash(i)
|
||||
domain = 3'u64
|
||||
domain = compute_domain(DOMAIN_DEPOSIT)
|
||||
|
||||
result = Deposit(
|
||||
data: DepositData(
|
||||
|
Loading…
x
Reference in New Issue
Block a user