proposed changes to the proof verification
This commit is contained in:
parent
4424c33ae6
commit
f32c46a785
|
@ -14,7 +14,8 @@ import
|
|||
../../database/content_db,
|
||||
../wire/[portal_protocol, portal_stream, portal_protocol_config],
|
||||
./state_content,
|
||||
./state_distance
|
||||
./state_distance,
|
||||
./state_proof_verification
|
||||
|
||||
logScope:
|
||||
topics = "portal_state"
|
||||
|
@ -83,16 +84,9 @@ proc validateContent(
|
|||
return false
|
||||
let
|
||||
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)
|
||||
verificationResult = verifyMptProof(proof, stateRoot, trieKey, value)
|
||||
case verificationResult.kind:
|
||||
of ValidProof:
|
||||
true
|
||||
else:
|
||||
warn "Received invalid account trie proof"
|
||||
false
|
||||
verificationResult = verifyAccount(stateRoot, key.accountTrieProofKey.address, AccountProof(proof))
|
||||
verificationResult.isOk()
|
||||
of contractStorageTrieProof:
|
||||
true
|
||||
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).
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/sequtils,
|
||||
stint,
|
||||
|
@ -17,19 +15,19 @@ export results
|
|||
|
||||
type
|
||||
MptProof = seq[seq[byte]]
|
||||
AccountProof* = distinct MptProof
|
||||
AccountProof* = distinct MptProof # I'm not really sure how I feel about this
|
||||
StorageProof* = distinct MptProof
|
||||
|
||||
proc verifyAccount*(
|
||||
trustedStateRoot: KeccakHash,
|
||||
address: EthAddress,
|
||||
account: Account,
|
||||
proof: AccountProof): Result[void, string] =
|
||||
proof: AccountProof
|
||||
): Result[void, string] =
|
||||
|
||||
let key = toSeq(keccakHash(address).data)
|
||||
let value = rlp.encode(account)
|
||||
|
||||
let proofResult = verifyMptProof(proof.MptProof, trustedStateRoot, key, value)
|
||||
let
|
||||
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
|
||||
proofResult = verifyMptProof(proof.MptProof, trustedStateRoot, key, value)
|
||||
|
||||
case proofResult.kind
|
||||
of ValidProof:
|
Loading…
Reference in New Issue