github.com/MetalBlockchain/subnet-evm@v0.4.9/precompile/params.go (about) 1 // (c) 2019-2020, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package precompile 5 6 import ( 7 "fmt" 8 9 "github.com/ethereum/go-ethereum/common" 10 ) 11 12 // Gas costs for stateful precompiles 13 const ( 14 writeGasCostPerSlot = 20_000 15 readGasCostPerSlot = 5_000 16 ) 17 18 // Designated addresses of stateful precompiles 19 // Note: it is important that none of these addresses conflict with each other or any other precompiles 20 // in core/vm/contracts.go. 21 // The first stateful precompiles were added in coreth to support nativeAssetCall and nativeAssetBalance. New stateful precompiles 22 // originating in coreth will continue at this prefix, so we reserve this range in subnet-evm so that they can be migrated into 23 // subnet-evm without issue. 24 // These start at the address: 0x0100000000000000000000000000000000000000 and will increment by 1. 25 // Optional precompiles implemented in subnet-evm start at 0x0200000000000000000000000000000000000000 and will increment by 1 26 // from here to reduce the risk of conflicts. 27 // For forks of subnet-evm, users should start at 0x0300000000000000000000000000000000000000 to ensure 28 // that their own modifications do not conflict with stateful precompiles that may be added to subnet-evm 29 // in the future. 30 var ( 31 ContractDeployerAllowListAddress = common.HexToAddress("0x0200000000000000000000000000000000000000") 32 ContractNativeMinterAddress = common.HexToAddress("0x0200000000000000000000000000000000000001") 33 TxAllowListAddress = common.HexToAddress("0x0200000000000000000000000000000000000002") 34 FeeConfigManagerAddress = common.HexToAddress("0x0200000000000000000000000000000000000003") 35 RewardManagerAddress = common.HexToAddress("0x0200000000000000000000000000000000000004") 36 // ADD YOUR PRECOMPILE HERE 37 // {YourPrecompile}Address = common.HexToAddress("0x03000000000000000000000000000000000000??") 38 39 UsedAddresses = []common.Address{ 40 ContractDeployerAllowListAddress, 41 ContractNativeMinterAddress, 42 TxAllowListAddress, 43 FeeConfigManagerAddress, 44 RewardManagerAddress, 45 // ADD YOUR PRECOMPILE HERE 46 // YourPrecompileAddress 47 } 48 reservedRanges = []AddressRange{ 49 { 50 common.HexToAddress("0x0100000000000000000000000000000000000000"), 51 common.HexToAddress("0x01000000000000000000000000000000000000ff"), 52 }, 53 { 54 common.HexToAddress("0x0200000000000000000000000000000000000000"), 55 common.HexToAddress("0x02000000000000000000000000000000000000ff"), 56 }, 57 { 58 common.HexToAddress("0x0300000000000000000000000000000000000000"), 59 common.HexToAddress("0x03000000000000000000000000000000000000ff"), 60 }, 61 } 62 ) 63 64 // UsedAddress returns true if [addr] is in a reserved range for custom precompiles 65 func ReservedAddress(addr common.Address) bool { 66 for _, reservedRange := range reservedRanges { 67 if reservedRange.Contains(addr) { 68 return true 69 } 70 } 71 72 return false 73 } 74 75 func init() { 76 // Ensure that every address used by a precompile is in a reserved range. 77 for _, addr := range UsedAddresses { 78 if !ReservedAddress(addr) { 79 panic(fmt.Errorf("address %s used for stateful precompile but not specified in any reserved range", addr)) 80 } 81 } 82 }