Skip to content

Commit

Permalink
fix: add Hertz precomile contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da committed May 17, 2023
1 parent 67da316 commit 56608fe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions core/vm/contracts.go
Expand Up @@ -179,6 +179,25 @@ var PrecompiledContractsPlato = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{103}): &cometBFTLightBlockValidate{},
}

// PrecompiledContractsHertz contains the default set of pre-compiled Ethereum
// contracts used in the Hertz release.
var PrecompiledContractsHertz = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{1}): &ecrecover{},
common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160hash{},
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}): &blake2F{},

common.BytesToAddress([]byte{100}): &tmHeaderValidate{},
common.BytesToAddress([]byte{101}): &iavlMerkleProofValidatePlato{},
common.BytesToAddress([]byte{102}): &blsSignatureVerify{},
common.BytesToAddress([]byte{103}): &cometBFTLightBlockValidate{},
}

// 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 @@ -194,6 +213,7 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
}

var (
PrecompiledAddressesHertz []common.Address
PrecompiledAddressesPlato []common.Address
PrecompiledAddressesLuban []common.Address
PrecompiledAddressesPlanck []common.Address
Expand Down Expand Up @@ -233,11 +253,16 @@ func init() {
for k := range PrecompiledContractsPlato {
PrecompiledAddressesPlato = append(PrecompiledAddressesPlato, k)
}
for k := range PrecompiledContractsHertz {
PrecompiledAddressesHertz = append(PrecompiledAddressesHertz, k)
}
}

// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address {
switch {
case rules.IsHertz:
return PrecompiledAddressesHertz
case rules.IsPlato:
return PrecompiledAddressesPlato
case rules.IsLuban:
Expand Down
2 changes: 2 additions & 0 deletions core/vm/evm.go
Expand Up @@ -51,6 +51,8 @@ type (
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
var precompiles map[common.Address]PrecompiledContract
switch {
case evm.chainRules.IsHertz:
precompiles = PrecompiledContractsHertz
case evm.chainRules.IsPlato:
precompiles = PrecompiledContractsPlato
case evm.chainRules.IsLuban:
Expand Down
2 changes: 2 additions & 0 deletions params/config.go
Expand Up @@ -879,6 +879,7 @@ type Rules struct {
IsPlanck bool
IsLuban bool
IsPlato bool
IsHertz bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -905,5 +906,6 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool) Rules {
IsPlanck: c.IsPlanck(num),
IsLuban: c.IsLuban(num),
IsPlato: c.IsPlato(num),
IsHertz: c.IsHertz(num),
}
}

0 comments on commit 56608fe

Please sign in to comment.