From f8319151a400f6c89ec37c7ad43553e884c3af40 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:40:12 -0700 Subject: [PATCH] rebase fixes --- core/vm/contracts_with_ctx.go | 17 +++++++---------- miner/miner_test.go | 2 +- tests/fuzzers/bls12381/precompile_fuzzer.go | 5 +++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/core/vm/contracts_with_ctx.go b/core/vm/contracts_with_ctx.go index cd5b7733cc..cf80f44552 100644 --- a/core/vm/contracts_with_ctx.go +++ b/core/vm/contracts_with_ctx.go @@ -7,9 +7,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" + "github.com/holiman/uint256" ) // Wrapper type which allows PrecompiledContract to be used as PrecompiledContractWithCtx @@ -45,10 +45,10 @@ func NewContext(caller common.Address, evm *EVM) *precompileContext { } var vmBlockCtx = BlockContext{ - CanTransfer: func(db StateDB, addr common.Address, amount *big.Int) bool { + CanTransfer: func(db StateDB, addr common.Address, amount *uint256.Int) bool { return db.GetBalance(addr).Cmp(amount) >= 0 }, - Transfer: func(StateDB, common.Address, common.Address, *big.Int) { + Transfer: func(StateDB, common.Address, common.Address, *uint256.Int) { panic("transfer: not implemented") }, GetHash: func(u uint64) common.Hash { @@ -90,10 +90,8 @@ func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) { } mintTo := common.BytesToAddress(input[0:32]) - - var parsed bool - value, parsed := math.ParseBig256(hexutil.Encode(input[32:64])) - if !parsed { + value, err := uint256.FromHex(hexutil.Encode(input[32:64])) + if err != nil { log.Error("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64])) return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64])) } @@ -124,9 +122,8 @@ func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) { burnFrom := common.BytesToAddress(input[0:32]) - var parsed bool - value, parsed := math.ParseBig256(hexutil.Encode(input[32:64])) - if !parsed { + value, err := uint256.FromHex(hexutil.Encode(input[32:64])) + if err != nil { log.Error("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64])) return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64])) } diff --git a/miner/miner_test.go b/miner/miner_test.go index c025715c85..c49c7af050 100644 --- a/miner/miner_test.go +++ b/miner/miner_test.go @@ -280,7 +280,7 @@ func minerTestGenesisBlock(period uint64, gasLimit uint64, faucet common.Address GasLimit: gasLimit, BaseFee: big.NewInt(params.InitialBaseFee), Difficulty: big.NewInt(1), - Alloc: map[common.Address]types.Account{ + Alloc: types.GenesisAlloc{ common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256 common.BytesToAddress([]byte{3}): {Balance: big.NewInt(1)}, // RIPEMD diff --git a/tests/fuzzers/bls12381/precompile_fuzzer.go b/tests/fuzzers/bls12381/precompile_fuzzer.go index 7d635e4c6e..1c31ae91d2 100644 --- a/tests/fuzzers/bls12381/precompile_fuzzer.go +++ b/tests/fuzzers/bls12381/precompile_fuzzer.go @@ -24,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" + "github.com/holiman/uint256" ) const ( @@ -63,10 +64,10 @@ func checkInput(id byte, inputLen int) bool { } var vmBlockCtx = vm.BlockContext{ - CanTransfer: func(db vm.StateDB, addr common.Address, amount *big.Int) bool { + CanTransfer: func(db vm.StateDB, addr common.Address, amount *uint256.Int) bool { return db.GetBalance(addr).Cmp(amount) >= 0 }, - Transfer: func(vm.StateDB, common.Address, common.Address, *big.Int) { + Transfer: func(vm.StateDB, common.Address, common.Address, *uint256.Int) { panic("transfer: not implemented") }, GetHash: func(u uint64) common.Hash {