Skip to content

Commit

Permalink
Merge pull request ethereum#41 from OffchainLabs/stylus-arbos-30
Browse files Browse the repository at this point in the history
Separate Nitro and Stylus `ChainRules` and Precompiles Lists
  • Loading branch information
rachel-bousfield authored Apr 19, 2024
2 parents abf6d0e + a21f648 commit e4dc411
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 14 deletions.
3 changes: 0 additions & 3 deletions core/types/arbitrum_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import (
"github.com/ethereum/go-ethereum/common"
)

const ArbosVersion_FixRedeemGas = uint64(11)
const ArbosVersion_Stylus = uint64(30)

var ArbosAddress = common.HexToAddress("0xa4b05")
var ArbosStateAddress = common.HexToAddress("0xA4B05FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")
var ArbSysAddress = common.HexToAddress("0x64")
Expand Down
4 changes: 3 additions & 1 deletion core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ func init() {
// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address {
switch {
case rules.IsStylus:
return PrecompiledAddressesArbitrumStylus
case rules.IsArbitrum:
return PrecompiledAddressesArbitrum
return PrecompiledAddressesArbitrumNitro
case rules.IsCancun:
return PrecompiledAddressesCancun
case rules.IsBerlin:
Expand Down
6 changes: 4 additions & 2 deletions core/vm/contracts_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package vm
import "github.com/ethereum/go-ethereum/common"

var (
PrecompiledContractsArbitrum = make(map[common.Address]PrecompiledContract)
PrecompiledAddressesArbitrum []common.Address
PrecompiledContractsArbitrumNitro = make(map[common.Address]PrecompiledContract)
PrecompiledContractsArbitrumStylus = make(map[common.Address]PrecompiledContract)
PrecompiledAddressesArbitrumNitro []common.Address
PrecompiledAddressesArbitrumStylus []common.Address
)
6 changes: 4 additions & 2 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ type (
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
var precompiles map[common.Address]PrecompiledContract
switch {
case evm.chainRules.IsStylus:
precompiles = PrecompiledContractsArbitrumStylus
case evm.chainRules.IsArbitrum:
precompiles = PrecompiledContractsArbitrum
precompiles = PrecompiledContractsArbitrumNitro
case evm.chainRules.IsCancun:
precompiles = PrecompiledContractsCancun
case evm.chainRules.IsBerlin:
Expand Down Expand Up @@ -523,7 +525,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
err = ErrInvalidCode

// Arbitrum: retain Stylus programs and instead store them in the DB alongside normal EVM bytecode.
if evm.IsStylus() && state.IsStylusProgram(ret) {
if evm.chainRules.IsStylus && state.IsStylusProgram(ret) {
err = nil
}
}
Expand Down
4 changes: 0 additions & 4 deletions core/vm/evm_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ func (evm *EVM) DecrementDepth() {
evm.depth -= 1
}

func (evm *EVM) IsStylus() bool {
return evm.chainRules.IsArbitrum && evm.Context.ArbOSVersion >= types.ArbosVersion_Stylus
}

type TxProcessingHook interface {
StartTxHook() (bool, uint64, error, []byte) // return 4-tuple rather than *struct to avoid an import cycle
GasChargingHook(gasRemaining *uint64) (common.Address, error)
Expand Down
2 changes: 1 addition & 1 deletion core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
}

// Arbitrum: handle Stylus programs
if in.evm.IsStylus() && state.IsStylusProgram(contract.Code) {
if in.evm.chainRules.IsStylus && state.IsStylusProgram(contract.Code) {
ret, err = in.evm.ProcessingHook.ExecuteWASM(callContext, input, in)
return
}
Expand Down
3 changes: 2 additions & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ func (err *ConfigCompatError) Error() string {
// Rules is a one time interface meaning that it shouldn't be used in between transition
// phases.
type Rules struct {
IsArbitrum bool
IsArbitrum, IsStylus bool
ChainID *big.Int
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
Expand All @@ -883,6 +883,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64, curren
}
return Rules{
IsArbitrum: c.IsArbitrum(),
IsStylus: c.IsArbitrum() && currentArbosVersion >= ArbosVersion_Stylus,
ChainID: new(big.Int).Set(chainID),
IsHomestead: c.IsHomestead(num),
IsEIP150: c.IsEIP150(num),
Expand Down
3 changes: 3 additions & 0 deletions params/config_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
"github.com/ethereum/go-ethereum/common"
)

const ArbosVersion_FixRedeemGas = uint64(11)
const ArbosVersion_Stylus = uint64(30)

type ArbitrumChainParams struct {
EnableArbOS bool
AllowDebugPrecompiles bool
Expand Down

0 comments on commit e4dc411

Please sign in to comment.