Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions op-node/rollup/derive/system_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ var (
ConfigUpdateEventVersion0 = common.Hash{}
)

var (
ErrUnknownEventVersion = errors.New("unknown SystemConfig event version")
ErrUnknownEventType = errors.New("unknown SystemConfig event type")
)

// UpdateSystemConfigWithL1Receipts filters all L1 receipts to find config updates and applies the config updates to the given sysCfg
// Updates are applied individually, and any malformed or invalid updates are ignored.
// Any errors encountered during the update process are returned as a multierror.
Expand Down Expand Up @@ -79,7 +84,7 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
// indexed 0
version := ev.Topics[1]
if version != ConfigUpdateEventVersion0 {
return fmt.Errorf("unrecognized SystemConfig update event version: %s", version)
return fmt.Errorf("%w: %s", ErrUnknownEventVersion, version)
}
// indexed 1
updateType := ev.Topics[2]
Expand Down Expand Up @@ -150,11 +155,11 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
destSysCfg.DAFootprintGasScalar = daFootprintGasScalar
return nil
default:
return fmt.Errorf("unrecognized L1 sysCfg update type: %s", updateType)
return fmt.Errorf("%w: %s", ErrUnknownEventType, updateType)
}
}

var ErrParsingSystemConfig = NewCriticalError(errors.New("error parsing system config"))
var ErrParsingSystemConfig = errors.New("error parsing system config")
Comment thread
geoknee marked this conversation as resolved.

func parseSystemConfigUpdateBatcher(data []byte) (common.Address, error) {
reader := bytes.NewReader(data)
Expand Down
32 changes: 32 additions & 0 deletions op-node/rollup/derive/system_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,25 @@ func TestUpdateSystemConfigWithL1Receipts_Atomicity(t *testing.T) {
},
Data: []byte{0x00}, // insufficient bytes for pointer/length -> parse error
}
// Future / unknown event type
futureLogType := &types.Log{
Address: l1Addr,
Topics: []common.Hash{
ConfigUpdateEventABIHash,
ConfigUpdateEventVersion0,
common.Hash{0: 'a', 31: 7}, // test assumes this is not a known event type
},
}
// Future / unknown event version
futureLogVersion := &types.Log{
Address: l1Addr,
Topics: []common.Hash{
ConfigUpdateEventABIHash,
common.Hash{31: 1}, // test assumes this is not a known event version
SystemConfigUpdateBatcher,
},
Data: batcherData,
}
Comment thread
geoknee marked this conversation as resolved.
receipts := []*types.Receipt{
{
Status: types.ReceiptStatusSuccessful,
Expand All @@ -396,6 +415,14 @@ func TestUpdateSystemConfigWithL1Receipts_Atomicity(t *testing.T) {
Status: types.ReceiptStatusSuccessful,
Logs: []*types.Log{malformedGasLog},
},
{
Status: types.ReceiptStatusSuccessful,
Logs: []*types.Log{futureLogType},
},
{
Status: types.ReceiptStatusSuccessful,
Logs: []*types.Log{futureLogVersion},
},
}
err = UpdateSystemConfigWithL1Receipts(&sysCfg, receipts, &cfg, 0)
// Error should be returned due to malformed update, but valid updates should apply
Expand All @@ -404,6 +431,11 @@ func TestUpdateSystemConfigWithL1Receipts_Atomicity(t *testing.T) {
require.Equal(t, newBatcher, sysCfg.BatcherAddr)
// Confirm invalid update did not apply; GasLimit remains unchanged
require.Equal(t, initial.GasLimit, sysCfg.GasLimit)
// Confirm error contains expected messages
require.ErrorContains(t, err, "invalid pointer field")
require.ErrorIs(t, err, ErrParsingSystemConfig)
require.ErrorIs(t, err, ErrUnknownEventType)
require.ErrorIs(t, err, ErrUnknownEventVersion)
})

t.Run("applies multiple updates within a single receipt", func(t *testing.T) {
Expand Down