proposed changes to the proof verification
This commit is contained in:
parent
4424c33ae6
commit
f32c46a785
|
@ -14,7 +14,8 @@ import
|
||||||
../../database/content_db,
|
../../database/content_db,
|
||||||
../wire/[portal_protocol, portal_stream, portal_protocol_config],
|
../wire/[portal_protocol, portal_stream, portal_protocol_config],
|
||||||
./state_content,
|
./state_content,
|
||||||
./state_distance
|
./state_distance,
|
||||||
|
./state_proof_verification
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "portal_state"
|
topics = "portal_state"
|
||||||
|
@ -83,16 +84,9 @@ proc validateContent(
|
||||||
return false
|
return false
|
||||||
let
|
let
|
||||||
proof = decodedProof.asSeq().map((p: ByteList) => p.toSeq())
|
proof = decodedProof.asSeq().map((p: ByteList) => p.toSeq())
|
||||||
trieKey = keccakHash(key.accountTrieProofKey.address).data.toSeq()
|
|
||||||
value = proof[^1].decode(seq[seq[byte]])[^1]
|
|
||||||
stateRoot = MDigest[256](data: key.accountTrieProofKey.stateRoot)
|
stateRoot = MDigest[256](data: key.accountTrieProofKey.stateRoot)
|
||||||
verificationResult = verifyMptProof(proof, stateRoot, trieKey, value)
|
verificationResult = verifyAccount(stateRoot, key.accountTrieProofKey.address, AccountProof(proof))
|
||||||
case verificationResult.kind:
|
verificationResult.isOk()
|
||||||
of ValidProof:
|
|
||||||
true
|
|
||||||
else:
|
|
||||||
warn "Received invalid account trie proof"
|
|
||||||
false
|
|
||||||
of contractStorageTrieProof:
|
of contractStorageTrieProof:
|
||||||
true
|
true
|
||||||
of contractBytecode:
|
of contractBytecode:
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
{.push raises: [].}
|
|
||||||
|
|
||||||
import
|
import
|
||||||
std/sequtils,
|
std/sequtils,
|
||||||
stint,
|
stint,
|
||||||
|
@ -17,19 +15,19 @@ export results
|
||||||
|
|
||||||
type
|
type
|
||||||
MptProof = seq[seq[byte]]
|
MptProof = seq[seq[byte]]
|
||||||
AccountProof* = distinct MptProof
|
AccountProof* = distinct MptProof # I'm not really sure how I feel about this
|
||||||
StorageProof* = distinct MptProof
|
StorageProof* = distinct MptProof
|
||||||
|
|
||||||
proc verifyAccount*(
|
proc verifyAccount*(
|
||||||
trustedStateRoot: KeccakHash,
|
trustedStateRoot: KeccakHash,
|
||||||
address: EthAddress,
|
address: EthAddress,
|
||||||
account: Account,
|
proof: AccountProof
|
||||||
proof: AccountProof): Result[void, string] =
|
): Result[void, string] =
|
||||||
|
|
||||||
let key = toSeq(keccakHash(address).data)
|
let
|
||||||
let value = rlp.encode(account)
|
key = keccakHash(address).data.toSeq()
|
||||||
|
value = proof.MptProof[^1].decode(seq[seq[byte]])[^1] # TODO this is undefined in spec. Update when the specs gets updated
|
||||||
let proofResult = verifyMptProof(proof.MptProof, trustedStateRoot, key, value)
|
proofResult = verifyMptProof(proof.MptProof, trustedStateRoot, key, value)
|
||||||
|
|
||||||
case proofResult.kind
|
case proofResult.kind
|
||||||
of ValidProof:
|
of ValidProof:
|
Loading…
Reference in New Issue