proposed changes to the proof verification

This commit is contained in:
Daniil Sobol 2023-12-30 21:02:51 +03:00
parent 4424c33ae6
commit f32c46a785
No known key found for this signature in database
GPG Key ID: 5121E3B3F2304E22
2 changed files with 11 additions and 19 deletions

View File

@ -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:

View File

@ -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: