rebase fixes

This commit is contained in:
Shawn 2024-04-17 18:40:12 -07:00
parent 645510a4e1
commit f8319151a4
3 changed files with 11 additions and 13 deletions

View file

@ -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]))
}

View file

@ -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

View file

@ -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 {