Skip to content

Commit 823719b

Browse files
authored
core/vm: enable bls-precompiles for Prague (ethereum#29552)
enables the bls-contracts on the "Prague" config, so that the testing-team can activate them to make tests.
1 parent b5902cf commit 823719b

File tree

3 files changed

+85
-55
lines changed

3 files changed

+85
-55
lines changed

core/vm/contracts.go

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -49,83 +49,86 @@ type PrecompiledContract interface {
4949
// PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum
5050
// contracts used in the Frontier and Homestead releases.
5151
var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{
52-
common.BytesToAddress([]byte{1}): &ecrecover{},
53-
common.BytesToAddress([]byte{2}): &sha256hash{},
54-
common.BytesToAddress([]byte{3}): &ripemd160hash{},
55-
common.BytesToAddress([]byte{4}): &dataCopy{},
52+
common.BytesToAddress([]byte{0x1}): &ecrecover{},
53+
common.BytesToAddress([]byte{0x2}): &sha256hash{},
54+
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
55+
common.BytesToAddress([]byte{0x4}): &dataCopy{},
5656
}
5757

5858
// PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum
5959
// contracts used in the Byzantium release.
6060
var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{
61-
common.BytesToAddress([]byte{1}): &ecrecover{},
62-
common.BytesToAddress([]byte{2}): &sha256hash{},
63-
common.BytesToAddress([]byte{3}): &ripemd160hash{},
64-
common.BytesToAddress([]byte{4}): &dataCopy{},
65-
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: false},
66-
common.BytesToAddress([]byte{6}): &bn256AddByzantium{},
67-
common.BytesToAddress([]byte{7}): &bn256ScalarMulByzantium{},
68-
common.BytesToAddress([]byte{8}): &bn256PairingByzantium{},
61+
common.BytesToAddress([]byte{0x1}): &ecrecover{},
62+
common.BytesToAddress([]byte{0x2}): &sha256hash{},
63+
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
64+
common.BytesToAddress([]byte{0x4}): &dataCopy{},
65+
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: false},
66+
common.BytesToAddress([]byte{0x6}): &bn256AddByzantium{},
67+
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulByzantium{},
68+
common.BytesToAddress([]byte{0x8}): &bn256PairingByzantium{},
6969
}
7070

7171
// PrecompiledContractsIstanbul contains the default set of pre-compiled Ethereum
7272
// contracts used in the Istanbul release.
7373
var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{
74-
common.BytesToAddress([]byte{1}): &ecrecover{},
75-
common.BytesToAddress([]byte{2}): &sha256hash{},
76-
common.BytesToAddress([]byte{3}): &ripemd160hash{},
77-
common.BytesToAddress([]byte{4}): &dataCopy{},
78-
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: false},
79-
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
80-
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
81-
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
82-
common.BytesToAddress([]byte{9}): &blake2F{},
74+
common.BytesToAddress([]byte{0x1}): &ecrecover{},
75+
common.BytesToAddress([]byte{0x2}): &sha256hash{},
76+
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
77+
common.BytesToAddress([]byte{0x4}): &dataCopy{},
78+
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: false},
79+
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{},
80+
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{},
81+
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{},
82+
common.BytesToAddress([]byte{0x9}): &blake2F{},
8383
}
8484

8585
// PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum
8686
// contracts used in the Berlin release.
8787
var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{
88-
common.BytesToAddress([]byte{1}): &ecrecover{},
89-
common.BytesToAddress([]byte{2}): &sha256hash{},
90-
common.BytesToAddress([]byte{3}): &ripemd160hash{},
91-
common.BytesToAddress([]byte{4}): &dataCopy{},
92-
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
93-
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
94-
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
95-
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
96-
common.BytesToAddress([]byte{9}): &blake2F{},
88+
common.BytesToAddress([]byte{0x1}): &ecrecover{},
89+
common.BytesToAddress([]byte{0x2}): &sha256hash{},
90+
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
91+
common.BytesToAddress([]byte{0x4}): &dataCopy{},
92+
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: true},
93+
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{},
94+
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{},
95+
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{},
96+
common.BytesToAddress([]byte{0x9}): &blake2F{},
9797
}
9898

