AntelopeIO / spring

C++ implementation of the Antelope protocol with Savanna consensus
Other
10 stars 5 forks source link

Verify block id as part of block header validation for savanna blocks #730

Open heifner opened 2 months ago

heifner commented 2 months ago

For legacy blocks, the block id can't be verified until the action_mroot (merkle root of action receipts) is calculated which requires applying the transactions. For Savanna blocks the action_mroot is the finality_mroot (merkle root of the finality tree) which is known before applying the transactions.

For savanna blocks, verify the block id as part of block header validation.

linh2931 commented 1 month ago

What about transaction_mroot? It is a part of block ID. It is unknown until transactions are applied.

heifner commented 1 month ago

What about transaction_mroot? It is a part of block ID. It is unknown until transactions are applied.

It is known before they are applied, see: https://github.com/AntelopeIO/spring/blob/main/libraries/chain/controller.cpp#L4127

linh2931 commented 1 month ago

Thanks. I was looking at the transaction_mroot for producing.

linh2931 commented 1 month ago

finality_mroot is known after valid structure built. To build valid structure, we need action_mroot (not the one in the header but the merkle root of action receipts) https://github.com/AntelopeIO/spring/blob/af51472f5157cd3181fde8dfc7233ab6c95c76c3/libraries/chain/block_state.cpp#L286 It is only available after transactions are applied. That's why 2 stages are currently used (step 7 in the Changes Required section): https://github.com/AntelopeIO/leap/issues/2080#:~:text=Similarly%2C%20when%20a,rejected%20as%20invalid.

Currently finality_tree root is checked by https://github.com/AntelopeIO/spring/blob/af51472f5157cd3181fde8dfc7233ab6c95c76c3/libraries/chain/controller.cpp#L3791 block id is checked by https://github.com/AntelopeIO/spring/blob/af51472f5157cd3181fde8dfc7233ab6c95c76c3/libraries/chain/controller.cpp#L3812

Not sure if we can move the checks any earlier.

I also think the following check is unnecessary as it uses the same value to check itself https://github.com/AntelopeIO/spring/blob/af51472f5157cd3181fde8dfc7233ab6c95c76c3/libraries/chain/controller.cpp#L4152

linh2931 commented 1 month ago

But we can verify action_mroot (Finality Tree Root) as early as in verify_basic_proper_block_invariants(). I will do that.