Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: L1InfoRootIncorrect error from agglayer #185

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"test_name": "L1InfoRootIncorrect",
"certificate_header": "{\"network_id\":1,\"height\":6,\"epoch_number\":null,\"certificate_index\":null,\"certificate_id\":\"0xa80cd4abb016bbb3c3058f923a88be1ad49d68277366c55554d6f13d62428a1f\",\"new_local_exit_root\":\"0x566244fbf813b6926f6895142979f61ed6706184909cb8c819cd0216202a8aa9\",\"metadata\":\"0x000000000000000000000000000000000000000000000000000000000000001f\",\"status\":{\"InError\":{\"error\":{\"TypeConversionError\":{\"L1InfoRootIncorrect\":{\"leaf_count\":11,\"declared\":\"0x566244fbf813b6926f6895142979f61ed6706184909cb8c819cd0216202a8aa9\",\"retrieved\":\"0xa80cd4abb016bbb3c3058f923a88be1ad49d68277366c55554d6f13d62428a1f\"}}}}}}"
},
{
"test_name": "L1InfoRootIncorrect - unmarshal error",
"expected_error": "value of key leaf_count is not of type uint32",
"certificate_header": "{\"network_id\":1,\"height\":6,\"epoch_number\":null,\"certificate_index\":null,\"certificate_id\":\"0xa80cd4abb016bbb3c3058f923a88be1ad49d68277366c55554d6f13d62428a1f\",\"new_local_exit_root\":\"0x566244fbf813b6926f6895142979f61ed6706184909cb8c819cd0216202a8aa9\",\"metadata\":\"0x000000000000000000000000000000000000000000000000000000000000001f\",\"status\":{\"InError\":{\"error\":{\"TypeConversionError\":{\"L1InfoRootIncorrect\":{\"leaf_count\":\"invalid\",\"declared\":\"0x566244fbf813b6926f6895142979f61ed6706184909cb8c819cd0216202a8aa9\",\"retrieved\":\"0xa80cd4abb016bbb3c3058f923a88be1ad49d68277366c55554d6f13d62428a1f\"}}}}}}"
}
]
goran-ethernal marked this conversation as resolved.
Show resolved Hide resolved
51 changes: 51 additions & 0 deletions agglayer/type_conversion_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package agglayer
import (
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common"
)

const (
Expand All @@ -12,6 +14,7 @@ const (
BalanceUnderflowErrorType = "BalanceUnderflow"
BalanceProofGenerationFailedErrorType = "BalanceProofGenerationFailed"
NullifierPathGenerationFailedErrorType = "NullifierPathGenerationFailed"
L1InfoRootIncorrectErrorType = "L1InfoRootIncorrect"
)

// TypeConversionError is an error that is returned when verifying a certficate
Expand Down Expand Up @@ -57,6 +60,12 @@ func (p *TypeConversionError) Unmarshal(data interface{}) error {
return nil, err
}
return nullifierPathGenerationFailed, nil
case L1InfoRootIncorrectErrorType:
l1InfoRootIncorrect := &L1InfoRootIncorrect{}
if err := l1InfoRootIncorrect.Unmarshal(value); err != nil {
return nil, err
}
return l1InfoRootIncorrect, nil
default:
return nil, fmt.Errorf("unknown type conversion error type: %v", key)
}
Expand Down Expand Up @@ -253,3 +262,45 @@ func (e *NullifierPathGenerationFailed) UnmarshalFromMap(data interface{}) error
e.GlobalIndex = &GlobalIndex{}
return e.GlobalIndex.UnmarshalFromMap(globalIndexMap)
}

// L1InfoRootIncorrect is an error that is returned when the L1 Info Root is invalid or unsettled
type L1InfoRootIncorrect struct {
Declared common.Hash `json:"declared"`
Retrieved common.Hash `json:"retrieved"`
LeafCount uint32 `json:"leaf_count"`
}

// String is the implementation of the Error interface
func (e *L1InfoRootIncorrect) String() string {
return fmt.Sprintf("%s: The L1 Info Root is incorrect. Declared: %s, Retrieved: %s, LeafCount: %d",
L1InfoRootIncorrectErrorType, e.Declared.String(), e.Retrieved.String(), e.LeafCount)
}

// Unmarshal unmarshals the data from a map into a L1InfoRootIncorrect struct.
func (e *L1InfoRootIncorrect) Unmarshal(data interface{}) error {
dataMap, ok := data.(map[string]interface{})
if !ok {
return errNotMap
}

declared, err := convertMapValue[string](dataMap, "declared")
if err != nil {
return err
}

retrieved, err := convertMapValue[string](dataMap, "retrieved")
if err != nil {
return err
}

leafCount, err := convertMapValue[uint32](dataMap, "leaf_count")
if err != nil {
return err
}

e.Declared = common.HexToHash(declared)
e.Retrieved = common.HexToHash(retrieved)
e.LeafCount = leafCount

return nil
}
Loading