mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
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:
parent
4bdf6d096c
commit
ea43834c19
4 changed files with 36 additions and 10 deletions
2
Makefile
2
Makefile
|
|
@ -41,6 +41,8 @@ test: all
|
|||
cd ${PWD}/cmd/geth; go test -test.run TestCustomGenesis
|
||||
# module test
|
||||
$(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.
|
||||
$(GORUN) build/ci.go lint
|
||||
|
|
|
|||
|
|
@ -126,6 +126,21 @@ var PrecompiledContractsBernoulli = map[common.Address]PrecompiledContract{
|
|||
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
|
||||
// contracts specified in EIP-2537. These are exported for testing purposes.
|
||||
var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
|
||||
|
|
@ -140,13 +155,8 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
|
|||
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 (
|
||||
PrecompiledAddressesEuclidV2 []common.Address
|
||||
PrecompiledAddressesBernoulli []common.Address
|
||||
PrecompiledAddressesArchimedes []common.Address
|
||||
PrecompiledAddressesBerlin []common.Address
|
||||
|
|
@ -174,11 +184,16 @@ func init() {
|
|||
for k := range PrecompiledContractsBernoulli {
|
||||
PrecompiledAddressesBernoulli = append(PrecompiledAddressesBernoulli, k)
|
||||
}
|
||||
for k := range PrecompiledContractsEuclidV2 {
|
||||
PrecompiledAddressesEuclidV2 = append(PrecompiledAddressesEuclidV2, k)
|
||||
}
|
||||
}
|
||||
|
||||
// ActivePrecompiles returns the precompiles enabled with the current configuration.
|
||||
func ActivePrecompiles(rules params.Rules) []common.Address {
|
||||
switch {
|
||||
case rules.IsEuclidV2:
|
||||
return PrecompiledAddressesEuclidV2
|
||||
case rules.IsBernoulli:
|
||||
return PrecompiledAddressesBernoulli
|
||||
case rules.IsArchimedes:
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ type (
|
|||
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
|
||||
var precompiles map[common.Address]PrecompiledContract
|
||||
switch {
|
||||
case evm.chainRules.IsEuclidV2:
|
||||
precompiles = PrecompiledContractsEuclidV2
|
||||
case evm.chainRules.IsBernoulli:
|
||||
precompiles = PrecompiledContractsBernoulli
|
||||
case evm.chainRules.IsArchimedes:
|
||||
|
|
|
|||
|
|
@ -639,6 +639,7 @@ type ChainConfig struct {
|
|||
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)
|
||||
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
|
||||
// the network that triggers the consensus upgrade.
|
||||
|
|
@ -899,21 +900,26 @@ func (c *ChainConfig) IsCurie(num *big.Int) bool {
|
|||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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.
|
||||
func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool {
|
||||
if c.TerminalTotalDifficulty == nil {
|
||||
|
|
@ -1126,7 +1132,7 @@ type Rules struct {
|
|||
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
|
||||
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul 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.
|
||||
|
|
@ -1153,5 +1159,6 @@ func (c *ChainConfig) Rules(num *big.Int, time uint64) Rules {
|
|||
IsCurie: c.IsCurie(num),
|
||||
IsDarwin: c.IsDarwin(time),
|
||||
IsEuclid: c.IsEuclid(time),
|
||||
IsEuclidV2: c.IsEuclidV2(time),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue