Storage root assignment missing in tree finalization
The handleTree function in the challenger's child chain processing calculates a merkle tree root hash but never assigns it to the storageRoot return value, so the caller's check for a non-nil storageRoot always fails. This prevents output handling from ever executing, disrupting state synchronisation and the challenge mechanism between L1 and L2 chains.
Submitted by OMEN
Summary
The handleTree function in the challenger’s child chain processing fails to assign the merkle tree root hash to the storage root return value, causing the output handling logic to never execute.
Impact
Severity: High
The bug prevents proper state synchronization between L1 and L2 chains by:
- Never triggering output handling.
- Missing state root updates.
- Potentially breaking cross-chain verification.
- Disrupting the challenge mechanism.
Technical Details
Location:
opinit-bots/challenger/child/withdraw.go:
func (ch *Child) handleTree(ctx types.Context, blockHeight int64, blockHeader cmtproto.Header) (storageRoot []byte, err error) {
if ch.finalizingBlockHeight == blockHeight {
finalizedTree, newNodes, treeRootHash, err := ch.Merkle().FinalizeWorkingTree(nil)
// ... saving trees and nodes ...
// BUG: treeRootHash is never assigned to storageRoot
// Should be: storageRoot = treeRootHash
}
return storageRoot, nil // Always returns nil
}
Call Site Impact:
opinit-bots/challenger/child/handler.go
func (ch *Child) endBlockHandler(ctx types.Context, args nodetypes.EndBlockArgs) error {
storageRoot, err := ch.handleTree(ctx, blockHeight, args.Block.Header)
if storageRoot != nil { // This condition never evaluates to true
// Output handling never executes
err = ch.handleOutput(...)
}
}
Proof of Concept
-
System processes blocks normally.
-
At finalization height:
- Tree is finalized successfully.
- Root hash is calculated.
- But root hash is never returned.
-
Output handling is skipped.
-
State synchronization fails.
Root Cause: Missing assignment of the calculated treeRootHash to the return value storageRoot in the handleTree function.
Recommended mitigation steps
opinit-bots/challenger/child/withdraw.go
func (ch *Child) handleTree(ctx types.Context, blockHeight int64, blockHeader cmtproto.Header) (storageRoot []byte, err error) {
if ch.finalizingBlockHeight == blockHeight {
finalizedTree, newNodes, treeRootHash, err := ch.Merkle().FinalizeWorkingTree(nil)
if err != nil {
return nil, errors.Wrap(err, "failed to finalize working tree")
}
// Fix: Assign tree root hash
storageRoot = treeRootHash
// ... rest of the function ...
}
return storageRoot, nil
}
beer-1 (Initia) confirmed and commented:
Mitigation here.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The calculated treeRootHash is not assigned to the named return variable storageRoot, so the function always returns nil.
Impact
The bug prevents proper state synchronisation between L1 and L2 chains, potentially breaking cross-chain verification and disrupting the challenge mechanism.
What the attacker needed
None
The fix
The issue was fixed by assigning the calculated tree root hash to the storageRoot return value.
How it was found
- The system processes blocks normally.
- At the finalization height, the tree is finalised and the root hash is calculated.
- The root hash is never returned because storageRoot is not assigned.
- Output handling is skipped, and state synchronisation fails.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A function that finalises a data structure calculates a fingerprint (the root hash) but forgets to pass it back to the caller. The caller checks whether it received a fingerprint and, seeing nothing, skips an important follow-up step. As a result, the system never processes the finalised data, which can break communication between two linked blockchains.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.