Open VRamakrishna opened 2 years ago
One of the main tasks of handleExternalRequest
is proof generation.
To obtain a signature by the validators on the contract response:
Among these, Steps 4 and 6 have to be figured out. In Step 4, we have to figure out how we get the Merkle Patricia trie corresponding to receiptsRoot? In Step 6, three things to be figured out:
a. how to obtain block hash from the Block Object? b. how to verify block hash against the validator signatures? c. identify the parts of Transaction Receipt Object to be hashed and verified against the tree node in the Merkle tree rooted at receiptsRoot.
@sanvenDev identified that the following are the parameters that are hashed to obtain the block hash: {parentHash, ommersHash, coinbase, stateRoot, transactionsRoot, receiptsRoot, logsBloom, difficulty, number, gasLimit, gasUsed, timestamp, extraData, mixHash, nonce, baseFee}
But we still have to figure out the hashing routine on obtaining the block hash from the above parameters.
Some seemingly related links to start figuring this out:
After a discussion in Hyperledger Discord channel (https://discord.com/channels/905194001349627914/938504958909747250/1003647719291764797) and a conversation internally, we realized that the implementation in Besu (and possibly also the web3 recover() function) of the validity and recovery of the validators implicitly performs the ECDSA signature verification. This resolves Question b in the comment above.
The link suggested in the above Discord chat shows how the block has is computed. So, this, in addition to @sanvenDev's finding in the above comment, resolves Question a.
We still have to figure out the answer to a part of Question c.
extraData
field in block header object contains signatures of the validators (atleast 2/3rd of the total validators) on the hash of blockHeader object. During this computation of the hash, the signature field in extraData is removed.
Proof:
{parentHash, ommersHash, coinbase, stateRoot, transactionsRoot, receiptsRoot, logsBloom, difficulty, number, gasLimit, gasUsed, timestamp, extraData (without signatures), mixHash, nonce, baseFee}
. receiptsRoot
in block header object.Flow of trust / reverse flow of verification:
Data -> TransactionReceipt Object -(merkle proof)-> ReceiptsRoot -> BlockHeader -(hash and sign)-> Signature
Steps to obtain data:
handleExternalRequest
function call.web3.eth.getTransactionReceipt
) -> txRcpt.txRcpt
, and get the index of log whose address is interop contract. Make sure in handleExternalRequest
there is only one event emitted. Else we obtain id by the event name from the response, and filter txRcpt
using this id.logs[index].args.data
.Steps to generate proof:
txHash
), and blockHash
from response of interop contract handleExternalRequest
function call.txHash
.blockHash
.receiptsRoot
in the Block Object.We still have to figure out Step 5, which is related to Question c in the first comment.
Typescript library for merkle patricia trie: https://www.npmjs.com/package/merkle-patricia-tree
We can try this to generate merkle-patricia proof.
To explore: how to specify particular validators i.e. the verification policy specified by the destination network.
To explore:
Create a set of interop contracts in Solidity to support data sharing with a Besu network as one of the participating networks. These include: