Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 21 additions & 6 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 11 additions & 4 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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),
}
}