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>
This commit is contained in:
colin 2025-02-06 16:37:28 +08:00 committed by GitHub
parent 4bdf6d096c
commit ea43834c19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 36 additions and 10 deletions

View file

@ -41,6 +41,8 @@ test: all
cd ${PWD}/cmd/geth; go test -test.run TestCustomGenesis cd ${PWD}/cmd/geth; go test -test.run TestCustomGenesis
# module test # module test
$(GORUN) build/ci.go test ./consensus ./core ./eth ./miner ./node ./trie ./rollup/... $(GORUN) build/ci.go test ./consensus ./core ./eth ./miner ./node ./trie ./rollup/...
# RIP-7212 (secp256r1) precompiled contract test
cd ${PWD}/core/vm; go test -v -run=^TestPrecompiledP256 -bench=^BenchmarkPrecompiledP256
lint: ## Run linters. lint: ## Run linters.
$(GORUN) build/ci.go lint $(GORUN) build/ci.go lint

View file

@ -126,6 +126,21 @@ var PrecompiledContractsBernoulli = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{9}): &blake2FDisabled{}, common.BytesToAddress([]byte{9}): &blake2FDisabled{},
} }
// PrecompiledContractsEuclidV2 contains the default set of pre-compiled Ethereum
// contracts used in the EuclidV2 release. Same as Bernoulli and adds p256Verify
var PrecompiledContractsEuclidV2 = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{1}): &ecrecover{},
common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160hashDisabled{},
common.BytesToAddress([]byte{4}): &dataCopy{},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
common.BytesToAddress([]byte{9}): &blake2FDisabled{},
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
}
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum // PrecompiledContractsBLS contains the set of pre-compiled Ethereum
// contracts specified in EIP-2537. These are exported for testing purposes. // contracts specified in EIP-2537. These are exported for testing purposes.
var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
@ -140,13 +155,8 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{18}): &bls12381MapG2{}, common.BytesToAddress([]byte{18}): &bls12381MapG2{},
} }
// PrecompiledContractsP256Verify contains the precompiled Ethereum
// contract specified in EIP-7212/RIP-7212. This is exported for testing purposes.
var PrecompiledContractsP256Verify = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
}
var ( var (
PrecompiledAddressesEuclidV2 []common.Address
PrecompiledAddressesBernoulli []common.Address PrecompiledAddressesBernoulli []common.Address
PrecompiledAddressesArchimedes []common.Address PrecompiledAddressesArchimedes []common.Address
PrecompiledAddressesBerlin []common.Address PrecompiledAddressesBerlin []common.Address
@ -174,11 +184,16 @@ func init() {
for k := range PrecompiledContractsBernoulli { for k := range PrecompiledContractsBernoulli {
PrecompiledAddressesBernoulli = append(PrecompiledAddressesBernoulli, k) PrecompiledAddressesBernoulli = append(PrecompiledAddressesBernoulli, k)
} }
for k := range PrecompiledContractsEuclidV2 {
PrecompiledAddressesEuclidV2 = append(PrecompiledAddressesEuclidV2, k)
}
} }
// ActivePrecompiles returns the precompiles enabled with the current configuration. // ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address { func ActivePrecompiles(rules params.Rules) []common.Address {
switch { switch {
case rules.IsEuclidV2:
return PrecompiledAddressesEuclidV2
case rules.IsBernoulli: case rules.IsBernoulli:
return PrecompiledAddressesBernoulli return PrecompiledAddressesBernoulli
case rules.IsArchimedes: case rules.IsArchimedes:

View file

@ -46,6 +46,8 @@ type (
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) { func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
var precompiles map[common.Address]PrecompiledContract var precompiles map[common.Address]PrecompiledContract
switch { switch {
case evm.chainRules.IsEuclidV2:
precompiles = PrecompiledContractsEuclidV2
case evm.chainRules.IsBernoulli: case evm.chainRules.IsBernoulli:
precompiles = PrecompiledContractsBernoulli precompiles = PrecompiledContractsBernoulli
case evm.chainRules.IsArchimedes: case evm.chainRules.IsArchimedes:

View file

@ -639,6 +639,7 @@ type ChainConfig struct {
DarwinTime *uint64 `json:"darwinTime,omitempty"` // Darwin switch time (nil = no fork, 0 = already on darwin) DarwinTime *uint64 `json:"darwinTime,omitempty"` // Darwin switch time (nil = no fork, 0 = already on darwin)
DarwinV2Time *uint64 `json:"darwinv2Time,omitempty"` // DarwinV2 switch time (nil = no fork, 0 = already on darwinv2) DarwinV2Time *uint64 `json:"darwinv2Time,omitempty"` // DarwinV2 switch time (nil = no fork, 0 = already on darwinv2)
EuclidTime *uint64 `json:"euclidTime,omitempty"` // Euclid switch time (nil = no fork, 0 = already on euclid) EuclidTime *uint64 `json:"euclidTime,omitempty"` // Euclid switch time (nil = no fork, 0 = already on euclid)
EuclidV2Time *uint64 `json:"euclidv2Time,omitempty"` // EuclidV2 switch time (nil = no fork, 0 = already on euclidv2)
// TerminalTotalDifficulty is the amount of total difficulty reached by // TerminalTotalDifficulty is the amount of total difficulty reached by
// the network that triggers the consensus upgrade. // the network that triggers the consensus upgrade.
@ -899,21 +900,26 @@ func (c *ChainConfig) IsCurie(num *big.Int) bool {
return isForked(c.CurieBlock, num) return isForked(c.CurieBlock, num)
} }
// IsDarwin returns whether num is either equal to the Darwin fork block or greater. // IsDarwin returns whether time is either equal to the Darwin fork time or greater.
func (c *ChainConfig) IsDarwin(now uint64) bool { func (c *ChainConfig) IsDarwin(now uint64) bool {
return isForkedTime(now, c.DarwinTime) return isForkedTime(now, c.DarwinTime)
} }
// IsDarwinV2 returns whether num is either equal to the DarwinV2 fork block or greater. // IsDarwinV2 returns whether time is either equal to the DarwinV2 fork time or greater.
func (c *ChainConfig) IsDarwinV2(now uint64) bool { func (c *ChainConfig) IsDarwinV2(now uint64) bool {
return isForkedTime(now, c.DarwinV2Time) return isForkedTime(now, c.DarwinV2Time)
} }
// IsEuclid returns whether num is either equal to the Darwin fork block or greater. // IsEuclid returns whether time is either equal to the Euclid fork time or greater.
func (c *ChainConfig) IsEuclid(now uint64) bool { func (c *ChainConfig) IsEuclid(now uint64) bool {
return isForkedTime(now, c.EuclidTime) return isForkedTime(now, c.EuclidTime)
} }
// IsEuclidV2 returns whether time is either equal to the EuclidV2 fork time or greater.
func (c *ChainConfig) IsEuclidV2(now uint64) bool {
return isForkedTime(now, c.EuclidV2Time)
}
// IsTerminalPoWBlock returns whether the given block is the last block of PoW stage. // IsTerminalPoWBlock returns whether the given block is the last block of PoW stage.
func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool { func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool {
if c.TerminalTotalDifficulty == nil { if c.TerminalTotalDifficulty == nil {
@ -1126,7 +1132,7 @@ type Rules struct {
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsLondon, IsArchimedes, IsShanghai bool IsBerlin, IsLondon, IsArchimedes, IsShanghai bool
IsBernoulli, IsCurie, IsDarwin, IsEuclid bool IsBernoulli, IsCurie, IsDarwin, IsEuclid, IsEuclidV2 bool
} }
// Rules ensures c's ChainID is not nil. // Rules ensures c's ChainID is not nil.
@ -1153,5 +1159,6 @@ func (c *ChainConfig) Rules(num *big.Int, time uint64) Rules {
IsCurie: c.IsCurie(num), IsCurie: c.IsCurie(num),
IsDarwin: c.IsDarwin(time), IsDarwin: c.IsDarwin(time),
IsEuclid: c.IsEuclid(time), IsEuclid: c.IsEuclid(time),
IsEuclidV2: c.IsEuclidV2(time),
} }
} }