Skip to content

Commit ea43834

Browse files
colinlyguoThegaram
andauthored
feat: enable p256Verify in EuclidV2 (#1111)
* enable p256Verify in euclid v2 * try enabling all test cases under ./core * add secp256r1 precompile test in CI * remove unused export * Update params/config.go Co-authored-by: Péter Garamvölgyi <peter@scroll.io> * add EuclidV2Time in ChainConfig * fix a typo --------- Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
1 parent 4bdf6d0 commit ea43834

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ test: all
4141
cd ${PWD}/cmd/geth; go test -test.run TestCustomGenesis
4242
# module test
4343
$(GORUN) build/ci.go test ./consensus ./core ./eth ./miner ./node ./trie ./rollup/...
44+
# RIP-7212 (secp256r1) precompiled contract test
45+
cd ${PWD}/core/vm; go test -v -run=^TestPrecompiledP256 -bench=^BenchmarkPrecompiledP256
4446

4547
lint: ## Run linters.
4648
$(GORUN) build/ci.go lint

core/vm/contracts.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ var PrecompiledContractsBernoulli = map[common.Address]PrecompiledContract{
126126
common.BytesToAddress([]byte{9}): &blake2FDisabled{},
127127
}
128128

129+
// PrecompiledContractsEuclidV2 contains the default set of pre-compiled Ethereum
130+
// contracts used in the EuclidV2 release. Same as Bernoulli and adds p256Verify
131+
var PrecompiledContractsEuclidV2 = map[common.Address]PrecompiledContract{
132+
common.BytesToAddress([]byte{1}): &ecrecover{},
133+
common.BytesToAddress([]byte{2}): &sha256hash{},
134+
common.BytesToAddress([]byte{3}): &ripemd160hashDisabled{},
135+
common.BytesToAddress([]byte{4}): &dataCopy{},
136+
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
137+
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
138+
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
139+
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
140+
common.BytesToAddress([]byte{9}): &blake2FDisabled{},
141+
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
142+
}
143+
129144
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum
130145
// contracts specified in EIP-2537. These are exported for testing purposes.
131146
var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
@@ -140,13 +155,8 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
140155
common.BytesToAddress([]byte{18}): &bls12381MapG2{},
141156
}
142157

143-
// PrecompiledContractsP256Verify contains the precompiled Ethereum
144-
// contract specified in EIP-7212/RIP-7212. This is exported for testing purposes.
145-
var PrecompiledContractsP256Verify = map[common.Address]PrecompiledContract{
146-
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
147-
}
148-
149158
var (
159+
PrecompiledAddressesEuclidV2 []common.Address
150160
PrecompiledAddressesBernoulli []common.Address
151161
PrecompiledAddressesArchimedes []common.Address
152162
PrecompiledAddressesBerlin []common.Address
@@ -174,11 +184,16 @@ func init() {
174184
for k := range PrecompiledContractsBernoulli {
175185
PrecompiledAddressesBernoulli = append(PrecompiledAddressesBernoulli, k)
176186
}
187+
for k := range PrecompiledContractsEuclidV2 {
188+
PrecompiledAddressesEuclidV2 = append(PrecompiledAddressesEuclidV2, k)
189+
}
177190
}
178191

179192
// ActivePrecompiles returns the precompiles enabled with the current configuration.
180193
func ActivePrecompiles(rules params.Rules) []common.Address {
181194
switch {
195+
case rules.IsEuclidV2:
196+
return PrecompiledAddressesEuclidV2
182197
case rules.IsBernoulli:
183198
return PrecompiledAddressesBernoulli
184199
case rules.IsArchimedes:

core/vm/evm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type (
4646
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
4747
var precompiles map[common.Address]PrecompiledContract
4848
switch {
49+
case evm.chainRules.IsEuclidV2:
50+
precompiles = PrecompiledContractsEuclidV2
4951
case evm.chainRules.IsBernoulli:
5052
precompiles = PrecompiledContractsBernoulli
5153
case evm.chainRules.IsArchimedes:

params/config.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ type ChainConfig struct {
639639
DarwinTime *uint64 `json:"darwinTime,omitempty"` // Darwin switch time (nil = no fork, 0 = already on darwin)
640640
DarwinV2Time *uint64 `json:"darwinv2Time,omitempty"` // DarwinV2 switch time (nil = no fork, 0 = already on darwinv2)
641641
EuclidTime *uint64 `json:"euclidTime,omitempty"` // Euclid switch time (nil = no fork, 0 = already on euclid)
642+
EuclidV2Time *uint64 `json:"euclidv2Time,omitempty"` // EuclidV2 switch time (nil = no fork, 0 = already on euclidv2)
642643

643644
// TerminalTotalDifficulty is the amount of total difficulty reached by
644645
// the network that triggers the consensus upgrade.
@@ -899,21 +900,26 @@ func (c *ChainConfig) IsCurie(num *big.Int) bool {
899900
return isForked(c.CurieBlock, num)
900901
}
901902

902-
// IsDarwin returns whether num is either equal to the Darwin fork block or greater.
903+
// IsDarwin returns whether time is either equal to the Darwin fork time or greater.
903904
func (c *ChainConfig) IsDarwin(now uint64) bool {
904905
return isForkedTime(now, c.DarwinTime)
905906
}
906907

907-
// IsDarwinV2 returns whether num is either equal to the DarwinV2 fork block or greater.
908+
// IsDarwinV2 returns whether time is either equal to the DarwinV2 fork time or greater.
908909
func (c *ChainConfig) IsDarwinV2(now uint64) bool {
909910
return isForkedTime(now, c.DarwinV2Time)
910911
}
911912

912-
// IsEuclid returns whether num is either equal to the Darwin fork block or greater.
913+
// IsEuclid returns whether time is either equal to the Euclid fork time or greater.
913914
func (c *ChainConfig) IsEuclid(now uint64) bool {
914915
return isForkedTime(now, c.EuclidTime)
915916
}
916917

918+
// IsEuclidV2 returns whether time is either equal to the EuclidV2 fork time or greater.
919+
func (c *ChainConfig) IsEuclidV2(now uint64) bool {
920+
return isForkedTime(now, c.EuclidV2Time)
921+
}
922+
917923
// IsTerminalPoWBlock returns whether the given block is the last block of PoW stage.
918924
func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool {
919925
if c.TerminalTotalDifficulty == nil {
@@ -1126,7 +1132,7 @@ type Rules struct {
11261132
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
11271133
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
11281134
IsBerlin, IsLondon, IsArchimedes, IsShanghai bool
1129-
IsBernoulli, IsCurie, IsDarwin, IsEuclid bool
1135+
IsBernoulli, IsCurie, IsDarwin, IsEuclid, IsEuclidV2 bool
11301136
}
11311137

11321138
// Rules ensures c's ChainID is not nil.
@@ -1153,5 +1159,6 @@ func (c *ChainConfig) Rules(num *big.Int, time uint64) Rules {
11531159
IsCurie: c.IsCurie(num),
11541160
IsDarwin: c.IsDarwin(time),
11551161
IsEuclid: c.IsEuclid(time),
1162+
IsEuclidV2: c.IsEuclidV2(time),
11561163
}
11571164
}

0 commit comments

Comments
 (0)