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
2 changes: 2 additions & 0 deletions arbos/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion arbos/incomingmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 6 additions & 13 deletions arbos/internal_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion arbos/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go-ethereum
34 changes: 26 additions & 8 deletions precompiles/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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,
Expand Down