vm: add HPPK precompile and map to 0x0b (Cancun)

This commit is contained in:
sergelen02 2025-09-16 17:50:21 +09:00
parent e48242bb69
commit fa6fa00f51
2 changed files with 27 additions and 0 deletions

View file

@ -149,6 +149,8 @@ var PrecompiledContractsVerkle = PrecompiledContractsBerlin
// PrecompiledContractsOsaka contains the set of pre-compiled Ethereum // PrecompiledContractsOsaka contains the set of pre-compiled Ethereum
// contracts used in the Osaka release. // contracts used in the Osaka release.
var PrecompiledContractsOsaka = PrecompiledContracts{ var PrecompiledContractsOsaka = PrecompiledContracts{
common.BytesToAddress([]byte{0x0b}): &hppkPrecompile{},
common.BytesToAddress([]byte{0x01}): &ecrecover{}, common.BytesToAddress([]byte{0x01}): &ecrecover{},
common.BytesToAddress([]byte{0x02}): &sha256hash{}, common.BytesToAddress([]byte{0x02}): &sha256hash{},
common.BytesToAddress([]byte{0x03}): &ripemd160hash{}, common.BytesToAddress([]byte{0x03}): &ripemd160hash{},

View file

@ -0,0 +1,25 @@
package vm
import "errors"
const (
hppkGasBase = 3000
hppkGasPerByte = 12
)
type hppkPrecompile struct{}
func (*hppkPrecompile) Name() string { return "hppk" }
func (*hppkPrecompile) RequiredGas(input []byte) uint64 {
return uint64(hppkGasBase + hppkGasPerByte*len(input))
}
func (*hppkPrecompile) Run(input []byte) ([]byte, error) {
if len(input) < 4 {
return nil, errors.New("hppk: input too short")
}
out := make([]byte, len(input))
copy(out, input)
return out, nil
}