Skip to content

Commit

Permalink
fix failures
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster-will committed Oct 8, 2024
1 parent 8b6d536 commit f94b64e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/fuzzers/bls12381/precompile_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ package bls
import (
"bytes"
"fmt"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -70,6 +75,11 @@ func checkInput(id byte, inputLen int) bool {
//
// other values are reserved for future use.
func fuzz(id byte, data []byte) int {
vmctx := vm.BlockContext{
Transfer: func(vm.StateDB, common.Address, common.Address, *uint256.Int) {},
}
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
evm := vm.NewEVM(vmctx, vm.TxContext{}, statedb, params.AllEthashProtocolChanges, vm.Config{})
// Even on bad input, it should not crash, so we still test the gas calc
precompile := vm.PrecompiledContractsBLS[common.BytesToAddress([]byte{id})]
gas := precompile.RequiredGas(data)
Expand All @@ -82,7 +92,7 @@ func fuzz(id byte, data []byte) int {
}
cpy := make([]byte, len(data))
copy(cpy, data)
_, err := precompile.Run(cpy)
_, err := precompile.Run(evm, cpy)
if !bytes.Equal(cpy, data) {
panic(fmt.Sprintf("input data modified, precompile %d: %x %x", id, data, cpy))
}
Expand Down

0 comments on commit f94b64e

Please sign in to comment.