Skip to content

Commit

Permalink
fix: add new error
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Nov 13, 2024
1 parent 0ed309e commit 7c2b7f3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"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\"}}}}}}"
}
]
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
}

0 comments on commit 7c2b7f3

Please sign in to comment.