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,
../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:

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).
# 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: