Implement blob sidecar signatures (#5072)

* Implement blob sidecar signatures

* Update allTests
This commit is contained in:
henridf 2023-06-16 17:47:18 +02:00 committed by GitHub
parent 8eec6ab221
commit ae29babd9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 3 deletions

View File

@ -350,6 +350,7 @@ OK: 4/4 Fail: 0/4 Skip: 0/4
```diff
+ Aggregate and proof signatures OK
+ Attestation signatures OK
+ Blob sidecar signatures OK
+ Deposit signatures OK
+ Slot signatures OK
+ Sync committee message signatures OK
@ -357,7 +358,7 @@ OK: 4/4 Fail: 0/4 Skip: 0/4
+ Sync committee signed contribution and proof signatures OK
+ Voluntary exit signatures OK
```
OK: 8/8 Fail: 0/8 Skip: 0/8
OK: 9/9 Fail: 0/9 Skip: 0/9
## Network metadata
```diff
+ goerli OK
@ -690,4 +691,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
OK: 9/9 Fail: 0/9 Skip: 0/9
---TOTAL---
OK: 391/396 Fail: 0/396 Skip: 5/396
OK: 392/397 Fail: 0/397 Skip: 5/397

View File

@ -107,6 +107,15 @@ func get_block_signature*(
blsSign(privkey, signing_root.data)
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.3/specs/deneb/validator.md#constructing-the-signedblobsidecars
proc get_blob_sidecar_signature*(
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
blob: BlobSidecar, privkey: ValidatorPrivKey): CookedSig =
let signing_root = compute_blob_signing_root(
fork, genesis_validators_root, slot, blob)
blsSign(privkey, signing_root.data)
proc verify_block_signature*(
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
blck: Eth2Digest | SomeForkyBeaconBlock | BeaconBlockHeader,

View File

@ -615,6 +615,20 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork,
proofs)
await v.signData(web3SignerRequest)
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.3/specs/deneb/validator.md#constructing-the-signedblobsidecars
proc getBlobSignature*(v: AttachedValidator, fork: Fork,
genesis_validators_root: Eth2Digest, slot: Slot,
blob: BlobSidecar): Future[SignatureResult] {.async.} =
return
case v.kind
of ValidatorKind.Local:
SignatureResult.ok(
get_blob_sidecar_signature(
fork, genesis_validators_root, slot, blob,
v.data.privateKey).toValidatorSig())
of ValidatorKind.Remote:
return SignatureResult.err("web3signer not supported for blobs")
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/validator.md#aggregate-signature
proc getAttestationSignature*(v: AttachedValidator, fork: Fork,
genesis_validators_root: Eth2Digest,

View File

@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018-2021 Status Research & Development GmbH
# Copyright (c) 2018-2023 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -58,6 +58,36 @@ suite "Message signatures":
get_block_signature(
fork0, genesis_validators_root1, slot, root, privkey0).toValidatorSig)
test "Blob sidecar signatures":
let
slot = default(Slot)
blob = default(BlobSidecar)
check:
# Matching public/private keys and genesis validator roots
verify_blob_signature(
fork0, genesis_validators_root0, slot, blob, pubkey0,
get_blob_sidecar_signature(
fork0, genesis_validators_root0, slot, blob, privkey0).toValidatorSig)
# Mismatched public/private keys
not verify_blob_signature(
fork0, genesis_validators_root0, slot, blob, pubkey0,
get_blob_sidecar_signature(
fork0, genesis_validators_root0, slot, blob, privkey1).toValidatorSig)
# Mismatched forks
not verify_blob_signature(
fork0, genesis_validators_root0, slot, blob, pubkey0,
get_blob_sidecar_signature(
fork1, genesis_validators_root0, slot, blob, privkey0).toValidatorSig)
# Mismatched genesis validator roots
not verify_blob_signature(
fork0, genesis_validators_root0, slot, blob, pubkey0,
get_blob_sidecar_signature(
fork0, genesis_validators_root1, slot, blob, privkey0).toValidatorSig)
test "Aggregate and proof signatures":
let aggregate_and_proof = AggregateAndProof(
aggregate: Attestation(aggregation_bits: CommitteeValidatorsBits.init(8)))