mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 22:56:43 +00:00
feat: register custom precompiles
This commit is contained in:
parent
d5275fa798
commit
8b9df8dd26
4 changed files with 16 additions and 8 deletions
|
|
@ -53,7 +53,10 @@ type PrecompiledContract interface {
|
|||
// PrecompiledContracts contains the precompiled contracts supported at the given fork.
|
||||
type PrecompiledContracts map[common.Address]PrecompiledContract
|
||||
|
||||
var CustomPrecompiledContracts = PrecompiledContracts{}
|
||||
var CustomPrecompiledContracts = PrecompiledContracts{
|
||||
(&DASignersPrecompile{}).Address(): NewDASignersPrecompile(),
|
||||
(&WrappedA0giBasePrecompile{}).Address(): NewWrappedA0giBasePrecompile(),
|
||||
}
|
||||
|
||||
// WithCustomPrecompiles merge given precompiles with custom precompiles
|
||||
func WithCustomPrecompiles(base PrecompiledContracts) PrecompiledContracts {
|
||||
|
|
@ -287,7 +290,11 @@ func RunPrecompiledContract(
|
|||
inputCopy := make([]byte, len(input))
|
||||
copy(inputCopy, input)
|
||||
|
||||
contract := NewContract(caller, p.Address(), value, suppliedGas, evm.jumpDests)
|
||||
var jumpDests map[common.Hash]bitvec
|
||||
if evm != nil {
|
||||
jumpDests = evm.jumpDests
|
||||
}
|
||||
contract := NewContract(caller, p.Address(), value, suppliedGas, jumpDests)
|
||||
contract.Input = inputCopy
|
||||
|
||||
gasCost := p.RequiredGas(input)
|
||||
|
|
|
|||
|
|
@ -274,6 +274,7 @@ func TestPrecompileBlake2FMalformedInput(t *testing.T) {
|
|||
func TestPrecompiledEcrecover(t *testing.T) { testJson("ecRecover", "01", t) }
|
||||
|
||||
func testJson(name, addr string, t *testing.T) {
|
||||
fmt.Printf("name: %v, addr: %v\n", name, addr)
|
||||
tests, err := loadJson(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
|||
|
|
@ -62,14 +62,14 @@ type DASignersPrecompile struct {
|
|||
abi abi.ABI
|
||||
}
|
||||
|
||||
func NewDASignersPrecompile() (*DASignersPrecompile, error) {
|
||||
func NewDASignersPrecompile() *DASignersPrecompile {
|
||||
abi, err := abi.JSON(strings.NewReader(dasigners.DASignersABI))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
panic(err)
|
||||
}
|
||||
return &DASignersPrecompile{
|
||||
abi: abi,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Address implements vm.PrecompiledContract.
|
||||
|
|
|
|||
|
|
@ -70,14 +70,14 @@ func (w *WrappedA0giBasePrecompile) RequiredGas(input []byte) uint64 {
|
|||
return WrappedA0GIBaseRequiredGasMax
|
||||
}
|
||||
|
||||
func NewWrappedA0giBasePrecompile() (*WrappedA0giBasePrecompile, error) {
|
||||
func NewWrappedA0giBasePrecompile() *WrappedA0giBasePrecompile {
|
||||
abi, err := abi.JSON(strings.NewReader(wrappeda0gibase.Wrappeda0gibaseABI))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
panic(err)
|
||||
}
|
||||
return &WrappedA0giBasePrecompile{
|
||||
abi: abi,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Run implements vm.PrecompiledContract.
|
||||
|
|
|
|||
Loading…
Reference in a new issue