GridPlus / cryptobridge-contracts

Smart contracts for trustless bridges
MIT License
75 stars 31 forks source link

Withdraw functionality and tests #3

Closed alex-miller-0 closed 6 years ago

alex-miller-0 commented 6 years ago

Users need to withdraw tokens by proving a deposit made on a the other chain. This implements a transaction Merkle proof in Solidity and adds tests.

alex-miller-0 commented 6 years ago

Unfortunately this isn't going to work with TestRPC/Ganache because they don't provide v,r,s parameters: https://github.com/trufflesuite/ganache/issues/294

I will add my Parity initializer script to this repo.

alex-miller-0 commented 6 years ago

Merkle-Patricia proofs are working in JS! Need to now match them in Solidity.

One thing to note is the v value provided by Parity mixes in EIP155. I will either need to modify the proof to account for that or just add it into Solidity. I'm not sure if Geth does the same thing - that would affect this decision. This is an important note because the Merkle transaction tree is completely changed depending on which v value gets hashed in the transaction. Bad standards are bad.

alex-miller-0 commented 6 years ago

Solidity v0 gas costs:

alex-miller-0 commented 6 years ago

Note on forming transaction hashes:

EIP155 changes the way that a transaction hash is calculated. It swaps v for the chain_id and sets s and r both equal to zero (Parity, EthereumJs). I'm still trying to get these two to match up in a test case.

Edit: these are unsigned transactions, but my test case has signed transactions. I tried hashing an RLP-encoded list of items but my v value was still EIP155 encoded. I will try it with the standardV instead.

alex-miller-0 commented 6 years ago

This is ready for merge. Note that it only contains a Merkle-Patricia proof on the transaction itself (i.e. to form the txRoot) and a check on the signer of the transaction. It does not check the receipt or the header proofs. Those will be separate PRs.