crypto: cleanup (#882)
* crypto: cleanup * fix several Defect-on-user-input * make crypto interface more similar to secp * use `crypto.nim` in all of nbc * digest: raises * fix * vendor
This commit is contained in:
parent
31bf8fa408
commit
afa08c8e3c
|
@ -20,7 +20,7 @@ func is_aggregator(state: BeaconState, slot: Slot, index: uint64,
|
|||
let
|
||||
committee = get_beacon_committee(state, slot, index, cache)
|
||||
modulo = max(1, len(committee) div TARGET_AGGREGATORS_PER_COMMITTEE).uint64
|
||||
bytes_to_int(eth2hash(slot_signature.getBytes).data[0..7]) mod modulo == 0
|
||||
bytes_to_int(eth2hash(slot_signature.toRaw()).data[0..7]) mod modulo == 0
|
||||
|
||||
proc aggregate_attestations*(
|
||||
pool: AttestationPool, state: BeaconState, index: uint64,
|
||||
|
|
|
@ -251,7 +251,7 @@ template findIt(s: openarray, predicate: untyped): int =
|
|||
|
||||
proc addLocalValidator(
|
||||
node: BeaconNode, state: BeaconState, privKey: ValidatorPrivKey) =
|
||||
let pubKey = privKey.pubKey()
|
||||
let pubKey = privKey.toPubKey()
|
||||
|
||||
let idx = state.validators.findIt(it.pubKey == pubKey)
|
||||
if idx == -1:
|
||||
|
|
|
@ -26,7 +26,7 @@ func makeInteropPrivKey*(i: int): ValidatorPrivKey =
|
|||
privkeyBytes = eth2hash(bytes)
|
||||
key = (UInt256.fromBytesLE(privkeyBytes.data) mod curveOrder).toBytesBE()
|
||||
|
||||
result.initFromBytes(key)
|
||||
ValidatorPrivKey.fromRaw(key).tryGet()
|
||||
|
||||
const eth1BlockHash* = block:
|
||||
var x: Eth2Digest
|
||||
|
@ -35,7 +35,7 @@ const eth1BlockHash* = block:
|
|||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/deposit-contract.md#withdrawal-credentials
|
||||
func makeWithdrawalCredentials*(k: ValidatorPubKey): Eth2Digest =
|
||||
var bytes = eth2hash(k.getBytes())
|
||||
var bytes = eth2hash(k.toRaw())
|
||||
bytes.data[0] = BLS_WITHDRAWAL_PREFIX.uint8
|
||||
bytes
|
||||
|
||||
|
|
|
@ -21,60 +21,53 @@
|
|||
# A, B and C, and another with B, C and D, we cannot practically combine them
|
||||
# even if in theory it is possible to allow this in BLS.
|
||||
|
||||
{.push raises: [Defect].}
|
||||
|
||||
import
|
||||
# Internal
|
||||
./digest,
|
||||
./digest, ../ssz/types,
|
||||
# Status
|
||||
stew/[endians2, objects, byteutils],
|
||||
nimcrypto/[utils, sysrand],
|
||||
blscurve, json_serialization,
|
||||
stew/[endians2, objects, results, byteutils],
|
||||
nimcrypto/sysrand,
|
||||
blscurve,
|
||||
chronicles,
|
||||
json_serialization,
|
||||
# Standard library
|
||||
hashes
|
||||
|
||||
export
|
||||
json_serialization
|
||||
|
||||
# export
|
||||
# blscurve.init, blscurve.getBytes, blscurve.combine,
|
||||
# blscurve.`$`, blscurve.`==`,
|
||||
# blscurve.Signature
|
||||
export results, json_serialization
|
||||
|
||||
# Type definitions
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
const
|
||||
RawSigSize* = 96
|
||||
RawPubKeySize* = 48
|
||||
RawPrivKeySize* = 48
|
||||
|
||||
type
|
||||
BlsValueType* = enum
|
||||
Real
|
||||
OpaqueBlob
|
||||
|
||||
BlsValue*[T] = object
|
||||
BlsValue*[N: static int, T] = object
|
||||
# TODO This is a temporary type needed until we sort out the
|
||||
# issues with invalid BLS values appearing in the SSZ test suites.
|
||||
case kind*: BlsValueType
|
||||
of Real:
|
||||
blsValue*: T
|
||||
of OpaqueBlob:
|
||||
when T is blscurve.Signature:
|
||||
blob*: array[96, byte]
|
||||
else:
|
||||
blob*: array[48, byte]
|
||||
blob*: array[N, byte]
|
||||
|
||||
ValidatorPubKey* = BlsValue[blscurve.PublicKey]
|
||||
# Alternatives
|
||||
# ValidatorPubKey* = blscurve.PublicKey
|
||||
# ValidatorPubKey* = array[48, byte]
|
||||
# The use of byte arrays proved to be a dead end pretty quickly.
|
||||
# Plenty of code needs to be modified for a successful build and
|
||||
# the changes will negatively affect the performance.
|
||||
ValidatorPubKey* = BlsValue[RawPubKeySize, blscurve.PublicKey]
|
||||
|
||||
ValidatorPrivKey* = blscurve.SecretKey
|
||||
# ValidatorPrivKey* = BlsValue[blscurve.SecretKey]
|
||||
ValidatorPrivKey* = distinct blscurve.SecretKey
|
||||
|
||||
ValidatorSig* = BlsValue[blscurve.Signature]
|
||||
ValidatorSig* = BlsValue[RawSigSize, blscurve.Signature]
|
||||
|
||||
BlsCurveType* = PublicKey|SecretKey|Signature
|
||||
ValidatorPKI* = ValidatorPrivKey|ValidatorPubKey|ValidatorSig
|
||||
BlsCurveType* = ValidatorPrivKey | ValidatorPubKey | ValidatorSig
|
||||
|
||||
BlsResult*[T] = Result[T, cstring]
|
||||
|
||||
func `==`*(a, b: BlsValue): bool =
|
||||
if a.kind != b.kind: return false
|
||||
|
@ -83,22 +76,22 @@ func `==`*(a, b: BlsValue): bool =
|
|||
else:
|
||||
return a.blob == b.blob
|
||||
|
||||
template `==`*[T](a: BlsValue[T], b: T): bool =
|
||||
template `==`*[N, T](a: BlsValue[N, T], b: T): bool =
|
||||
a.blsValue == b
|
||||
|
||||
template `==`*[T](a: T, b: BlsValue[T]): bool =
|
||||
template `==`*[N, T](a: T, b: BlsValue[N, T]): bool =
|
||||
a == b.blsValue
|
||||
|
||||
# API
|
||||
# ----------------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#bls-signatures
|
||||
|
||||
func pubKey*(privkey: ValidatorPrivKey): ValidatorPubKey =
|
||||
func toPubKey*(privkey: ValidatorPrivKey): ValidatorPubKey =
|
||||
## Create a private key from a public key
|
||||
# Un-specced in either hash-to-curve or Eth2
|
||||
# TODO: Test suite should use `keyGen` instead
|
||||
when ValidatorPubKey is BlsValue:
|
||||
ValidatorPubKey(kind: Real, blsValue: privkey.privToPub())
|
||||
ValidatorPubKey(kind: Real, blsValue: SecretKey(privkey).privToPub())
|
||||
elif ValidatorPubKey is array:
|
||||
privkey.getKey.getBytes
|
||||
else:
|
||||
|
@ -150,7 +143,7 @@ func blsVerify*(
|
|||
|
||||
func blsSign*(privkey: ValidatorPrivKey, message: openarray[byte]): ValidatorSig =
|
||||
## Computes a signature from a secret key and a message
|
||||
ValidatorSig(kind: Real, blsValue: privkey.sign(message))
|
||||
ValidatorSig(kind: Real, blsValue: SecretKey(privkey).sign(message))
|
||||
|
||||
func blsFastAggregateVerify*[T: byte|char](
|
||||
publicKeys: openarray[ValidatorPubKey],
|
||||
|
@ -184,7 +177,7 @@ func blsFastAggregateVerify*[T: byte|char](
|
|||
unwrapped.add pubkey.blsValue
|
||||
return fastAggregateVerify(unwrapped, message, signature.blsValue)
|
||||
|
||||
proc newKeyPair*(): tuple[pub: ValidatorPubKey, priv: ValidatorPrivKey] {.noInit.}=
|
||||
proc newKeyPair*(): BlsResult[tuple[pub: ValidatorPubKey, priv: ValidatorPrivKey]] =
|
||||
## Generates a new public-private keypair
|
||||
## This requires entropy on the system
|
||||
# The input-keying-material requires 32 bytes at least for security
|
||||
|
@ -192,28 +185,16 @@ proc newKeyPair*(): tuple[pub: ValidatorPubKey, priv: ValidatorPrivKey] {.noInit
|
|||
# must be protected against side-channel attacks
|
||||
|
||||
var ikm: array[32, byte]
|
||||
let written = randomBytes(ikm)
|
||||
doAssert written >= 32, "Key generation failure"
|
||||
if randomBytes(ikm) != 32:
|
||||
return err "bls: no random bytes"
|
||||
|
||||
result.pub = ValidatorPubKey(kind: Real)
|
||||
doAssert keyGen(ikm, result.pub.blsValue, result.priv), "Key generation failure"
|
||||
|
||||
# Logging
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
func shortLog*(x: BlsValue): string =
|
||||
## Logging for wrapped BLS types
|
||||
## that may contain valid or non-validated data
|
||||
# The prefix must be short
|
||||
# due to the mechanics of the `shortLog` function.
|
||||
if x.kind == Real:
|
||||
x.blsValue.toHex()[0..7]
|
||||
var
|
||||
sk: SecretKey
|
||||
pk: PublicKey
|
||||
if keyGen(ikm, pk, sk):
|
||||
ok((ValidatorPubKey(kind: Real, blsValue: pk), ValidatorPrivKey(sk)))
|
||||
else:
|
||||
"raw: " & x.blob.toHex(lowercase = true)[0..7]
|
||||
|
||||
func shortLog*(x: BlsCurveType): string =
|
||||
## Logging for raw unwrapped BLS types
|
||||
($x)[0..7]
|
||||
err "bls: cannot generate keypair"
|
||||
|
||||
proc toGaugeValue*(hash: Eth2Digest): int64 =
|
||||
# Only the last 8 bytes are taken into consideration in accordance
|
||||
|
@ -224,124 +205,139 @@ proc toGaugeValue*(hash: Eth2Digest): int64 =
|
|||
# Codecs
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
func `$`*(x: ValidatorPrivKey): string =
|
||||
"<private key>"
|
||||
|
||||
func `$`*(x: BlsValue): string =
|
||||
# The prefix must be short
|
||||
# due to the mechanics of the `shortLog` function.
|
||||
if x.kind == Real:
|
||||
x.blsValue.toHex()
|
||||
else:
|
||||
"raw: " & x.blob.toHex(lowercase = true)
|
||||
"raw: " & x.blob.toHex()
|
||||
|
||||
func getBytes*(x: BlsValue): auto =
|
||||
func toRaw*(x: ValidatorPrivKey): array[RawPrivKeySize, byte] =
|
||||
SecretKey(x).exportRaw()
|
||||
|
||||
func toRaw*(x: BlsValue): auto =
|
||||
if x.kind == Real:
|
||||
x.blsValue.exportRaw()
|
||||
else:
|
||||
x.blob
|
||||
|
||||
func initFromBytes[T](val: var BlsValue[T], bytes: openarray[byte]) =
|
||||
func toHex*(x: BlsCurveType): string =
|
||||
toHex(toRaw(x))
|
||||
|
||||
func fromRaw*(T: type ValidatorPrivKey, bytes: openarray[byte]): BlsResult[T] =
|
||||
var val: SecretKey
|
||||
if val.fromBytes(bytes):
|
||||
ok ValidatorPrivKey(val)
|
||||
else:
|
||||
err "bls: invalid private key"
|
||||
|
||||
func fromRaw*[N, T](BT: type BlsValue[N, T], bytes: openarray[byte]): BlsResult[BT] =
|
||||
# This is a workaround, so that we can deserialize the serialization of a
|
||||
# default-initialized BlsValue without raising an exception
|
||||
when defined(ssz_testing):
|
||||
# Only for SSZ parsing tests, everything is an opaque blob
|
||||
val = BlsValue[T](kind: OpaqueBlob, blob: toArray(val.blob.len, bytes))
|
||||
ok BT(kind: OpaqueBlob, blob: toArray(N, bytes))
|
||||
else:
|
||||
# Try if valid BLS value
|
||||
# TODO: address the side-effects in nim-blscurve
|
||||
val = BlsValue[T](kind: Real)
|
||||
let success = val.blsValue.fromBytes(bytes)
|
||||
if not success:
|
||||
# TODO: chronicles trace
|
||||
val = BlsValue[T](kind: OpaqueBlob)
|
||||
val.blob[val.blob.low .. val.blob.high] = bytes
|
||||
var val: T
|
||||
if fromBytes(val, bytes):
|
||||
ok BT(kind: Real, blsValue: val)
|
||||
else:
|
||||
ok BT(kind: OpaqueBlob, blob: toArray(N, bytes))
|
||||
|
||||
func initFromBytes*(val: var ValidatorPrivKey, bytes: openarray[byte]) {.inline.} =
|
||||
discard val.fromBytes(bytes)
|
||||
|
||||
func fromBytes[T](R: type BlsValue[T], bytes: openarray[byte]): R {.inline.}=
|
||||
result.initFromBytes(bytes)
|
||||
|
||||
func fromBytes[T](R: var BlsValue[T], bytes: openarray[byte]) {.inline.}=
|
||||
# This version is only to support tests/test_interop.nim
|
||||
R.initFromBytes(bytes)
|
||||
|
||||
func fromHex*[T](R: var BlsValue[T], hexStr: string) {.inline.} =
|
||||
func fromHex*(T: type BlsCurveType, hexStr: string): BlsResult[T] {.inline.} =
|
||||
## Initialize a BLSValue from its hex representation
|
||||
R.fromBytes(hexStr.hexToSeqByte())
|
||||
try:
|
||||
T.fromRaw(hexStr.hexToSeqByte())
|
||||
except ValueError:
|
||||
err "bls: cannot parse value"
|
||||
|
||||
# Hashing
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
func hash*(x: BlsValue): Hash {.inline.} =
|
||||
# TODO: we can probably just slice the BlsValue
|
||||
if x.kind == Real:
|
||||
hash x.blsValue.exportRaw()
|
||||
else:
|
||||
hash x.blob
|
||||
|
||||
template hash*(x: BlsCurveType): Hash =
|
||||
# TODO: prevent using secret keys
|
||||
bind getBytes
|
||||
hash(getBytes(x))
|
||||
bind toRaw
|
||||
hash(toRaw(x))
|
||||
|
||||
# Serialization
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
proc writeValue*(writer: var JsonWriter, value: ValidatorPubKey) {.inline.} =
|
||||
doAssert value.kind == Real
|
||||
writer.writeValue(value.blsValue.toHex())
|
||||
|
||||
proc readValue*(reader: var JsonReader, value: var ValidatorPubKey) {.inline.} =
|
||||
value.initFromBytes(fromHex reader.readValue(string))
|
||||
|
||||
proc writeValue*(writer: var JsonWriter, value: ValidatorSig) {.inline.} =
|
||||
if value.kind == Real:
|
||||
writer.writeValue(value.blsValue.toHex())
|
||||
else:
|
||||
# Workaround: https://github.com/status-im/nim-beacon-chain/issues/374
|
||||
let asHex = value.blob.toHex(lowercase = true)
|
||||
# echo "[Warning] writing raw opaque signature: ", asHex
|
||||
writer.writeValue(asHex)
|
||||
|
||||
proc readValue*(reader: var JsonReader, value: var ValidatorSig) {.inline.} =
|
||||
value.initFromBytes(fromHex reader.readValue(string))
|
||||
|
||||
proc writeValue*(writer: var JsonWriter, value: ValidatorPrivKey) {.inline.} =
|
||||
proc writeValue*(writer: var JsonWriter, value: ValidatorPubKey) {.
|
||||
inline, raises: [IOError, Defect].} =
|
||||
writer.writeValue(value.toHex())
|
||||
|
||||
proc readValue*(reader: var JsonReader, value: var ValidatorPrivKey) {.inline.} =
|
||||
value.initFromBytes(fromHex reader.readValue(string))
|
||||
proc readValue*(reader: var JsonReader, value: var ValidatorPubKey) {.
|
||||
inline, raises: [Exception].} =
|
||||
value = ValidatorPubKey.fromHex(reader.readValue(string)).tryGet()
|
||||
|
||||
proc writeValue*(writer: var JsonWriter, value: PublicKey) {.inline.} =
|
||||
proc writeValue*(writer: var JsonWriter, value: ValidatorSig) {.
|
||||
inline, raises: [IOError, Defect].} =
|
||||
# Workaround: https://github.com/status-im/nim-beacon-chain/issues/374
|
||||
writer.writeValue(value.toHex())
|
||||
|
||||
proc readValue*(reader: var JsonReader, value: var PublicKey) {.inline.} =
|
||||
let hex = reader.readValue(string)
|
||||
let ok = value.fromHex(hex)
|
||||
doAssert ok, "Invalid public key: " & hex
|
||||
proc readValue*(reader: var JsonReader, value: var ValidatorSig) {.
|
||||
inline, raises: [Exception].} =
|
||||
value = ValidatorSig.fromHex(reader.readValue(string)).tryGet()
|
||||
|
||||
proc writeValue*(writer: var JsonWriter, value: Signature) {.inline.} =
|
||||
proc writeValue*(writer: var JsonWriter, value: ValidatorPrivKey) {.
|
||||
inline, raises: [IOError, Defect].} =
|
||||
writer.writeValue(value.toHex())
|
||||
|
||||
proc readValue*(reader: var JsonReader, value: var Signature) {.inline.} =
|
||||
let hex = reader.readValue(string)
|
||||
let ok = value.fromHex(hex)
|
||||
doAssert ok, "Invalid signature: " & hex
|
||||
proc readValue*(reader: var JsonReader, value: var ValidatorPrivKey) {.
|
||||
inline, raises: [Exception].} =
|
||||
value = ValidatorPrivKey.fromHex(reader.readValue(string)).tryGet()
|
||||
|
||||
template fromSszBytes*(T: type BlsValue, bytes: openarray[byte]): auto =
|
||||
fromBytes(T, bytes)
|
||||
let v = fromRaw(T, bytes)
|
||||
if v.isErr:
|
||||
raise newException(MalformedSszError, $v.error)
|
||||
v[]
|
||||
|
||||
# Logging
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
func shortLog*(x: BlsValue): string =
|
||||
## Logging for wrapped BLS types
|
||||
## that may contain valid or non-validated data
|
||||
# The prefix must be short
|
||||
# due to the mechanics of the `shortLog` function.
|
||||
if x.kind == Real:
|
||||
x.blsValue.exportRaw()[0..3].toHex()
|
||||
else:
|
||||
"raw: " & x.blob[0..3].toHex()
|
||||
|
||||
func shortLog*(x: ValidatorPrivKey): string =
|
||||
## Logging for raw unwrapped BLS types
|
||||
x.toRaw()[0..3].toHex()
|
||||
|
||||
# Initialization
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
# TODO more specific exceptions? don't raise?
|
||||
|
||||
# For confutils
|
||||
func init*(T: typedesc[ValidatorPrivKey], hex: string): T {.noInit, inline.} =
|
||||
let success = result.fromHex(hex)
|
||||
doAssert success, "Private key is invalid" # Don't display private keys even if invalid
|
||||
func init*(T: typedesc[ValidatorPrivKey], hex: string): T {.noInit, raises: [ValueError, Defect].} =
|
||||
let v = T.fromHex(hex)
|
||||
if v.isErr:
|
||||
raise (ref ValueError)(msg: $v.error)
|
||||
return v[]
|
||||
|
||||
|
||||
# For mainchain monitor
|
||||
func init*(T: typedesc[ValidatorPubKey], data: array[48, byte]): T {.noInit, inline.} =
|
||||
result.initFromBytes(data)
|
||||
func init*(T: typedesc[ValidatorPubKey], data: array[RawPubKeySize, byte]): T {.noInit, raises: [ValueError, Defect].} =
|
||||
let v = T.fromRaw(data)
|
||||
if v.isErr:
|
||||
raise (ref ValueError)(msg: $v.error)
|
||||
return v[]
|
||||
|
||||
# For mainchain monitor
|
||||
func init*(T: typedesc[ValidatorSig], data: array[96, byte]): T {.noInit, inline.} =
|
||||
result.initFromBytes(data)
|
||||
func init*(T: typedesc[ValidatorSig], data: array[RawSigSize, byte]): T {.noInit, raises: [ValueError, Defect].} =
|
||||
let v = T.fromRaw(data)
|
||||
if v.isErr:
|
||||
raise (ref ValueError)(msg: $v.error)
|
||||
return v[]
|
||||
|
|
|
@ -80,8 +80,6 @@ const
|
|||
template maxSize*(n: int) {.pragma.}
|
||||
|
||||
type
|
||||
Bytes = seq[byte]
|
||||
|
||||
# Domains
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#domain-types
|
||||
|
@ -547,7 +545,7 @@ Json.useCustomSerialization(BitSeq):
|
|||
BitSeq reader.readValue(string).hexToSeqByte
|
||||
|
||||
write:
|
||||
writer.writeValue "0x" & Bytes(value).toHex
|
||||
writer.writeValue "0x" & seq[byte](value).toHex
|
||||
|
||||
template readValue*(reader: var JsonReader, value: var BitList) =
|
||||
type T = type(value)
|
||||
|
|
|
@ -19,13 +19,16 @@
|
|||
# (already did Blake2b --> Keccak256 --> SHA2-256),
|
||||
# we call this function `eth2hash`, and it outputs a `Eth2Digest`. Easy to sed :)
|
||||
|
||||
{.push raises: [Defect].}
|
||||
|
||||
import
|
||||
chronicles, json_serialization,
|
||||
nimcrypto/[sha2, hash, utils],
|
||||
chronicles,
|
||||
nimcrypto/[sha2, hash],
|
||||
stew/byteutils,
|
||||
hashes
|
||||
|
||||
export
|
||||
hash.`$`, json_serialization
|
||||
hash.`$`, sha2
|
||||
|
||||
type
|
||||
Eth2Digest* = MDigest[32 * 8] ## `hash32` from spec
|
||||
|
@ -33,10 +36,10 @@ type
|
|||
|
||||
chronicles.formatIt Eth2Digest:
|
||||
mixin toHex
|
||||
it.data[0..3].toHex(true)
|
||||
it.data[0..3].toHex()
|
||||
|
||||
func shortLog*(x: Eth2Digest): string =
|
||||
x.data[0..3].toHex(true)
|
||||
x.data[0..3].toHex()
|
||||
|
||||
# TODO: expose an in-place digest function
|
||||
# when hashing in loop or into a buffer
|
||||
|
@ -70,9 +73,3 @@ func hash*(x: Eth2Digest): Hash =
|
|||
# We just slice the first 4 or 8 bytes of the block hash
|
||||
# depending of if we are on a 32 or 64-bit platform
|
||||
result = cast[ptr Hash](unsafeAddr x)[]
|
||||
|
||||
proc writeValue*(writer: var JsonWriter, value: Eth2Digest) =
|
||||
writeValue(writer, value.data.toHex(true))
|
||||
|
||||
proc readValue*(reader: var JsonReader, value: var Eth2Digest) =
|
||||
value = Eth2Digest.fromHex(reader.readValue(string))
|
||||
|
|
|
@ -121,7 +121,7 @@ proc process_randao(
|
|||
# Mix it in
|
||||
let
|
||||
mix = get_randao_mix(state, epoch)
|
||||
rr = eth2hash(body.randao_reveal.getBytes()).data
|
||||
rr = eth2hash(body.randao_reveal.toRaw()).data
|
||||
|
||||
for i in 0 ..< mix.data.len:
|
||||
state.randao_mixes[epoch mod EPOCHS_PER_HISTORICAL_VECTOR].data[i] = mix.data[i] xor rr[i]
|
||||
|
|
|
@ -12,7 +12,6 @@ import
|
|||
stew/shims/macros, options, algorithm, options,
|
||||
stew/[bitops2, bitseqs, endians2, objects, varints, ptrops, ranges/ptr_arith], stint,
|
||||
faststreams/input_stream, serialization, serialization/testing/tracing,
|
||||
nimcrypto/sha2, blscurve,
|
||||
./spec/[crypto, datatypes, digest],
|
||||
./ssz/[types, bytes_reader]
|
||||
|
||||
|
@ -101,7 +100,7 @@ template toSszType*(x: auto): auto =
|
|||
|
||||
when x is Slot|Epoch|ValidatorIndex|enum: uint64(x)
|
||||
elif x is Eth2Digest: x.data
|
||||
elif x is BlsValue|BlsCurveType: getBytes(x)
|
||||
elif x is BlsCurveType: toRaw(x)
|
||||
elif x is BitSeq|BitList: ByteList(x)
|
||||
elif x is ref|ptr: toSszType x[]
|
||||
elif x is Option: toSszType x.get
|
||||
|
@ -390,7 +389,7 @@ func getFinalHash(merkelizer: SszChunksMerkelizer): Eth2Digest =
|
|||
|
||||
let HashingStreamVTable = OutputStreamVTable(
|
||||
writePage: proc (s: OutputStreamVar, data: openarray[byte])
|
||||
{.nimcall, gcsafe, raises: [IOError].} =
|
||||
{.nimcall, gcsafe, raises: [Defect, IOError].} =
|
||||
trs "ADDING STREAM CHUNK ", data
|
||||
SszChunksMerkelizer(s.outputDevice).addChunk(data)
|
||||
,
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
# now.
|
||||
|
||||
import
|
||||
collections/sets, chronicles, sets,
|
||||
chronicles, options,
|
||||
./extras, ./ssz, metrics,
|
||||
./spec/[datatypes, crypto, digest, helpers, validator],
|
||||
./spec/[state_transition_block, state_transition_epoch],
|
||||
|
|
|
@ -42,10 +42,10 @@ proc generateDeposits*(totalValidators: int,
|
|||
pubKey{.noInit.}: ValidatorPubKey
|
||||
|
||||
if randomKeys:
|
||||
(pubKey, privKey) = crypto.newKeyPair()
|
||||
(pubKey, privKey) = crypto.newKeyPair().tryGet()
|
||||
else:
|
||||
privKey = makeInteropPrivKey(i)
|
||||
pubKey = privKey.pubKey()
|
||||
pubKey = privKey.toPubKey()
|
||||
|
||||
let dp = makeDeposit(pubKey, privKey)
|
||||
|
||||
|
@ -73,9 +73,9 @@ proc sendDeposits*(
|
|||
for i, dp in deposits:
|
||||
let depositContract = web3.contractSender(DepositContract, contractAddress)
|
||||
discard await depositContract.deposit(
|
||||
Bytes48(dp.data.pubKey.getBytes()),
|
||||
Bytes48(dp.data.pubKey.toRaw()),
|
||||
Bytes32(dp.data.withdrawal_credentials.data),
|
||||
Bytes96(dp.data.signature.getBytes()),
|
||||
Bytes96(dp.data.signature.toRaw()),
|
||||
FixedBytes[32](hash_tree_root(dp.data).data)).send(value = 32.u256.ethToWei, gasPrice = 1)
|
||||
|
||||
when isMainModule:
|
||||
|
|
|
@ -16,7 +16,7 @@ import
|
|||
# (fully generic available - see also https://github.com/status-im/nim-beacon-chain/commit/993789bad684721bd7c74ea14b35c2d24dbb6e51)
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
proc `==`*[T](a, b: BlsValue[T]): bool =
|
||||
proc `==`*(a, b: BlsValue): bool =
|
||||
## We sometimes need to compare real BlsValue
|
||||
## from parsed opaque blobs that are not really on the BLS curve
|
||||
## and full of zeros
|
||||
|
|
|
@ -67,7 +67,7 @@ func mockDepositData(
|
|||
|
||||
# Insecurely use pubkey as withdrawal key
|
||||
deposit_data.withdrawal_credentials.data[0] = byte BLS_WITHDRAWAL_PREFIX
|
||||
deposit_data.withdrawal_credentials.data[1..^1] = pubkey.getBytes()
|
||||
deposit_data.withdrawal_credentials.data[1..^1] = pubkey.toRaw()
|
||||
.eth2hash()
|
||||
.data
|
||||
.toOpenArray(1, 31)
|
||||
|
|
|
@ -16,7 +16,7 @@ import
|
|||
# which is `num_validators` which is `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT`
|
||||
proc genMockPrivKeys(privkeys: var array[MIN_GENESIS_ACTIVE_VALIDATOR_COUNT, ValidatorPrivKey]) =
|
||||
for i in 0 ..< privkeys.len:
|
||||
let pair = newKeyPair()
|
||||
let pair = newKeyPair()[]
|
||||
privkeys[i] = pair.priv
|
||||
|
||||
proc genMockPubKeys(
|
||||
|
@ -24,7 +24,7 @@ proc genMockPubKeys(
|
|||
privkeys: array[MIN_GENESIS_ACTIVE_VALIDATOR_COUNT, ValidatorPrivKey]
|
||||
) =
|
||||
for i in 0 ..< privkeys.len:
|
||||
pubkeys[i] = pubkey(privkeys[i])
|
||||
pubkeys[i] = toPubKey(privkeys[i])
|
||||
|
||||
# Ref array necessary to limit stack usage / binary size
|
||||
var MockPrivKeys*: ref array[MIN_GENESIS_ACTIVE_VALIDATOR_COUNT, ValidatorPrivKey]
|
||||
|
@ -41,8 +41,6 @@ template `[]`*[N: static int](a: array[N, MockKey], idx: ValidatorIndex): MockKe
|
|||
a[idx.int]
|
||||
|
||||
when isMainModule:
|
||||
from blscurve import toHex
|
||||
|
||||
echo "========================================"
|
||||
echo "Mock keys"
|
||||
for i in 0 ..< MIN_GENESIS_ACTIVE_VALIDATOR_COUNT:
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
{.used.}
|
||||
|
||||
import
|
||||
unittest,
|
||||
unittest, chronicles,
|
||||
./testutil,
|
||||
../beacon_chain/spec/datatypes,
|
||||
../beacon_chain/[beacon_node_types, block_pool, ssz]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{.used.}
|
||||
|
||||
import
|
||||
unittest, stint, blscurve, ./testutil, stew/byteutils,
|
||||
unittest, stint, ./testutil, stew/byteutils,
|
||||
../beacon_chain/[extras, interop, ssz],
|
||||
../beacon_chain/spec/[beaconstate, crypto, datatypes]
|
||||
|
||||
|
@ -31,89 +31,87 @@ type DepositConfig = object
|
|||
# - https://github.com/status-im/eth2.0-specs/blob/c58096754b62389b0ea75dbdd717d362691b7c34/test_libs/pyspec/mockup_genesis.py
|
||||
# - "zcli genesis mock" https://github.com/protolambda/zcli
|
||||
|
||||
func fromHex(T: type[ValidatorSig], hex: string): T = result.fromhex(hex)
|
||||
|
||||
let depositsConfig = [
|
||||
DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x25295f0d1d592a90b333e26e85149708208e9f8e8bc18f6c77bd62f8ad7a6866"),
|
||||
signing_root: hexToByteArray[32]("139b510ea7f2788ab82da1f427d6cbe1db147c15a053db738ad5500cd83754a6"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"b796b670fa7eb04b4422bb0872b016895a6adffb1ebd1023db41452701ad65d6fa53d84f3b62e8753bf55230364c6aa318620b574528506ad78517f70c688b82d1c9ad0b12633e0fa5792cf58c21cee9ad25f74156eebd0b6dcd548b91db860f"
|
||||
sig: ValidatorSig.fromHex("b796b670fa7eb04b4422bb0872b016895a6adffb1ebd1023db41452701ad65d6fa53d84f3b62e8753bf55230364c6aa318620b574528506ad78517f70c688b82d1c9ad0b12633e0fa5792cf58c21cee9ad25f74156eebd0b6dcd548b91db860f")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x51d0b65185db6989ab0b560d6deed19c7ead0e24b9b6372cbecb1f26bdfad000"),
|
||||
signing_root: hexToByteArray[32]("bb4b6184b25873cdf430df3838c8d3e3d16cf3dc3b214e2f3ab7df9e6d5a9b52"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"98c4c6a7e12a2b4aeaa23a7d6ae4d2acabc8193d1c1cb53fabcb107ebcbd9c04189c4278995c62883507926712133d941677bd15407eefa49ea6c1cb97f4f7ee4efc3fe0bfa80e3efc3c6b48646b06e6bb845c4e0e7f21df58ef67147f0da7ea"
|
||||
sig: ValidatorSig.fromHex("98c4c6a7e12a2b4aeaa23a7d6ae4d2acabc8193d1c1cb53fabcb107ebcbd9c04189c4278995c62883507926712133d941677bd15407eefa49ea6c1cb97f4f7ee4efc3fe0bfa80e3efc3c6b48646b06e6bb845c4e0e7f21df58ef67147f0da7ea")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x315ed405fafe339603932eebe8dbfd650ce5dafa561f6928664c75db85f97857"),
|
||||
signing_root: hexToByteArray[32]("c6ddd74b1b45db17a864c87dd941cb6c6e16540c534cdbe1cc0d43e9a5d87f7c"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"8e6163059668ff2db1c8d430a1b0f9aeb330e8eaf680ed9709aaff5d437a54fb0144f2703cbb1e2a4a67c505b534718d0450d99203cccaf18e442bddd27e93ebfa289e6ce30a92e7befb656f12a01cb0204ffd14eed39ae457b7fad22faf8eab"
|
||||
sig: ValidatorSig.fromHex("8e6163059668ff2db1c8d430a1b0f9aeb330e8eaf680ed9709aaff5d437a54fb0144f2703cbb1e2a4a67c505b534718d0450d99203cccaf18e442bddd27e93ebfa289e6ce30a92e7befb656f12a01cb0204ffd14eed39ae457b7fad22faf8eab")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x25b1166a43c109cb330af8945d364722757c65ed2bfed5444b5a2f057f82d391"),
|
||||
signing_root: hexToByteArray[32]("9397cd33d4e8883dbdc1a1d7df410aa2b627740d11c5574697a2d483a50ab7bb"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"b389e7b4db5caccad6b0b32394b1e77a814e519f4d0789a1e4bb20e2f7f68d7787fe5f065181eeab72d31d847ae96abc0512466689eafbee0439ab7229fb14272654815f535759467e012d9ab7db6e3b3e86d9f73742c46993c755d1f2893684"
|
||||
sig: ValidatorSig.fromHex("b389e7b4db5caccad6b0b32394b1e77a814e519f4d0789a1e4bb20e2f7f68d7787fe5f065181eeab72d31d847ae96abc0512466689eafbee0439ab7229fb14272654815f535759467e012d9ab7db6e3b3e86d9f73742c46993c755d1f2893684")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x3f5615898238c4c4f906b507ee917e9ea1bb69b93f1dbd11a34d229c3b06784b"),
|
||||
signing_root: hexToByteArray[32]("27340cc0f3b76bcc89c78e67166c13a58c97c232889391d1387fc404c4f5255e"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"aeb410612b19c3176fa087fab3e56e278a01cf5ba5379aa7f4e7344dbfa9e3b3f91b6f39af463ce2e448787b0a77ee1a05f22c0d9afd2f0f6137232c432f83c26389c07a8348364ab8a745eda59ecf2aa65fa8eb3f18eacd10e5a8a2e71b1e06"
|
||||
sig: ValidatorSig.fromHex("aeb410612b19c3176fa087fab3e56e278a01cf5ba5379aa7f4e7344dbfa9e3b3f91b6f39af463ce2e448787b0a77ee1a05f22c0d9afd2f0f6137232c432f83c26389c07a8348364ab8a745eda59ecf2aa65fa8eb3f18eacd10e5a8a2e71b1e06")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x055794614bc85ed5436c1f5cab586aab6ca84835788621091f4f3b813761e7a8"),
|
||||
signing_root: hexToByteArray[32]("b8cf48542d8531ae59b56e175228e7fcb82415649b5e992e132d3234b31dda2f"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"b501a41ca61665dddbe248d2fa15e5498cb2b38dcf2093acd5768efeda1b0ac963e600d8e38c2c91964d8bf72fd197c71824c1d493272caf6140828f7f6b266281f044b4811bbd7ef0f57953b15399b4ef17af5b9c80df5c142600cf17bfee64"
|
||||
sig: ValidatorSig.fromHex("b501a41ca61665dddbe248d2fa15e5498cb2b38dcf2093acd5768efeda1b0ac963e600d8e38c2c91964d8bf72fd197c71824c1d493272caf6140828f7f6b266281f044b4811bbd7ef0f57953b15399b4ef17af5b9c80df5c142600cf17bfee64")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x1023c68852075965e0f7352dee3f76a84a83e7582c181c10179936c6d6348893"),
|
||||
signing_root: hexToByteArray[32]("5f919d91faecece67422edf573a507fc5f9720f4e37063cceb40aa3b371f1aa9"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"8f2e2de3c0504cc4d424de1593d508d7488bfc54f61882922b754e97e4faeebe4f24f19184f0630dc51327bc9ab26dd2073d55687f7284ab3395b770d7c4d35bb6e719e6881739e2f4f61e29e11c3b9e61529c202e30f5f5957544eeb0a9626e"
|
||||
sig: ValidatorSig.fromHex("8f2e2de3c0504cc4d424de1593d508d7488bfc54f61882922b754e97e4faeebe4f24f19184f0630dc51327bc9ab26dd2073d55687f7284ab3395b770d7c4d35bb6e719e6881739e2f4f61e29e11c3b9e61529c202e30f5f5957544eeb0a9626e")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x3a941600dc41e5d20e818473b817a28507c23cdfdb4b659c15461ee5c71e41f5"),
|
||||
signing_root: hexToByteArray[32]("d2ff8bfda7e7bcc64c636a4855d2a1eccb7f47379f526a753fd934ae37ba9ec7"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"90a83842b6d215f1da3ebf3eeea6c4bff0682ee3f7aa9d06bb818c716cfdb5cd577f997ddd606c908f7a68157f36ff660a0e73265f17cccbd23be5ed053b3812672ba52bce6ec034fadea3b78f46a9c6da88db6327a18a9bb3a7f2747185fc6f"
|
||||
sig: ValidatorSig.fromHex("90a83842b6d215f1da3ebf3eeea6c4bff0682ee3f7aa9d06bb818c716cfdb5cd577f997ddd606c908f7a68157f36ff660a0e73265f17cccbd23be5ed053b3812672ba52bce6ec034fadea3b78f46a9c6da88db6327a18a9bb3a7f2747185fc6f")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x066e3bdc0415530e5c7fed6382d5c822c192b620203cf669903e1810a8c67d06"),
|
||||
signing_root: hexToByteArray[32]("1e19687d32785632ddc9b6b319690ea45c0ea20d7bc8aacbd33f6ebbe30816e1"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"a232a8bb03ecd356cf0e18644077880afe7ecfc565c8627841797deb4dfce8366cc0d0f6e151b51c0acc05a66f1363d204e8133e772dfb4878c11f7bf14b8293ce734c37adca9c32cc2987f0bc34242cc30f139d86c44f8d4383af743be3d1ae"
|
||||
sig: ValidatorSig.fromHex("a232a8bb03ecd356cf0e18644077880afe7ecfc565c8627841797deb4dfce8366cc0d0f6e151b51c0acc05a66f1363d204e8133e772dfb4878c11f7bf14b8293ce734c37adca9c32cc2987f0bc34242cc30f139d86c44f8d4383af743be3d1ae")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x2b3b88a041168a1c4cd04bdd8de7964fd35238f95442dc678514f9dadb81ec34"),
|
||||
signing_root: hexToByteArray[32]("64a910a0a3e7da9a7a29ee2c92859314a160040ffb2042641fc56cba75b78012"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"8e0ccf7dd9dd00820a695161ea865220489ca48504012b7c36c85b3effb896a02ee9714a5e383f7105357a24f791562c1353e331d2cfa048cb94fd4fe42a008b18c5bdec6fcf7c8b75c5f5e582cd9571b308e8b1757d672fbb9092725985a716"
|
||||
sig: ValidatorSig.fromHex("8e0ccf7dd9dd00820a695161ea865220489ca48504012b7c36c85b3effb896a02ee9714a5e383f7105357a24f791562c1353e331d2cfa048cb94fd4fe42a008b18c5bdec6fcf7c8b75c5f5e582cd9571b308e8b1757d672fbb9092725985a716")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x2e62dbea7fe3127c3b236a92795dd633be51ee7cdfe5424882a2f355df497117"),
|
||||
signing_root: hexToByteArray[32]("5bf0c7a39df536b3c8a5dc550f0163af0b33a56b9454b5240cea9ad8356c4117"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"a07adeeb639a974fe3ae78a0a28785b195bffeaa2ec558c6baa63458daaf5b7a245940a2d9b91a993515295075eba4e115c6777eda1e7933cb53f64ab36619e49faadf289a8cc1521ca3ae5f9a3f2b88e355ef0b75dd8a9949c9d2a43c5589e0"
|
||||
sig: ValidatorSig.fromHex("a07adeeb639a974fe3ae78a0a28785b195bffeaa2ec558c6baa63458daaf5b7a245940a2d9b91a993515295075eba4e115c6777eda1e7933cb53f64ab36619e49faadf289a8cc1521ca3ae5f9a3f2b88e355ef0b75dd8a9949c9d2a43c5589e0")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x2042dc809c130e91906c9cb0be2fec0d6afaa8f22635efc7a3c2dbf833c1851a"),
|
||||
signing_root: hexToByteArray[32]("e8a45fa71addd854d8d78e0b2cdc8f9100c8a5e03d894c1c382068e8aa4b71e2"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"95719c0c4dae737aac602aeadf9faeb9ad3492450af249c43a1147a6e471ddb3f2b5979b6587e843d20c9caa8ecd83e8001b57a4f7c302927725966acc959eb6668357831b7a0692f2396a18939d9fa974e611beed4a7a59ffe892e77d2680bd"
|
||||
sig: ValidatorSig.fromHex("95719c0c4dae737aac602aeadf9faeb9ad3492450af249c43a1147a6e471ddb3f2b5979b6587e843d20c9caa8ecd83e8001b57a4f7c302927725966acc959eb6668357831b7a0692f2396a18939d9fa974e611beed4a7a59ffe892e77d2680bd")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x15283c540041cd85c4533ee47517c8bb101c6207e9acbba2935287405a78502c"),
|
||||
signing_root: hexToByteArray[32]("3dfab0daa3be9c72c5dd3b383e756d6048bb76cd3d09abb4dc991211ae8a547b"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"b8221ad674d7c23378b488555eb6e06ce56a342dad84ba6e3a57e108c1c426161b568a9366d82fd0059a23621922a1fc0e59d8eaa66dbb4611a173be167731367edf8daad3b07b64207faf3ea457a335228def3ca61571c4edc15dc392bf4e56"
|
||||
sig: ValidatorSig.fromHex("b8221ad674d7c23378b488555eb6e06ce56a342dad84ba6e3a57e108c1c426161b568a9366d82fd0059a23621922a1fc0e59d8eaa66dbb4611a173be167731367edf8daad3b07b64207faf3ea457a335228def3ca61571c4edc15dc392bf4e56")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x03c85e538e1bb30235a87a3758c5571753ca1308b7dee321b74c19f78423999b"),
|
||||
signing_root: hexToByteArray[32]("8905ae60c419e38f263eb818a5536e4144df3c0a800132e07594d457c62b5825"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"a5e61349958745c80862af84e06924748832cae379b02a50909468fef9f07f21d35a98e1287b6219528a1ad566567d0619e049efa9fa6e81410bb3a247cf53b0f6787f747f8229fb9f851290b140f14f14a2adcb23b7cafaf90b301d14169324"
|
||||
sig: ValidatorSig.fromHex("a5e61349958745c80862af84e06924748832cae379b02a50909468fef9f07f21d35a98e1287b6219528a1ad566567d0619e049efa9fa6e81410bb3a247cf53b0f6787f747f8229fb9f851290b140f14f14a2adcb23b7cafaf90b301d14169324")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x45a577d5cab31ac5cfff381500e09655f0799f29b130e6ad61c1eec4b15bf8dd"),
|
||||
signing_root: hexToByteArray[32]("702d1bd9c27c999923149f6c6578c835943b58b90845086bbf5be3b94aa4663d"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"893d8e70f2cdb6f7acc3d9828e72d7b20e512956588d8c068b3ef4aa649db369cf962506b7c9107246246d9b20361cd80250109da513809415314af3ef1f220c171dbc2d9c2b62056739703ae4eb1be13fa289ea8472920b2393041f69198dc5"
|
||||
sig: ValidatorSig.fromHex("893d8e70f2cdb6f7acc3d9828e72d7b20e512956588d8c068b3ef4aa649db369cf962506b7c9107246246d9b20361cd80250109da513809415314af3ef1f220c171dbc2d9c2b62056739703ae4eb1be13fa289ea8472920b2393041f69198dc5")[]
|
||||
), DepositConfig(
|
||||
privkey: ValidatorPrivKey.init("0x03cffafa1cbaa7e585eaee07a9d35ae57f6dfe19a9ea53af9c37e9f3dfac617c"),
|
||||
signing_root: hexToByteArray[32]("77f3da02c410e9ccba39d89983c52e6e77ca5dec3ae423311a578ee28b2ec0cd"),
|
||||
domain: DOMAIN_DEPOSIT,
|
||||
sig: ValidatorSig.fromHex"87ae1567999d3ceefce04c1a48aa189c3d368efbeda53c01962783941c03d3a26e08e5e9d287a927decf4e77755b97e80856e339c3af41dc5ffd373c6e4768de62718ce76cfd8c2062e7673c9eedd2fec235467967f932e59e0b3a32040c0038"
|
||||
sig: ValidatorSig.fromHex("87ae1567999d3ceefce04c1a48aa189c3d368efbeda53c01962783941c03d3a26e08e5e9d287a927decf4e77755b97e80856e339c3af41dc5ffd373c6e4768de62718ce76cfd8c2062e7673c9eedd2fec235467967f932e59e0b3a32040c0038")[]
|
||||
)
|
||||
]
|
||||
|
||||
|
@ -126,7 +124,7 @@ suiteReport "Interop":
|
|||
|
||||
check:
|
||||
# getBytes is bigendian and returns full 48 bytes of key..
|
||||
Uint256.fromBytesBE(key.exportRaw()[48-32..<48]) == v
|
||||
Uint256.fromBytesBE(key.toRaw()[48-32..<48]) == v
|
||||
|
||||
timedTest "Interop signatures":
|
||||
for dep in depositsConfig:
|
||||
|
@ -147,7 +145,7 @@ suiteReport "Interop":
|
|||
for i in 0..<64:
|
||||
let
|
||||
privKey = makeInteropPrivKey(i)
|
||||
deposits.add(makeDeposit(privKey.pubKey(), privKey))
|
||||
deposits.add(makeDeposit(privKey.toPubKey(), privKey))
|
||||
|
||||
const genesis_time = 1570500000
|
||||
var
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
{.used.}
|
||||
|
||||
import
|
||||
unittest, options,
|
||||
unittest, options, json_serialization,
|
||||
stint, nimcrypto, eth/common, serialization/testing/generic_suite,
|
||||
./testutil,
|
||||
../beacon_chain/spec/[datatypes, digest],
|
||||
|
|
|
@ -42,7 +42,7 @@ func makeDeposit(i: int, flags: UpdateFlags): Deposit =
|
|||
## for testing :)
|
||||
let
|
||||
privkey = makeFakeValidatorPrivKey(i)
|
||||
pubkey = privkey.pubKey()
|
||||
pubkey = privkey.toPubKey()
|
||||
withdrawal_credentials = makeFakeHash(i)
|
||||
domain = compute_domain(DOMAIN_DEPOSIT, GENESIS_FORK_VERSION)
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9ce0266e0a56e990b68d29d199080b16ae6288de
|
||||
Subproject commit eed3ae3c4c60caa2e6b9a12624c2f777ef963c32
|
|
@ -1 +1 @@
|
|||
Subproject commit b06a5b6e32aa4d5abf9c1019ab6728fa8f360cc5
|
||||
Subproject commit 5512e89d4cfc56745840c74f301e19c43cf84e5c
|
|
@ -1 +1 @@
|
|||
Subproject commit cd58cf69a0b883a4672cd3f79ee38ec0cf2c8c56
|
||||
Subproject commit 30d0ceaba02c0b966515f98873a0404786fbf796
|
Loading…
Reference in New Issue