-
Notifications
You must be signed in to change notification settings - Fork 84
/
precompiled_contracts_addr.go
142 lines (112 loc) · 5.64 KB
/
precompiled_contracts_addr.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2018 Wanchain Foundation Ltd
package vm
import (
"math/big"
"github.com/wanchain/go-wanchain/common"
"github.com/wanchain/go-wanchain/core/types"
)
// Precompiled contracts address or
// Reserved contracts address.
// Should prevent overwriting to them.
var (
ecrecoverPrecompileAddr = common.BytesToAddress([]byte{1})
sha256hashPrecompileAddr = common.BytesToAddress([]byte{2})
ripemd160hashPrecompileAddr = common.BytesToAddress([]byte{3})
dataCopyPrecompileAddr = common.BytesToAddress([]byte{4})
bigModExpPrecompileAddr = common.BytesToAddress([]byte{5})
bn256AddPrecompileAddr = common.BytesToAddress([]byte{6})
bn256ScalarMulPrecompileAddr = common.BytesToAddress([]byte{7})
bn256PairingPrecompileAddr = common.BytesToAddress([]byte{8})
s256AddPrecompileAddr = common.BytesToAddress([]byte{66})
s256ScalarMulPrecompileAddr = common.BytesToAddress([]byte{67})
wanCoinPrecompileAddr = common.BytesToAddress([]byte{100})
wanStampPrecompileAddr = common.BytesToAddress([]byte{200})
WanCscPrecompileAddr = common.BytesToAddress([]byte{218})
StakersInfoAddr = common.BytesToAddress(big.NewInt(400).Bytes())
StakingCommonAddr = common.BytesToAddress(big.NewInt(401).Bytes())
StakersFeeAddr = common.BytesToAddress(big.NewInt(402).Bytes())
StakersMaxFeeAddr = common.BytesToAddress(big.NewInt(403).Bytes())
otaBalanceStorageAddr = common.BytesToAddress(big.NewInt(300).Bytes())
otaImageStorageAddr = common.BytesToAddress(big.NewInt(301).Bytes())
// 0.01wan --> "0x0000000000000000000000010000000000000000"
otaBalancePercentdot001WStorageAddr = common.HexToAddress(WanStampdot001)
otaBalancePercentdot002WStorageAddr = common.HexToAddress(WanStampdot002)
otaBalancePercentdot005WStorageAddr = common.HexToAddress(WanStampdot005)
otaBalancePercentdot003WStorageAddr = common.HexToAddress(WanStampdot003)
otaBalancePercentdot006WStorageAddr = common.HexToAddress(WanStampdot006)
otaBalancePercentdot009WStorageAddr = common.HexToAddress(WanStampdot009)
otaBalancePercentdot03WStorageAddr = common.HexToAddress(WanStampdot03)
otaBalancePercentdot06WStorageAddr = common.HexToAddress(WanStampdot06)
otaBalancePercentdot09WStorageAddr = common.HexToAddress(WanStampdot09)
otaBalancePercentdot2WStorageAddr = common.HexToAddress(WanStampdot2)
otaBalancePercentdot5WStorageAddr = common.HexToAddress(WanStampdot5)
otaBalance10WStorageAddr = common.HexToAddress(Wancoin10)
otaBalance20WStorageAddr = common.HexToAddress(Wancoin20)
otaBalance50WStorageAddr = common.HexToAddress(Wancoin50)
otaBalance100WStorageAddr = common.HexToAddress(Wancoin100)
otaBalance200WStorageAddr = common.HexToAddress(Wancoin200)
otaBalance500WStorageAddr = common.HexToAddress(Wancoin500)
otaBalance1000WStorageAddr = common.HexToAddress(Wancoin1000)
otaBalance5000WStorageAddr = common.HexToAddress(Wancoin5000)
otaBalance50000WStorageAddr = common.HexToAddress(Wancoin50000)
//pos
slotLeaderPrecompileAddr = common.BytesToAddress(big.NewInt(600).Bytes())
IncentivePrecompileAddr = common.BytesToAddress(big.NewInt(606).Bytes()) //0x25E
randomBeaconPrecompileAddr = common.BytesToAddress(big.NewInt(610).Bytes())
PosControlPrecompileAddr = common.BytesToAddress(big.NewInt(612).Bytes())
SolEnhancePrecompileAddr = common.BytesToAddress(big.NewInt(616).Bytes())
// TODO: remove one?
RandomBeaconPrecompileAddr = randomBeaconPrecompileAddr
SlotLeaderPrecompileAddr = slotLeaderPrecompileAddr
)
// PrecompiledContract is the basic interface for native Go contracts. The implementation
// requires a deterministic gas count based on the input size of the Run method of the
// contract.
type PrecompiledContract interface {
RequiredGas(input []byte) uint64 // RequiredPrice calculates the contract gas use
Run(input []byte, contract *Contract, evm *EVM) ([]byte, error) // Run runs the precompiled contract
ValidTx(stateDB StateDB, signer types.Signer, tx *types.Transaction) error
}
// PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum
// contracts used in the Frontier and Homestead releases.
var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{
ecrecoverPrecompileAddr: &ecrecover{},
sha256hashPrecompileAddr: &sha256hash{},
ripemd160hashPrecompileAddr: &ripemd160hash{},
dataCopyPrecompileAddr: &dataCopy{},
wanCoinPrecompileAddr: &wanCoinSC{},
wanStampPrecompileAddr: &wanchainStampSC{},
}
// PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum
// contracts used in the Byzantium release.
var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{
ecrecoverPrecompileAddr: &ecrecover{},
sha256hashPrecompileAddr: &sha256hash{},
ripemd160hashPrecompileAddr: &ripemd160hash{},
dataCopyPrecompileAddr: &dataCopy{},
bigModExpPrecompileAddr: &bigModExp{},
bn256AddPrecompileAddr: &bn256Add{},
bn256ScalarMulPrecompileAddr: &bn256ScalarMul{},
bn256PairingPrecompileAddr: &bn256Pairing{},
wanCoinPrecompileAddr: &wanCoinSC{},
wanStampPrecompileAddr: &wanchainStampSC{},
//pos
WanCscPrecompileAddr: &PosStaking{},
PosControlPrecompileAddr: &PosControl{},
slotLeaderPrecompileAddr: &slotLeaderSC{},
randomBeaconPrecompileAddr: &RandomBeaconContract{},
SolEnhancePrecompileAddr: &SolEnhance{},
s256AddPrecompileAddr: &s256Add{},
s256ScalarMulPrecompileAddr: &s256ScalarMul{},
}
func IsPosPrecompiledAddr(addr *common.Address) bool {
if addr == nil {
return false
}
if (*addr) == slotLeaderPrecompileAddr ||
(*addr) == IncentivePrecompileAddr ||
(*addr) == randomBeaconPrecompileAddr {
return true
}
return false
}