0

I am trying to generate an extrinsic proof that can in turn be used to generate a partial trie and then extract the actual extrinsic for which the proof was generated from the trie, but I've not been able to figure it out yet.

Currently I'm using the trie_db::proof::generate_proof to generate the proof

This is what I've done so far https://github.com/Wizdave97/extrinsic-from-proof/blob/master/src/main.rs

The issue is the second line of this snippet returns an error 'InvalidStateRoot'

let db = sp_trie::storage_proof::StorageProof::new(proof.to_vec()).into_memory_db::<BlakeTwo256>();
let trie = sp_trie::TrieDB::<sp_trie::LayoutV0<BlakeTwo256>>::new(&db, root).unwrap();

1 Answer 1

1

Proofs created with let extrinsic_proof = generate_proof::<_, sp_trie::LayoutV0<BlakeTwo256>, _, _ >(&trie, vec![&key]).unwrap(); (generate_proof) cannot be loaded directly with StorageProof::new, they need to use https://github.com/paritytech/trie/blob/f64e1b0a8ced1b4b574d2b705202bf790d4394e4/trie-db/src/proof/verify.rs#L394, because the encoded node are incomplete (some hash are ommitted as they can be calculated from child nodes).

Sadly I do not know of an implementation that rebuild the full memorydb. If you look at the verify method, you can see where the hash are calculated ('L::Hash::hash') over the full encoded node, inserted in memorydb there should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.