optimism icon indicating copy to clipboard operation
optimism copied to clipboard

op-program: Error handling inconsistency in super root type validation

Open BlocksOnAChain opened this issue 8 months ago • 0 comments

Spearbit audit finding

Description

The codebase uses different error variables (ErrIncorrectOutputRootType and ErrInvalidSuperRootVersion) to represent the same error in two different contexts, which creates ambiguity in the error diagnosis.

In interop.go:

func parseAgreedState(bootInfo *boot.BootInfoInterop, l2PreimageOracle l2.Oracle) (*types.TransitionState, *eth.SuperV1, error) {
    // ....
    if super.Version() != eth.SuperRootVersionV1 {
	return nil, nil, fmt.Errorf("%w: %v", ErrIncorrectOutputRootType, super.Version())
    }
    // ...
}

In super_root.go

func UnmarshalSuperRoot(data []byte) (Super, error) {
	if len(data) < 1 {
		return nil, ErrInvalidSuperRoot
	}
	ver := data[0]
	switch ver {
	case SuperRootVersionV1:
		return unmarshalSuperRootV1(data)
	default:
		return nil, ErrInvalidSuperRootVersion
	}
}

Recommendation Consider returning the same error for handling version incompatibility of super roots across the entire codebase to facilitate easier debugging.

BlocksOnAChain avatar Apr 03 '25 12:04 BlocksOnAChain