Web3Signer support only for only Bellatrix and later (#5107)
Co-authored-by: Etan Kissling <etan@status.im>
This commit is contained in:
parent
dc5687093f
commit
d5a6d51ede
|
@ -369,14 +369,12 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
|
|||
OK: 3/3 Fail: 0/3 Skip: 0/3
|
||||
## Nimbus remote signer/signing test (verifying-web3signer)
|
||||
```diff
|
||||
+ Signing BeaconBlock (getBlockSignature(altair)) OK
|
||||
+ Signing BeaconBlock (getBlockSignature(bellatrix)) OK
|
||||
+ Signing BeaconBlock (getBlockSignature(capella)) OK
|
||||
+ Signing BeaconBlock (getBlockSignature(deneb)) OK
|
||||
+ Signing BeaconBlock (getBlockSignature(phase0)) OK
|
||||
+ Waiting for signing node (/upcheck) test OK
|
||||
```
|
||||
OK: 6/6 Fail: 0/6 Skip: 0/6
|
||||
OK: 4/4 Fail: 0/4 Skip: 0/4
|
||||
## Nimbus remote signer/signing test (web3signer)
|
||||
```diff
|
||||
+ Connection timeout test OK
|
||||
|
@ -384,11 +382,9 @@ OK: 6/6 Fail: 0/6 Skip: 0/6
|
|||
+ Idle connection test OK
|
||||
+ Public keys enumeration (/api/v1/eth2/publicKeys) test OK
|
||||
+ Public keys reload (/reload) test OK
|
||||
+ Signing BeaconBlock (getBlockSignature(altair)) OK
|
||||
+ Signing BeaconBlock (getBlockSignature(bellatrix)) OK
|
||||
+ Signing BeaconBlock (getBlockSignature(capella)) OK
|
||||
+ Signing BeaconBlock (getBlockSignature(deneb)) OK
|
||||
+ Signing BeaconBlock (getBlockSignature(phase0)) OK
|
||||
+ Signing SC contribution and proof (getContributionAndProofSignature()) OK
|
||||
+ Signing SC message (getSyncCommitteeMessage()) OK
|
||||
+ Signing SC selection proof (getSyncCommitteeSelectionProof()) OK
|
||||
|
@ -401,7 +397,7 @@ OK: 6/6 Fail: 0/6 Skip: 0/6
|
|||
+ Signing voluntary exit (getValidatorExitSignature()) OK
|
||||
+ Waiting for signing node (/upcheck) test OK
|
||||
```
|
||||
OK: 21/21 Fail: 0/21 Skip: 0/21
|
||||
OK: 19/19 Fail: 0/19 Skip: 0/19
|
||||
## Old database versions [Preset: mainnet]
|
||||
```diff
|
||||
+ pre-1.1.0 OK
|
||||
|
@ -692,4 +688,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
|
|||
OK: 9/9 Fail: 0/9 Skip: 0/9
|
||||
|
||||
---TOTAL---
|
||||
OK: 393/398 Fail: 0/398 Skip: 5/398
|
||||
OK: 389/394 Fail: 0/394 Skip: 5/394
|
||||
|
|
|
@ -219,10 +219,9 @@ proc installApiHandlers*(node: SigningNodeRef) =
|
|||
let
|
||||
forkInfo = request.forkInfo.get()
|
||||
blockRoot = hash_tree_root(request.beaconBlock)
|
||||
signature = withBlck(request.beaconBlock):
|
||||
get_block_signature(forkInfo.fork,
|
||||
forkInfo.genesis_validators_root, blck.slot, blockRoot,
|
||||
validator.data.privateKey).toValidatorSig().toHex()
|
||||
signature = get_block_signature(forkInfo.fork,
|
||||
forkInfo.genesis_validators_root, request.beaconBlock.data.slot,
|
||||
blockRoot, validator.data.privateKey).toValidatorSig().toHex()
|
||||
return signatureResponse(Http200, signature)
|
||||
|
||||
let (feeRecipientIndex, blockHeader) =
|
||||
|
@ -231,12 +230,10 @@ proc installApiHandlers*(node: SigningNodeRef) =
|
|||
# `phase0` and `altair` blocks do not have `fee_recipient`, so
|
||||
# we return an error.
|
||||
return errorResponse(Http400, BlockIncorrectFork)
|
||||
of ConsensusFork.Bellatrix:
|
||||
(GeneralizedIndex(401), request.beaconBlock.bellatrixData)
|
||||
of ConsensusFork.Capella:
|
||||
(GeneralizedIndex(401), request.beaconBlock.capellaData)
|
||||
of ConsensusFork.Bellatrix, ConsensusFork.Capella:
|
||||
(GeneralizedIndex(401), request.beaconBlock.data)
|
||||
of ConsensusFork.Deneb:
|
||||
(GeneralizedIndex(801), request.beaconBlock.denebData)
|
||||
(GeneralizedIndex(801), request.beaconBlock.data)
|
||||
|
||||
if request.proofs.isNone() or len(request.proofs.get()) == 0:
|
||||
return errorResponse(Http400, MissingMerkleProofError)
|
||||
|
@ -258,10 +255,9 @@ proc installApiHandlers*(node: SigningNodeRef) =
|
|||
let
|
||||
forkInfo = request.forkInfo.get()
|
||||
blockRoot = hash_tree_root(request.beaconBlock)
|
||||
signature = withBlck(request.beaconBlock):
|
||||
get_block_signature(forkInfo.fork,
|
||||
forkInfo.genesis_validators_root, blck.slot, blockRoot,
|
||||
validator.data.privateKey).toValidatorSig().toHex()
|
||||
signature = get_block_signature(forkInfo.fork,
|
||||
forkInfo.genesis_validators_root, request.beaconBlock.data.slot,
|
||||
blockRoot, validator.data.privateKey).toValidatorSig().toHex()
|
||||
signatureResponse(Http200, signature)
|
||||
of Web3SignerRequestKind.Deposit:
|
||||
let
|
||||
|
|
|
@ -1200,103 +1200,30 @@ proc readValue*[BlockType: Web3SignerForkedBeaconBlock](
|
|||
prepareForkedBlockReading(reader, version, data,
|
||||
"Web3SignerForkedBeaconBlock")
|
||||
|
||||
case version.get():
|
||||
of ConsensusFork.Phase0:
|
||||
let res =
|
||||
try:
|
||||
some(RestJson.decode(string(data.get()),
|
||||
phase0.BeaconBlock,
|
||||
requireAllFields = true,
|
||||
allowUnknownFields = true))
|
||||
except SerializationError:
|
||||
none[phase0.BeaconBlock]()
|
||||
if res.isNone():
|
||||
reader.raiseUnexpectedValue("Incorrect phase0 block format")
|
||||
value = Web3SignerForkedBeaconBlock(
|
||||
kind: ConsensusFork.Phase0,
|
||||
phase0Data: res.get())
|
||||
of ConsensusFork.Altair:
|
||||
let res =
|
||||
try:
|
||||
some(RestJson.decode(string(data.get()),
|
||||
altair.BeaconBlock,
|
||||
requireAllFields = true,
|
||||
allowUnknownFields = true))
|
||||
except SerializationError:
|
||||
none[altair.BeaconBlock]()
|
||||
if res.isNone():
|
||||
reader.raiseUnexpectedValue("Incorrect altair block format")
|
||||
value = Web3SignerForkedBeaconBlock(
|
||||
kind: ConsensusFork.Altair,
|
||||
altairData: res.get())
|
||||
of ConsensusFork.Bellatrix:
|
||||
let res =
|
||||
try:
|
||||
some(RestJson.decode(string(data.get()),
|
||||
BeaconBlockHeader,
|
||||
requireAllFields = true,
|
||||
allowUnknownFields = true))
|
||||
except SerializationError:
|
||||
none[BeaconBlockHeader]()
|
||||
if res.isNone():
|
||||
reader.raiseUnexpectedValue("Incorrect bellatrix block format")
|
||||
value = Web3SignerForkedBeaconBlock(
|
||||
kind: ConsensusFork.Bellatrix,
|
||||
bellatrixData: res.get())
|
||||
of ConsensusFork.Capella:
|
||||
let res =
|
||||
try:
|
||||
some(RestJson.decode(string(data.get()),
|
||||
BeaconBlockHeader,
|
||||
requireAllFields = true,
|
||||
allowUnknownFields = true))
|
||||
except SerializationError:
|
||||
none[BeaconBlockHeader]()
|
||||
if res.isNone():
|
||||
reader.raiseUnexpectedValue("Incorrect capella block format")
|
||||
value = Web3SignerForkedBeaconBlock(
|
||||
kind: ConsensusFork.Capella,
|
||||
capellaData: res.get())
|
||||
of ConsensusFork.Deneb:
|
||||
let res =
|
||||
try:
|
||||
some(RestJson.decode(string(data.get()),
|
||||
BeaconBlockHeader,
|
||||
requireAllFields = true,
|
||||
allowUnknownFields = true))
|
||||
except SerializationError:
|
||||
none[BeaconBlockHeader]()
|
||||
if res.isNone():
|
||||
reader.raiseUnexpectedValue("Incorrect deneb block format")
|
||||
value = Web3SignerForkedBeaconBlock(
|
||||
kind: ConsensusFork.Deneb,
|
||||
denebData: res.get())
|
||||
let res =
|
||||
try:
|
||||
some(RestJson.decode(string(data.get()),
|
||||
BeaconBlockHeader,
|
||||
requireAllFields = true,
|
||||
allowUnknownFields = true))
|
||||
except SerializationError:
|
||||
none[BeaconBlockHeader]()
|
||||
if res.isNone():
|
||||
reader.raiseUnexpectedValue("Incorrect block header format")
|
||||
if version.get() <= ConsensusFork.Altair:
|
||||
reader.raiseUnexpectedValue(
|
||||
"Web3Signer implementation supports Bellatrix and newer")
|
||||
value = Web3SignerForkedBeaconBlock(kind: version.get(), data: res.get())
|
||||
|
||||
proc writeValue*[
|
||||
BlockType: Web3SignerForkedBeaconBlock](
|
||||
writer: var JsonWriter[RestJson],
|
||||
value: BlockType) {.raises: [IOError, Defect].} =
|
||||
template forkIdentifier(id: string): auto = (static toUpperAscii id)
|
||||
|
||||
# https://consensys.github.io/web3signer/web3signer-eth2.html#tag/Signing/operation/ETH2_SIGN
|
||||
# https://github.com/ConsenSys/web3signer/blob/d51337e96ba5ce410222943556bed7c4856b8e57/core/src/main/java/tech/pegasys/web3signer/core/service/http/handlers/signing/eth2/json/BlockRequestDeserializer.java#L42-L58
|
||||
writer.beginRecord()
|
||||
case value.kind
|
||||
of ConsensusFork.Phase0:
|
||||
writer.writeField("version", forkIdentifier "phase0")
|
||||
writer.writeField("block", value.phase0Data)
|
||||
of ConsensusFork.Altair:
|
||||
writer.writeField("version", forkIdentifier "altair")
|
||||
writer.writeField("block", value.altairData)
|
||||
of ConsensusFork.Bellatrix:
|
||||
writer.writeField("version", forkIdentifier "bellatrix")
|
||||
writer.writeField("block_header", value.bellatrixData)
|
||||
of ConsensusFork.Capella:
|
||||
writer.writeField("version", forkIdentifier "capella")
|
||||
writer.writeField("block_header", value.capellaData)
|
||||
of ConsensusFork.Deneb:
|
||||
writer.writeField("version", forkIdentifier "deneb")
|
||||
writer.writeField("block_header", value.denebData)
|
||||
writer.writeField("version", value.kind.toString.toUpperAscii)
|
||||
writer.writeField("block", value.data)
|
||||
writer.endRecord()
|
||||
|
||||
proc writeValue*[
|
||||
|
|
|
@ -146,12 +146,8 @@ type
|
|||
of ConsensusFork.Deneb: denebData*: deneb.BeaconBlock
|
||||
|
||||
Web3SignerForkedBeaconBlock* = object
|
||||
case kind*: ConsensusFork
|
||||
of ConsensusFork.Phase0: phase0Data*: phase0.BeaconBlock
|
||||
of ConsensusFork.Altair: altairData*: altair.BeaconBlock
|
||||
of ConsensusFork.Bellatrix: bellatrixData*: BeaconBlockHeader
|
||||
of ConsensusFork.Capella: capellaData*: BeaconBlockHeader
|
||||
of ConsensusFork.Deneb: denebData*: BeaconBlockHeader
|
||||
kind*: ConsensusFork
|
||||
data*: BeaconBlockHeader
|
||||
|
||||
ForkedBlindedBeaconBlock* = object
|
||||
case kind*: ConsensusFork
|
||||
|
@ -739,7 +735,7 @@ template asTrusted*(
|
|||
isomorphicCast[ref ForkedTrustedSignedBeaconBlock](x)
|
||||
|
||||
template withBlck*(
|
||||
x: ForkedBeaconBlock | Web3SignerForkedBeaconBlock |
|
||||
x: ForkedBeaconBlock |
|
||||
ForkedSignedBeaconBlock | ForkedMsgTrustedSignedBeaconBlock |
|
||||
ForkedTrustedSignedBeaconBlock | ForkedBlindedBeaconBlock |
|
||||
ForkedSignedBlindedBeaconBlock,
|
||||
|
@ -769,10 +765,12 @@ template withBlck*(
|
|||
func proposer_index*(x: ForkedBeaconBlock): uint64 =
|
||||
withBlck(x): blck.proposer_index
|
||||
|
||||
func hash_tree_root*(x: ForkedBeaconBlock | Web3SignerForkedBeaconBlock):
|
||||
Eth2Digest =
|
||||
func hash_tree_root*(x: ForkedBeaconBlock): Eth2Digest =
|
||||
withBlck(x): hash_tree_root(blck)
|
||||
|
||||
func hash_tree_root*(x: Web3SignerForkedBeaconBlock): Eth2Digest =
|
||||
hash_tree_root(x.data)
|
||||
|
||||
template getForkedBlockField*(
|
||||
x: ForkedSignedBeaconBlock |
|
||||
ForkedMsgTrustedSignedBeaconBlock |
|
||||
|
|
|
@ -470,148 +470,118 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork,
|
|||
let web3SignerRequest =
|
||||
when blck is ForkedBlindedBeaconBlock:
|
||||
case blck.kind
|
||||
of ConsensusFork.Phase0:
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Phase0,
|
||||
phase0Data: blck.phase0Data))
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
return SignatureResult.err("Invalid beacon block fork version")
|
||||
of ConsensusFork.Altair:
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Altair,
|
||||
altairData: blck.altairData))
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
return SignatureResult.err("Invalid beacon block fork version")
|
||||
of ConsensusFork.Phase0, ConsensusFork.Altair:
|
||||
return SignatureResult.err("Invalid beacon block fork version")
|
||||
of ConsensusFork.Bellatrix:
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Bellatrix,
|
||||
bellatrixData: blck.bellatrixData.toBeaconBlockHeader))
|
||||
data: blck.bellatrixData.toBeaconBlockHeader))
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
let proofs = blockPropertiesProofs(
|
||||
blck.bellatrixData.body, bellatrixIndex)
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Bellatrix,
|
||||
bellatrixData: blck.bellatrixData.toBeaconBlockHeader),
|
||||
data: blck.bellatrixData.toBeaconBlockHeader),
|
||||
proofs)
|
||||
of ConsensusFork.Capella:
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Capella,
|
||||
capellaData: blck.capellaData.toBeaconBlockHeader))
|
||||
data: blck.capellaData.toBeaconBlockHeader))
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
let proofs = blockPropertiesProofs(
|
||||
blck.capellaData.body, capellaIndex)
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Capella,
|
||||
capellaData: blck.capellaData.toBeaconBlockHeader),
|
||||
data: blck.capellaData.toBeaconBlockHeader),
|
||||
proofs)
|
||||
of ConsensusFork.Deneb:
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Deneb,
|
||||
denebData: blck.denebData.toBeaconBlockHeader))
|
||||
data: blck.denebData.toBeaconBlockHeader))
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
let proofs = blockPropertiesProofs(
|
||||
blck.denebData.body, denebIndex)
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Deneb,
|
||||
denebData: blck.denebData.toBeaconBlockHeader),
|
||||
data: blck.denebData.toBeaconBlockHeader),
|
||||
proofs)
|
||||
elif blck is bellatrix_mev.BlindedBeaconBlock:
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Bellatrix,
|
||||
bellatrixData: blck.toBeaconBlockHeader)
|
||||
data: blck.toBeaconBlockHeader)
|
||||
)
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
let proofs = blockPropertiesProofs(
|
||||
blck.body, bellatrixIndex)
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Bellatrix,
|
||||
bellatrixData: blck.toBeaconBlockHeader),
|
||||
data: blck.toBeaconBlockHeader),
|
||||
proofs)
|
||||
elif blck is capella_mev.BlindedBeaconBlock:
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Capella,
|
||||
capellaData: blck.toBeaconBlockHeader))
|
||||
data: blck.toBeaconBlockHeader))
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
let proofs = blockPropertiesProofs(
|
||||
blck.body, capellaIndex)
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Capella,
|
||||
capellaData: blck.toBeaconBlockHeader),
|
||||
data: blck.toBeaconBlockHeader),
|
||||
proofs)
|
||||
else:
|
||||
# There should be a deneb_mev module just like the ones above
|
||||
discard denebImplementationMissing
|
||||
case blck.kind
|
||||
of ConsensusFork.Phase0:
|
||||
# In case of `phase0` block we did not send merkle proof.
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Phase0,
|
||||
phase0Data: blck.phase0Data))
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
return SignatureResult.err("Invalid beacon block fork version")
|
||||
of ConsensusFork.Altair:
|
||||
# In case of `altair` block we did not send merkle proof.
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Altair,
|
||||
altairData: blck.altairData))
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
return SignatureResult.err("Invalid beacon block fork version")
|
||||
of ConsensusFork.Phase0, ConsensusFork.Altair:
|
||||
return SignatureResult.err("Invalid beacon block fork version")
|
||||
of ConsensusFork.Bellatrix:
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Bellatrix,
|
||||
bellatrixData: blck.bellatrixData.toBeaconBlockHeader))
|
||||
data: blck.bellatrixData.toBeaconBlockHeader))
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
let proofs = blockPropertiesProofs(
|
||||
blck.bellatrixData.body, bellatrixIndex)
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Bellatrix,
|
||||
bellatrixData: blck.bellatrixData.toBeaconBlockHeader),
|
||||
data: blck.bellatrixData.toBeaconBlockHeader),
|
||||
proofs)
|
||||
of ConsensusFork.Capella:
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Capella,
|
||||
capellaData: blck.capellaData.toBeaconBlockHeader))
|
||||
data: blck.capellaData.toBeaconBlockHeader))
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
let proofs = blockPropertiesProofs(
|
||||
blck.capellaData.body, capellaIndex)
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Capella,
|
||||
capellaData: blck.capellaData.toBeaconBlockHeader),
|
||||
data: blck.capellaData.toBeaconBlockHeader),
|
||||
proofs)
|
||||
of ConsensusFork.Deneb:
|
||||
case v.data.remoteType
|
||||
of RemoteSignerType.Web3Signer:
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Deneb,
|
||||
denebData: blck.denebData.toBeaconBlockHeader))
|
||||
data: blck.denebData.toBeaconBlockHeader))
|
||||
of RemoteSignerType.VerifyingWeb3Signer:
|
||||
let proofs = blockPropertiesProofs(
|
||||
blck.denebData.body, denebIndex)
|
||||
Web3SignerRequest.init(fork, genesis_validators_root,
|
||||
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Deneb,
|
||||
denebData: blck.denebData.toBeaconBlockHeader),
|
||||
data: blck.denebData.toBeaconBlockHeader),
|
||||
proofs)
|
||||
await v.signData(web3SignerRequest)
|
||||
|
||||
|
|
|
@ -116,26 +116,20 @@ proc getBlock(fork: ConsensusFork,
|
|||
proc init(t: typedesc[Web3SignerForkedBeaconBlock],
|
||||
forked: ForkedBeaconBlock): Web3SignerForkedBeaconBlock =
|
||||
case forked.kind
|
||||
of ConsensusFork.Phase0:
|
||||
Web3SignerForkedBeaconBlock(
|
||||
kind: ConsensusFork.Phase0,
|
||||
phase0Data: forked.phase0Data)
|
||||
of ConsensusFork.Altair:
|
||||
Web3SignerForkedBeaconBlock(
|
||||
kind: ConsensusFork.Altair,
|
||||
altairData: forked.altairData)
|
||||
of ConsensusFork.Phase0, ConsensusFork.Altair:
|
||||
raiseAssert "supports Bellatrix and later forks"
|
||||
of ConsensusFork.Bellatrix:
|
||||
Web3SignerForkedBeaconBlock(
|
||||
kind: ConsensusFork.Bellatrix,
|
||||
bellatrixData: forked.bellatrixData.toBeaconBlockHeader)
|
||||
data: forked.bellatrixData.toBeaconBlockHeader)
|
||||
of ConsensusFork.Capella:
|
||||
Web3SignerForkedBeaconBlock(
|
||||
kind: ConsensusFork.Capella,
|
||||
capellaData: forked.capellaData.toBeaconBlockHeader)
|
||||
data: forked.capellaData.toBeaconBlockHeader)
|
||||
of ConsensusFork.Deneb:
|
||||
Web3SignerForkedBeaconBlock(
|
||||
kind: ConsensusFork.Deneb,
|
||||
denebData: forked.denebData.toBeaconBlockHeader)
|
||||
data: forked.denebData.toBeaconBlockHeader)
|
||||
|
||||
proc createKeystore(dataDir, pubkey,
|
||||
store, password: string): Result[void, string] =
|
||||
|
@ -764,76 +758,6 @@ suite "Nimbus remote signer/signing test (web3signer)":
|
|||
sres2.get() == rres2.get()
|
||||
sres3.get() == rres3.get()
|
||||
|
||||
asyncTest "Signing BeaconBlock (getBlockSignature(phase0))":
|
||||
let
|
||||
forked = getBlock(ConsensusFork.Phase0)
|
||||
blockRoot = withBlck(forked): hash_tree_root(blck)
|
||||
|
||||
sres1 =
|
||||
await validator1.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
sres2 =
|
||||
await validator2.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
sres3 =
|
||||
await validator3.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
rres1 =
|
||||
await validator4.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
rres2 =
|
||||
await validator5.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
rres3 =
|
||||
await validator6.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
|
||||
check:
|
||||
sres1.isOk()
|
||||
sres2.isOk()
|
||||
sres3.isOk()
|
||||
rres1.isOk()
|
||||
rres2.isOk()
|
||||
rres3.isOk()
|
||||
sres1.get() == rres1.get()
|
||||
sres2.get() == rres2.get()
|
||||
sres3.get() == rres3.get()
|
||||
|
||||
asyncTest "Signing BeaconBlock (getBlockSignature(altair))":
|
||||
let
|
||||
forked = getBlock(ConsensusFork.Altair)
|
||||
blockRoot = withBlck(forked): hash_tree_root(blck)
|
||||
|
||||
sres1 =
|
||||
await validator1.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
sres2 =
|
||||
await validator2.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
sres3 =
|
||||
await validator3.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
rres1 =
|
||||
await validator4.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
rres2 =
|
||||
await validator5.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
rres3 =
|
||||
await validator6.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot, forked)
|
||||
|
||||
check:
|
||||
sres1.isOk()
|
||||
sres2.isOk()
|
||||
sres3.isOk()
|
||||
rres1.isOk()
|
||||
rres2.isOk()
|
||||
rres3.isOk()
|
||||
sres1.get() == rres1.get()
|
||||
sres2.get() == rres2.get()
|
||||
sres3.get() == rres3.get()
|
||||
|
||||
asyncTest "Signing BeaconBlock (getBlockSignature(bellatrix))":
|
||||
let
|
||||
forked = getBlock(ConsensusFork.Bellatrix)
|
||||
|
@ -1161,180 +1085,6 @@ suite "Nimbus remote signer/signing test (verifying-web3signer)":
|
|||
|
||||
await client.closeWait()
|
||||
|
||||
asyncTest "Signing BeaconBlock (getBlockSignature(phase0))":
|
||||
let
|
||||
fork = ConsensusFork.Phase0
|
||||
forked1 = getBlock(fork)
|
||||
blockRoot1 = withBlck(forked1): hash_tree_root(blck)
|
||||
forked2 = getBlock(fork, SigningOtherFeeRecipient)
|
||||
blockRoot2 = withBlck(forked2): hash_tree_root(blck)
|
||||
request1 = Web3SignerRequest.init(SigningFork, GenesisValidatorsRoot,
|
||||
Web3SignerForkedBeaconBlock.init(forked1))
|
||||
request2 = Web3SignerRequest.init(SigningFork, GenesisValidatorsRoot,
|
||||
Web3SignerForkedBeaconBlock.init(forked1), @[])
|
||||
remoteUrl = "http://" & SigningNodeAddress & ":" &
|
||||
$getNodePort(basePort, RemoteSignerType.VerifyingWeb3Signer)
|
||||
prestoFlags = {RestClientFlag.CommaSeparatedArray}
|
||||
rclient = RestClientRef.new(remoteUrl, prestoFlags, {})
|
||||
publicKey1 = ValidatorPubKey.fromHex(ValidatorPubKey1).get()
|
||||
publicKey2 = ValidatorPubKey.fromHex(ValidatorPubKey2).get()
|
||||
publicKey3 = ValidatorPubKey.fromHex(ValidatorPubKey3).get()
|
||||
|
||||
check rclient.isOk()
|
||||
|
||||
let
|
||||
client = rclient.get()
|
||||
sres1 =
|
||||
await validator1.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
sres2 =
|
||||
await validator2.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
sres3 =
|
||||
await validator3.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
rres1 =
|
||||
await validator4.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
rres2 =
|
||||
await validator5.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
rres3 =
|
||||
await validator6.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
bres1 =
|
||||
await validator4.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot2, forked2)
|
||||
bres2 =
|
||||
await validator5.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot2, forked2)
|
||||
bres3 =
|
||||
await validator6.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot2, forked2)
|
||||
|
||||
check:
|
||||
# Local requests
|
||||
sres1.isOk()
|
||||
sres2.isOk()
|
||||
sres3.isOk()
|
||||
# Phase0 blocks do not have FeeRecipient field, so it should not care
|
||||
rres1.isErr()
|
||||
rres2.isErr()
|
||||
rres3.isErr()
|
||||
# Phase0 blocks do not have FeeRecipient field, so it should not care
|
||||
bres1.isErr()
|
||||
bres2.isErr()
|
||||
bres3.isErr()
|
||||
|
||||
try:
|
||||
let
|
||||
# `proofs` array is not present.
|
||||
response1 = await client.signDataPlain(publicKey1, request1)
|
||||
response2 = await client.signDataPlain(publicKey2, request1)
|
||||
response3 = await client.signDataPlain(publicKey3, request1)
|
||||
# `proofs` array is empty.
|
||||
response4 = await client.signDataPlain(publicKey1, request2)
|
||||
response5 = await client.signDataPlain(publicKey2, request2)
|
||||
response6 = await client.signDataPlain(publicKey3, request2)
|
||||
check:
|
||||
# When `Phase0` block specified remote signer should ignore `proof`
|
||||
# field and its value
|
||||
response1.status == 400
|
||||
response2.status == 400
|
||||
response3.status == 400
|
||||
response4.status == 400
|
||||
response5.status == 400
|
||||
response6.status == 400
|
||||
finally:
|
||||
await client.closeWait()
|
||||
|
||||
asyncTest "Signing BeaconBlock (getBlockSignature(altair))":
|
||||
let
|
||||
fork = ConsensusFork.Altair
|
||||
forked1 = getBlock(fork)
|
||||
blockRoot1 = withBlck(forked1): hash_tree_root(blck)
|
||||
forked2 = getBlock(fork, SigningOtherFeeRecipient)
|
||||
blockRoot2 = withBlck(forked2): hash_tree_root(blck)
|
||||
request1 = Web3SignerRequest.init(SigningFork, GenesisValidatorsRoot,
|
||||
Web3SignerForkedBeaconBlock.init(forked1))
|
||||
request2 = Web3SignerRequest.init(SigningFork, GenesisValidatorsRoot,
|
||||
Web3SignerForkedBeaconBlock.init(forked1), @[])
|
||||
remoteUrl = "http://" & SigningNodeAddress & ":" &
|
||||
$getNodePort(basePort, RemoteSignerType.VerifyingWeb3Signer)
|
||||
prestoFlags = {RestClientFlag.CommaSeparatedArray}
|
||||
rclient = RestClientRef.new(remoteUrl, prestoFlags, {})
|
||||
publicKey1 = ValidatorPubKey.fromHex(ValidatorPubKey1).get()
|
||||
publicKey2 = ValidatorPubKey.fromHex(ValidatorPubKey2).get()
|
||||
publicKey3 = ValidatorPubKey.fromHex(ValidatorPubKey3).get()
|
||||
|
||||
check rclient.isOk()
|
||||
|
||||
let
|
||||
client = rclient.get()
|
||||
sres1 =
|
||||
await validator1.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
sres2 =
|
||||
await validator2.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
sres3 =
|
||||
await validator3.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
rres1 =
|
||||
await validator4.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
rres2 =
|
||||
await validator5.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
rres3 =
|
||||
await validator6.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot1, forked1)
|
||||
bres1 =
|
||||
await validator4.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot2, forked2)
|
||||
bres2 =
|
||||
await validator5.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot2, forked2)
|
||||
bres3 =
|
||||
await validator6.getBlockSignature(SigningFork, GenesisValidatorsRoot,
|
||||
Slot(1), blockRoot2, forked2)
|
||||
|
||||
check:
|
||||
# Local requests
|
||||
sres1.isOk()
|
||||
sres2.isOk()
|
||||
sres3.isOk()
|
||||
# Altair block do not have FeeRecipient field, so it should not care
|
||||
rres1.isErr()
|
||||
rres2.isErr()
|
||||
rres3.isErr()
|
||||
# Altair block do not have FeeRecipient field, so it should not care
|
||||
bres1.isErr()
|
||||
bres2.isErr()
|
||||
bres3.isErr()
|
||||
|
||||
try:
|
||||
let
|
||||
# `proofs` array is not present.
|
||||
response1 = await client.signDataPlain(publicKey1, request1)
|
||||
response2 = await client.signDataPlain(publicKey2, request1)
|
||||
response3 = await client.signDataPlain(publicKey3, request1)
|
||||
# `proofs` array is empty.
|
||||
response4 = await client.signDataPlain(publicKey1, request2)
|
||||
response5 = await client.signDataPlain(publicKey2, request2)
|
||||
response6 = await client.signDataPlain(publicKey3, request2)
|
||||
check:
|
||||
# When `Altair` block specified remote signer should ignore `proof`
|
||||
# field and its value.
|
||||
response1.status == 400
|
||||
response2.status == 400
|
||||
response3.status == 400
|
||||
response4.status == 400
|
||||
response5.status == 400
|
||||
response6.status == 400
|
||||
finally:
|
||||
await client.closeWait()
|
||||
|
||||
asyncTest "Signing BeaconBlock (getBlockSignature(bellatrix))":
|
||||
let
|
||||
fork = ConsensusFork.Bellatrix
|
||||
|
|
Loading…
Reference in New Issue