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