diff --git a/arbos/block_processor.go b/arbos/block_processor.go index 8d68be3fad..2db29fcfaf 100644 --- a/arbos/block_processor.go +++ b/arbos/block_processor.go @@ -31,6 +31,8 @@ import ( // set by the precompile module, to avoid a package dependence cycle var ArbRetryableTxAddress common.Address var ArbSysAddress common.Address +var InternalTxStartBlockMethodID [4]byte +var InternalTxBatchPostingReportMethodID [4]byte var RedeemScheduledEventID common.Hash var L2ToL1TransactionEventID common.Hash var L2ToL1TxEventID common.Hash diff --git a/arbos/incomingmessage.go b/arbos/incomingmessage.go index ad627f9938..b2ba70bf66 100644 --- a/arbos/incomingmessage.go +++ b/arbos/incomingmessage.go @@ -540,7 +540,6 @@ func parseBatchPostingReportMessage(rd io.Reader, chainId *big.Int, batchFetcher } return types.NewTx(&types.ArbitrumInternalTx{ ChainId: chainId, - SubType: arbInternalTxBatchPostReport, Data: data, // don't need to fill in the other fields, since they exist only to ensure uniqueness, and batchNum is already unique }), nil diff --git a/arbos/internal_tx.go b/arbos/internal_tx.go index fc4b531f57..ce0b4314ca 100644 --- a/arbos/internal_tx.go +++ b/arbos/internal_tx.go @@ -5,9 +5,10 @@ package arbos import ( "fmt" - "github.com/offchainlabs/nitro/util/arbmath" "math/big" + "github.com/offchainlabs/nitro/util/arbmath" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/common" @@ -17,13 +18,6 @@ import ( "github.com/offchainlabs/nitro/arbos/util" ) -// Types of ArbitrumInternalTx, distinguished by the first data byte -const ( - // Contains 8 bytes indicating the big endian L1 block number to set - arbInternalTxStartBlock uint8 = 0 - arbInternalTxBatchPostReport uint8 = 1 -) - func InternalTxStartBlock( chainId, l1BaseFee *big.Int, @@ -45,14 +39,13 @@ func InternalTxStartBlock( return &types.ArbitrumInternalTx{ ChainId: chainId, L2BlockNumber: arbmath.BigAddByUint(lastHeader.Number, 1), - SubType: arbInternalTxStartBlock, Data: data, } } func ApplyInternalTxUpdate(tx *types.ArbitrumInternalTx, state *arbosState.ArbosState, evm *vm.EVM) { - switch tx.SubType { - case arbInternalTxStartBlock: + switch *(*[4]byte)(tx.Data[:4]) { + case InternalTxStartBlockMethodID: inputs, err := util.UnpackInternalTxDataStartBlock(tx.Data) if err != nil { panic(err) @@ -92,7 +85,7 @@ func ApplyInternalTxUpdate(tx *types.ArbitrumInternalTx, state *arbosState.Arbos state.L1PricingState().UpdateTime(currentTime) state.UpgradeArbosVersionIfNecessary(currentTime, evm.ChainConfig()) - case arbInternalTxBatchPostReport: + case InternalTxBatchPostingReportMethodID: inputs, err := util.UnpackInternalTxDataBatchPostingReport(tx.Data) if err != nil { panic(err) @@ -103,7 +96,7 @@ func ApplyInternalTxUpdate(tx *types.ArbitrumInternalTx, state *arbosState.Arbos batchDataGas, _ := inputs[3].(uint64) l1BaseFeeWei, _ := inputs[4].(*big.Int) - weiSpent := new(big.Int).Mul(l1BaseFeeWei, new(big.Int).SetUint64(batchDataGas)) + weiSpent := arbmath.BigMulByUint(l1BaseFeeWei, batchDataGas) err = state.L1PricingState().UpdateForBatchPosterSpending(evm.StateDB, evm, batchTimestamp.Uint64(), evm.Context.Time.Uint64(), batchPosterAddress, weiSpent) if err != nil { log.Warn("L1Pricing UpdateForSequencerSpending failed", "err", err) diff --git a/arbos/util/util.go b/arbos/util/util.go index 75b48b5d8c..ca97fa0c6b 100644 --- a/arbos/util/util.go +++ b/arbos/util/util.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/offchainlabs/nitro/solgen/go/precompilesgen" + "github.com/offchainlabs/nitro/util/arbmath" ) var AddressAliasOffset *big.Int @@ -34,7 +35,7 @@ func init() { panic("Error initializing AddressAliasOffset") } AddressAliasOffset = offset - InverseAddressAliasOffset = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 160), AddressAliasOffset) + InverseAddressAliasOffset = arbmath.BigSub(new(big.Int).Lsh(big.NewInt(1), 160), AddressAliasOffset) // Create a mechanism for parsing event logs logParser := func(source string, name string) func(interface{}, *types.Log) error { diff --git a/go-ethereum b/go-ethereum index 471db8b266..f7a56f4a62 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 471db8b2667a7d2c5f7517c13d52237db93b0d48 +Subproject commit f7a56f4a628be29584293353b927a65b7fc8bbfb diff --git a/precompiles/precompile.go b/precompiles/precompile.go index fdb0e61e56..6dbc970f68 100644 --- a/precompiles/precompile.go +++ b/precompiles/precompile.go @@ -58,12 +58,14 @@ const ( ) type Precompile struct { - methods map[[4]byte]PrecompileMethod - events map[string]PrecompileEvent - errors map[string]PrecompileError - implementer reflect.Value - address common.Address - arbosVersion uint64 + methods map[[4]byte]PrecompileMethod + methodsByName map[string]PrecompileMethod + events map[string]PrecompileEvent + errors map[string]PrecompileError + name string + implementer reflect.Value + address common.Address + arbosVersion uint64 } type PrecompileMethod struct { @@ -154,6 +156,7 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, Pre } methods := make(map[[4]byte]PrecompileMethod) + methodsByName := make(map[string]PrecompileMethod) events := make(map[string]PrecompileEvent) errors := make(map[string]PrecompileError) @@ -218,13 +221,15 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, Pre ) } - methods[id] = PrecompileMethod{ + method := PrecompileMethod{ name, method, purity, handler, 0, } + methods[id] = method + methodsByName[name] = method } // provide the implementer mechanisms to emit logs for the solidity events @@ -487,8 +492,10 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, Pre return address, Precompile{ methods, + methodsByName, events, errors, + contract, reflect.ValueOf(implementer), address, 0, @@ -518,7 +525,6 @@ func Precompiles() map[addr]ArbosPrecompile { insert(MakePrecompile(templates.ArbGasInfoMetaData, &ArbGasInfo{Address: hex("6c")})) insert(MakePrecompile(templates.ArbAggregatorMetaData, &ArbAggregator{Address: hex("6d")})) insert(MakePrecompile(templates.ArbStatisticsMetaData, &ArbStatistics{Address: hex("6f")})) - insert(MakePrecompile(templates.ArbosActsMetaData, &ArbosActs{Address: types.ArbosAddress})) eventCtx := func(gasLimit uint64, err error) *Context { if err != nil { @@ -559,6 +565,10 @@ func Precompiles() map[addr]ArbosPrecompile { insert(ownerOnly(ArbOwnerImpl.Address, ArbOwner, emitOwnerActs)) insert(debugOnly(MakePrecompile(templates.ArbDebugMetaData, &ArbDebug{Address: hex("ff")}))) + ArbosActs := insert(MakePrecompile(templates.ArbosActsMetaData, &ArbosActs{Address: types.ArbosAddress})) + arbos.InternalTxStartBlockMethodID = ArbosActs.GetMethodID("StartBlock") + arbos.InternalTxBatchPostingReportMethodID = ArbosActs.GetMethodID("BatchPostingReport") + return contracts } @@ -567,6 +577,14 @@ func (p Precompile) SwapImpl(impl interface{}) Precompile { return p } +func (p Precompile) GetMethodID(name string) bytes4 { + method, ok := p.methodsByName[name] + if !ok { + panic(fmt.Sprintf("Precompile %v does not have a method with the name %v", p.name, name)) + } + return *(*bytes4)(method.template.ID) +} + // call a precompile in typed form, deserializing its inputs and serializing its outputs func (p Precompile) Call( input []byte,