The needs for using a trie in the browser are much simpler.
This implementation is for one time use cases of data verification: put serialized BlockReceipts in the Trie and build an inclusion proof with findPath, and that's it.
This is a light weight and synchronous implementation of the Ethereum modified Merkle Patricia Tree.
Most of the core logic is taken from https://github.com/ethereumjs/ethereumjs-monorepo.
It replaces the database and async logic with a simple Map to temporarily store trie nodes.
Reasons for not forking ethereum.js:
it is a monorepo
it has complex build settings for the whole monorepo
Ethereum's Patricia trie will not evolve (only replaced by a new trie if the decision is made to go binary) so maintenance will be minimal
We can refactor this trie to a separate utility repository which can be used by other dapps needing to verify receipts.
I had to disable some of the TS checks so as not to make many modifications to the trie algorithm at this time. This can be improved in a separate PR when fixing TS in this repo and adding tests to make the changes securely.
While testing I came across a bridge transfer which could not be finalized. The reason is that the trie built from receipts to make the proof is invalid: the root computed does not match the block header receiptsRoot. This bug appears in both the original ethereumjs implementation and this implementation.
@mfornet mentioned a similar failing transfer, to be confirmed if it was also due to an invalid receipts trie built.
This is the lock tx hash so you can restore and test it also: https://ropsten.etherscan.io/tx/0xb1008805a1547b792942d33953decb0d55d5f4fc316d1a54193aa358e7af833c
EDIT: the invalid computed trie may also be caused by an invalid serialization of the receipt used as value in the trie.
https://github.com/near/rainbow-bridge-frontend/issues/128 The merle-patricia-tree from ethereumjs import is the reason for the UI not being able to load on browsers other than Chrome. That implementation is quite heavy and aimed to reproduce all the functionality that would be needed of a trie in a node. It uses
level-mem
as a dependency and is know to have bundling issue in browsers: https://github.com/ethereumjs/ethereumjs-monorepo/issues/1056The needs for using a trie in the browser are much simpler. This implementation is for one time use cases of data verification: put serialized BlockReceipts in the Trie and build an inclusion proof with
findPath
, and that's it. This is a light weight and synchronous implementation of the Ethereum modified Merkle Patricia Tree. Most of the core logic is taken from https://github.com/ethereumjs/ethereumjs-monorepo. It replaces the database and async logic with a simple Map to temporarily store trie nodes.Reasons for not forking ethereum.js:
I had to disable some of the TS checks so as not to make many modifications to the trie algorithm at this time. This can be improved in a separate PR when fixing TS in this repo and adding tests to make the changes securely.
While testing I came across a bridge transfer which could not be finalized. The reason is that the trie built from receipts to make the proof is invalid: the root computed does not match the block header receiptsRoot. This bug appears in both the original ethereumjs implementation and this implementation. @mfornet mentioned a similar failing transfer, to be confirmed if it was also due to an invalid receipts trie built. This is the lock tx hash so you can restore and test it also: https://ropsten.etherscan.io/tx/0xb1008805a1547b792942d33953decb0d55d5f4fc316d1a54193aa358e7af833c
EDIT: the invalid computed trie may also be caused by an invalid serialization of the receipt used as value in the trie.
This is a pre-release version, it should work on all browsers desktop and mobile https://ropsten-patricia.onrender.com https://mainnet-patricia.onrender.com