Skip to content

Commit a21f648

Browse files
separate Nitro and Stylus precompiles rules and lists
1 parent 33ee405 commit a21f648

File tree

8 files changed

+17
-14
lines changed

8 files changed

+17
-14
lines changed

core/types/arbitrum_signer.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import (
66
"github.com/ethereum/go-ethereum/common"
77
)
88

9-
const ArbosVersion_FixRedeemGas = uint64(11)
10-
const ArbosVersion_Stylus = uint64(30)
11-
129
var ArbosAddress = common.HexToAddress("0xa4b05")
1310
var ArbosStateAddress = common.HexToAddress("0xA4B05FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")
1411
var ArbSysAddress = common.HexToAddress("0x64")

core/vm/contracts.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@ func init() {
150150
// ActivePrecompiles returns the precompiles enabled with the current configuration.
151151
func ActivePrecompiles(rules params.Rules) []common.Address {
152152
switch {
153+
case rules.IsStylus:
154+
return PrecompiledAddressesArbitrumStylus
153155
case rules.IsArbitrum:
154-
return PrecompiledAddressesArbitrum
156+
return PrecompiledAddressesArbitrumNitro
155157
case rules.IsCancun:
156158
return PrecompiledAddressesCancun
157159
case rules.IsBerlin:

core/vm/contracts_arbitrum.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package vm
33
import "github.com/ethereum/go-ethereum/common"
44

55
var (
6-
PrecompiledContractsArbitrum = make(map[common.Address]PrecompiledContract)
7-
PrecompiledAddressesArbitrum []common.Address
6+
PrecompiledContractsArbitrumNitro = make(map[common.Address]PrecompiledContract)
7+
PrecompiledContractsArbitrumStylus = make(map[common.Address]PrecompiledContract)
8+
PrecompiledAddressesArbitrumNitro []common.Address
9+
PrecompiledAddressesArbitrumStylus []common.Address
810
)

core/vm/evm.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ type (
4242
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
4343
var precompiles map[common.Address]PrecompiledContract
4444
switch {
45+
case evm.chainRules.IsStylus:
46+
precompiles = PrecompiledContractsArbitrumStylus
4547
case evm.chainRules.IsArbitrum:
46-
precompiles = PrecompiledContractsArbitrum
48+
precompiles = PrecompiledContractsArbitrumNitro
4749
case evm.chainRules.IsCancun:
4850
precompiles = PrecompiledContractsCancun
4951
case evm.chainRules.IsBerlin:
@@ -523,7 +525,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
523525
err = ErrInvalidCode
524526

525527
// Arbitrum: retain Stylus programs and instead store them in the DB alongside normal EVM bytecode.
526-
if evm.IsStylus() && state.IsStylusProgram(ret) {
528+
if evm.chainRules.IsStylus && state.IsStylusProgram(ret) {
527529
err = nil
528530
}
529531
}

core/vm/evm_arbitrum.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ func (evm *EVM) DecrementDepth() {
3737
evm.depth -= 1
3838
}
3939

40-
func (evm *EVM) IsStylus() bool {
41-
return evm.chainRules.IsArbitrum && evm.Context.ArbOSVersion >= types.ArbosVersion_Stylus
42-
}
43-
4440
type TxProcessingHook interface {
4541
StartTxHook() (bool, uint64, error, []byte) // return 4-tuple rather than *struct to avoid an import cycle
4642
GasChargingHook(gasRemaining *uint64) (common.Address, error)

core/vm/interpreter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
170170
}
171171

172172
// Arbitrum: handle Stylus programs
173-
if in.evm.IsStylus() && state.IsStylusProgram(contract.Code) {
173+
if in.evm.chainRules.IsStylus && state.IsStylusProgram(contract.Code) {
174174
ret, err = in.evm.ProcessingHook.ExecuteWASM(callContext, input, in)
175175
return
176176
}

params/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ func (err *ConfigCompatError) Error() string {
866866
// Rules is a one time interface meaning that it shouldn't be used in between transition
867867
// phases.
868868
type Rules struct {
869-
IsArbitrum bool
869+
IsArbitrum, IsStylus bool
870870
ChainID *big.Int
871871
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
872872
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
@@ -883,6 +883,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64, curren
883883
}
884884
return Rules{
885885
IsArbitrum: c.IsArbitrum(),
886+
IsStylus: c.IsArbitrum() && currentArbosVersion >= ArbosVersion_Stylus,
886887
ChainID: new(big.Int).Set(chainID),
887888
IsHomestead: c.IsHomestead(num),
888889
IsEIP150: c.IsEIP150(num),

params/config_arbitrum.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
"github.com/ethereum/go-ethereum/common"
2323
)
2424

25+
const ArbosVersion_FixRedeemGas = uint64(11)
26+
const ArbosVersion_Stylus = uint64(30)
27+
2528
type ArbitrumChainParams struct {
2629
EnableArbOS bool
2730
AllowDebugPrecompiles bool

0 commit comments

Comments
 (0)