diff --git a/fluffy/network/state/state_network.nim b/fluffy/network/state/state_network.nim index 81db00f18..c6e93c03e 100644 --- a/fluffy/network/state/state_network.nim +++ b/fluffy/network/state/state_network.nim @@ -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: diff --git a/fluffy/network/state/experimental/state_proof_verification.nim b/fluffy/network/state/state_proof_verification.nim similarity index 81% rename from fluffy/network/state/experimental/state_proof_verification.nim rename to fluffy/network/state/state_proof_verification.nim index 7ccea0549..c6eaae549 100644 --- a/fluffy/network/state/experimental/state_proof_verification.nim +++ b/fluffy/network/state/state_proof_verification.nim @@ -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: