Skip to content
Business logic Audit finding Intermediate

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.

OMEN Follow

Originally disclosed on Code4rena

Submitted by OMEN

https://github.com/initia-labs/opinit-bots/blob/640649b97cbfa5782925b7dc8c0b62b8fa5367f6/challenger/child/withdraw.go#L117-L170

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:

  1. Never triggering output handling.
  2. Missing state root updates.
  3. Potentially breaking cross-chain verification.
  4. 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

  1. System processes blocks normally.

  2. At finalization height:

    • Tree is finalized successfully.
    • Root hash is calculated.
    • But root hash is never returned.
  3. Output handling is skipped.

  4. 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.


The original report as published on Code4rena, by OMEN. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. The system processes blocks normally.
  2. At the finalization height, the tree is finalised and the root hash is calculated.
  3. The root hash is never returned because storageRoot is not assigned.
  4. 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.

More by OMEN

View all

1 more disclosed report, best first.

More from Initia Rollup Modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.