9999
// PrecompiledContractsCancun contains the default set of pre-compiled Ethereum
100100
// contracts used in the Cancun release.
101101
var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{
102-
common.BytesToAddress([]byte{1}): &ecrecover{},
103-
common.BytesToAddress([]byte{2}): &sha256hash{},
104-
common.BytesToAddress([]byte{3}): &ripemd160hash{},
105-
common.BytesToAddress([]byte{4}): &dataCopy{},
106-
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
107-
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
108-
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
109-
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
110-
common.BytesToAddress([]byte{9}): &blake2F{},
111-
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
112-
}
113-
114-
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum
115-
// contracts specified in EIP-2537. These are exported for testing purposes.
116-
var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
117-
common.BytesToAddress([]byte{11}): &bls12381G1Add{},
118-
common.BytesToAddress([]byte{12}): &bls12381G1Mul{},
119-
common.BytesToAddress([]byte{13}): &bls12381G1MultiExp{},
120-
common.BytesToAddress([]byte{14}): &bls12381G2Add{},
121-
common.BytesToAddress([]byte{15}): &bls12381G2Mul{},
122-
common.BytesToAddress([]byte{16}): &bls12381G2MultiExp{},
123-
common.BytesToAddress([]byte{17}): &bls12381Pairing{},
124-
common.BytesToAddress([]byte{18}): &bls12381MapG1{},
125-
common.BytesToAddress([]byte{19}): &bls12381MapG2{},
126-
}
102+
common.BytesToAddress([]byte{0x1}): &ecrecover{},
103+
common.BytesToAddress([]byte{0x2}): &sha256hash{},
104+
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
105+
common.BytesToAddress([]byte{0x4}): &dataCopy{},
106+
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: true},
107+
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{},
108+
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{},
109+
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{},
110+
common.BytesToAddress([]byte{0x9}): &blake2F{},
111+
common.BytesToAddress([]byte{0xa}): &kzgPointEvaluation{},
112+
}
113+
114+
// PrecompiledContractsPrague contains the set of pre-compiled Ethereum
115+
// contracts used in the Prague release.
116+
var PrecompiledContractsPrague = map[common.Address]PrecompiledContract{
117+
common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{},
118+
common.BytesToAddress([]byte{0x0c}): &bls12381G1Mul{},
119+
common.BytesToAddress([]byte{0x0d}): &bls12381G1MultiExp{},
120+
common.BytesToAddress([]byte{0x0e}): &bls12381G2Add{},
121+
common.BytesToAddress([]byte{0x0f}): &bls12381G2Mul{},
122+
common.BytesToAddress([]byte{0x10}): &bls12381G2MultiExp{},
123+
common.BytesToAddress([]byte{0x11}): &bls12381Pairing{},
124+
common.BytesToAddress([]byte{0x12}): &bls12381MapG1{},
125+
common.BytesToAddress([]byte{0x13}): &bls12381MapG2{},
126+
}
127+
128+
var PrecompiledContractsBLS = PrecompiledContractsPrague
127129

128130
var (
131+
PrecompiledAddressesPrague []common.Address
129132
PrecompiledAddressesCancun []common.Address
130133
PrecompiledAddressesBerlin []common.Address
131134
PrecompiledAddressesIstanbul []common.Address
@@ -149,11 +152,16 @@ func init() {
149152
for k := range PrecompiledContractsCancun {
150153
PrecompiledAddressesCancun = append(PrecompiledAddressesCancun, k)
151154
}
155+
for k := range PrecompiledContractsPrague {
156+
PrecompiledAddressesPrague = append(PrecompiledAddressesPrague, k)
157+
}
152158
}
153159

154160
// ActivePrecompiles returns the precompiles enabled with the current configuration.
155161
func ActivePrecompiles(rules params.Rules) []common.Address {
156162
switch {
163+
case rules.IsPrague:
164+
return PrecompiledAddressesPrague
157165
case rules.IsCancun:
158166
return PrecompiledAddressesCancun
159167
case rules.IsBerlin:

core/vm/evm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ type (
4242
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
4343
var precompiles map[common.Address]PrecompiledContract
4444
switch {
45+
case evm.chainRules.IsPrague:
46+
precompiles = PrecompiledContractsPrague
4547
case evm.chainRules.IsCancun:
4648
precompiles = PrecompiledContractsCancun
4749
case evm.chainRules.IsBerlin:

tests/init.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,26 @@ var Forks = map[string]*params.ChainConfig{
337337
ShanghaiTime: u64(0),
338338
CancunTime: u64(15_000),
339339
},
340+
"Prague": {
341+
ChainID: big.NewInt(1),
342+
HomesteadBlock: big.NewInt(0),
343+
EIP150Block: big.NewInt(0),
344+
EIP155Block: big.NewInt(0),
345+
EIP158Block: big.NewInt(0),
346+
ByzantiumBlock: big.NewInt(0),
347+
ConstantinopleBlock: big.NewInt(0),
348+
PetersburgBlock: big.NewInt(0),
349+
IstanbulBlock: big.NewInt(0),
350+
MuirGlacierBlock: big.NewInt(0),
351+
BerlinBlock: big.NewInt(0),
352+
LondonBlock: big.NewInt(0),
353+
ArrowGlacierBlock: big.NewInt(0),
354+
MergeNetsplitBlock: big.NewInt(0),
355+
TerminalTotalDifficulty: big.NewInt(0),
356+
ShanghaiTime: u64(0),
357+
CancunTime: u64(0),
358+
PragueTime: u64(0),
359+
},
340360
}
341361

342362
// AvailableForks returns the set of defined fork names

0 commit comments

Comments
 (0)