# Merged leaves & optimistic rollup

Merged leaves is used for item append sequence validation for the merkle tree rollup of massive items.

Merged leaves concept is used for the sequence verification of the appended items when we want to prove Merkle tree updates through multiple transactions. Let us assume that what exactly we are going to prove is the following result.

To prove above, we will run the following steps:

To add a massive number of items, we split the transactions and record the intermediate proof result.

Every item will be merged sequentially into the

`mergedLeaves`

value to ensure the sequence of the item appending.In the end, the result stored on the EVM will be

And then we can compare the Merkle tree update result.

Let us see a more detailed example.

`startRoot`

is`0x0001234...`

`startIndex`

is 38`itemsToAdd`

is`[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09]`

we are now trying to prove

`resultRoot`

is`0xabcd1234...`

when after adding all items in the`itemsToAdd`

list.

We're going to add three items at once, so after two times of transactions, we can have a proof for the Merkle tree transition on EVM. Note that we have used random values for the hash calculation for this example.

Start

Add the first item

Add the second item

Add the third item & record to the storage

To add the fourth item, we will retrive the result from the storage and keep going to append items.

As a result, we now have the result on Ethereum storage, proving the valid Merkle tree transition by the EVM calculation.

Using the stored proof, we can validate the following information is valid or not. To validate the information, it computes the

`mergedLeaves`

result of the`itemsToAdd`

and compares it with the stored`mergedLeaves`

.Here is how it computes the

`mergedLeaves`

of`itemsToAdd`

Finally, if the result

`merged`

value equals to the`mergedLeaves`

value`0xDEFEDFED...`

of the stored proof, it returns`true`

or will be reverted.

Last updated