@@ -20,14 +20,15 @@ import (
20
20
"crypto/sha256"
21
21
"encoding/binary"
22
22
"errors"
23
+ "math/big"
24
+
23
25
"github.com/ethereum/go-ethereum/common"
24
26
"github.com/ethereum/go-ethereum/common/math"
25
27
"github.com/ethereum/go-ethereum/crypto"
26
28
"github.com/ethereum/go-ethereum/crypto/blake2b"
27
29
"github.com/ethereum/go-ethereum/crypto/bls12381"
28
30
"github.com/ethereum/go-ethereum/crypto/bn256"
29
31
"github.com/ethereum/go-ethereum/params"
30
- "math/big"
31
32
32
33
//lint:ignore SA1019 Needed for precompile
33
34
"golang.org/x/crypto/ripemd160"
@@ -41,56 +42,6 @@ type PrecompiledContract interface {
41
42
Run (input []byte ) ([]byte , error ) // Run runs the precompiled contract
42
43
}
43
44
44
- // PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum
45
- // contracts used in the Frontier and Homestead releases.
46
- var PrecompiledContractsHomestead = map [common.Address ]PrecompiledContract {
47
- common .BytesToAddress ([]byte {1 }): & ecrecover {},
48
- common .BytesToAddress ([]byte {2 }): & sha256hash {},
49
- common .BytesToAddress ([]byte {3 }): & ripemd160hash {},
50
- common .BytesToAddress ([]byte {4 }): & dataCopy {},
51
- }
52
-
53
- // PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum
54
- // contracts used in the Byzantium release.
55
- var PrecompiledContractsByzantium = map [common.Address ]PrecompiledContract {
56
- common .BytesToAddress ([]byte {1 }): & ecrecover {},
57
- common .BytesToAddress ([]byte {2 }): & sha256hash {},
58
- common .BytesToAddress ([]byte {3 }): & ripemd160hash {},
59
- common .BytesToAddress ([]byte {4 }): & dataCopy {},
60
- common .BytesToAddress ([]byte {5 }): & bigModExp {eip2565 : false },
61
- common .BytesToAddress ([]byte {6 }): & bn256AddByzantium {},
62
- common .BytesToAddress ([]byte {7 }): & bn256ScalarMulByzantium {},
63
- common .BytesToAddress ([]byte {8 }): & bn256PairingByzantium {},
64
- }
65
-
66
- // PrecompiledContractsIstanbul contains the default set of pre-compiled Ethereum
67
- // contracts used in the Istanbul release.
68
- var PrecompiledContractsIstanbul = map [common.Address ]PrecompiledContract {
69
- common .BytesToAddress ([]byte {1 }): & ecrecover {},
70
- common .BytesToAddress ([]byte {2 }): & sha256hash {},
71
- common .BytesToAddress ([]byte {3 }): & ripemd160hash {},
72
- common .BytesToAddress ([]byte {4 }): & dataCopy {},
73
- common .BytesToAddress ([]byte {5 }): & bigModExp {eip2565 : false },
74
- common .BytesToAddress ([]byte {6 }): & bn256AddIstanbul {},
75
- common .BytesToAddress ([]byte {7 }): & bn256ScalarMulIstanbul {},
76
- common .BytesToAddress ([]byte {8 }): & bn256PairingIstanbul {},
77
- common .BytesToAddress ([]byte {9 }): & blake2F {},
78
- }
79
-
80
- // PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum
81
- // contracts used in the Berlin release.
82
- var PrecompiledContractsBerlin = map [common.Address ]PrecompiledContract {
83
- common .BytesToAddress ([]byte {1 }): & ecrecover {},
84
- common .BytesToAddress ([]byte {2 }): & sha256hash {},
85
- common .BytesToAddress ([]byte {3 }): & ripemd160hash {},
86
- common .BytesToAddress ([]byte {4 }): & dataCopy {},
87
- common .BytesToAddress ([]byte {5 }): & bigModExp {eip2565 : true },
88
- common .BytesToAddress ([]byte {6 }): & bn256AddIstanbul {},
89
- common .BytesToAddress ([]byte {7 }): & bn256ScalarMulIstanbul {},
90
- common .BytesToAddress ([]byte {8 }): & bn256PairingIstanbul {},
91
- common .BytesToAddress ([]byte {9 }): & blake2F {},
92
- }
93
-
94
45
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum
95
46
// contracts specified in EIP-2537. These are exported for testing purposes.
96
47
var PrecompiledContractsBLS = map [common.Address ]PrecompiledContract {
@@ -106,13 +57,78 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
106
57
}
107
58
108
59
var (
109
- PrecompiledAddressesBerlin []common.Address
110
- PrecompiledAddressesIstanbul []common.Address
111
- PrecompiledAddressesByzantium []common.Address
112
- PrecompiledAddressesHomestead []common.Address
60
+ PrecompiledAddressesBerlin []common.Address
61
+ PrecompiledAddressesMiko []common.Address
62
+ PrecompiledAddressesConsortium []common.Address
63
+ PrecompiledAddressesIstanbul []common.Address
64
+ PrecompiledAddressesByzantium []common.Address
65
+ PrecompiledAddressesHomestead []common.Address
66
+
67
+ // PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum
68
+ // contracts used in the Frontier and Homestead releases.
69
+ PrecompiledContractsHomestead map [common.Address ]PrecompiledContract
70
+
71
+ // PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum
72
+ // contracts used in the Byzantium release.
73
+ PrecompiledContractsByzantium map [common.Address ]PrecompiledContract
74
+
75
+ // PrecompiledContractsIstanbul contains the default set of pre-compiled Ethereum
76
+ // contracts used in the Istanbul release.
77
+ PrecompiledContractsIstanbul map [common.Address ]PrecompiledContract
78
+
79
+ // PrecompiledContractsConsortium contains additional Consortium precompiled contract
80
+ // beside PrecompiledContractsIstanbul
81
+ PrecompiledContractsConsortium map [common.Address ]PrecompiledContract
82
+
83
+ // PrecompiledContractsConsortium contains proof of possession precompiled contract
84
+ // beside PrecompiledContractsConsortium
85
+ PrecompiledContractsConsortiumMiko map [common.Address ]PrecompiledContract
86
+
87
+ // PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum
88
+ // contracts used in the Berlin release.
89
+ PrecompiledContractsBerlin map [common.Address ]PrecompiledContract
113
90
)
114
91
92
+ func copyPrecompiledContract (contracts map [common.Address ]PrecompiledContract ) map [common.Address ]PrecompiledContract {
93
+ cpy := make (map [common.Address ]PrecompiledContract )
94
+
95
+ for address , contract := range contracts {
96
+ cpy [address ] = contract
97
+ }
98
+
99
+ return cpy
100
+ }
101
+
115
102
func init () {
103
+ PrecompiledContractsHomestead = map [common.Address ]PrecompiledContract {
104
+ common .BytesToAddress ([]byte {1 }): & ecrecover {},
105
+ common .BytesToAddress ([]byte {2 }): & sha256hash {},
106
+ common .BytesToAddress ([]byte {3 }): & ripemd160hash {},
107
+ common .BytesToAddress ([]byte {4 }): & dataCopy {},
108
+ }
109
+
110
+ PrecompiledContractsByzantium = copyPrecompiledContract (PrecompiledContractsHomestead )
111
+ PrecompiledContractsByzantium [common .BytesToAddress ([]byte {5 })] = & bigModExp {eip2565 : false }
112
+ PrecompiledContractsByzantium [common .BytesToAddress ([]byte {6 })] = & bn256AddByzantium {}
113
+ PrecompiledContractsByzantium [common .BytesToAddress ([]byte {7 })] = & bn256ScalarMulByzantium {}
114
+ PrecompiledContractsByzantium [common .BytesToAddress ([]byte {8 })] = & bn256PairingByzantium {}
115
+
116
+ PrecompiledContractsIstanbul = copyPrecompiledContract (PrecompiledContractsByzantium )
117
+ PrecompiledContractsIstanbul [common .BytesToAddress ([]byte {9 })] = & blake2F {}
118
+
119
+ PrecompiledContractsConsortium = copyPrecompiledContract (PrecompiledContractsIstanbul )
120
+ PrecompiledContractsConsortium [common .BytesToAddress ([]byte {101 })] = & consortiumLog {}
121
+ PrecompiledContractsConsortium [common .BytesToAddress ([]byte {102 })] = & consortiumValidatorSorting {}
122
+ PrecompiledContractsConsortium [common .BytesToAddress ([]byte {103 })] = & consortiumVerifyHeaders {}
123
+ PrecompiledContractsConsortium [common .BytesToAddress ([]byte {104 })] = & consortiumPickValidatorSet {}
124
+ PrecompiledContractsConsortium [common .BytesToAddress ([]byte {105 })] = & consortiumValidateFinalityProof {}
125
+
126
+ PrecompiledContractsConsortiumMiko = copyPrecompiledContract (PrecompiledContractsConsortium )
127
+ PrecompiledContractsConsortiumMiko [common .BytesToAddress ([]byte {106 })] = & consortiumValidateProofOfPossession {}
128
+
129
+ PrecompiledContractsBerlin = copyPrecompiledContract (PrecompiledContractsConsortiumMiko )
130
+ PrecompiledContractsBerlin [common .BytesToAddress ([]byte {5 })] = & bigModExp {eip2565 : true }
131
+
116
132
for k := range PrecompiledContractsHomestead {
117
133
PrecompiledAddressesHomestead = append (PrecompiledAddressesHomestead , k )
118
134
}
@@ -122,6 +138,12 @@ func init() {
122
138
for k := range PrecompiledContractsIstanbul {
123
139
PrecompiledAddressesIstanbul = append (PrecompiledAddressesIstanbul , k )
124
140
}
141
+ for k := range PrecompiledContractsConsortium {
142
+ PrecompiledAddressesConsortium = append (PrecompiledAddressesConsortium , k )
143
+ }
144
+ for k := range PrecompiledContractsConsortiumMiko {
145
+ PrecompiledAddressesMiko = append (PrecompiledAddressesMiko , k )
146
+ }
125
147
for k := range PrecompiledContractsBerlin {
126
148
PrecompiledAddressesBerlin = append (PrecompiledAddressesBerlin , k )
127
149
}
@@ -132,6 +154,10 @@ func ActivePrecompiles(rules params.Rules) []common.Address {
132
154
switch {
133
155
case rules .IsBerlin :
134
156
return PrecompiledAddressesBerlin
157
+ case rules .IsMiko :
158
+ return PrecompiledAddressesMiko
159
+ case rules .IsConsortiumV2 :
160
+ return PrecompiledAddressesConsortium
135
161
case rules .IsIstanbul :
136
162
return PrecompiledAddressesIstanbul
137
163
case rules .IsByzantium :
0 commit comments