0

when create contract in statedb, i get error code the error is gas uint64 overflow, the code data is not much and i just give it little gasprice, the code is following:

func NewContext() vm.Context {
    canTransferFunc := func(db vm.StateDB, addr common.Address, amount *big.Int) bool {
        return true
    }
    transferFunc := func(db vm.StateDB, sender, recipient common.Address, amount *big.Int) {
    }
    getHashFunc := func(height uint64) common.Hash {
        return common.HexToHash("0x5A0b54D5dc17e0AadC383d2db43B0a0D3E029c4c")//common.Hash{}
    }
        fromAddress := common.BytesToAddress([]byte("0x5A0b54D5dc17e0AadC383d2db43B0a0D3E029c4c"))
    coinbase := common.BytesToAddress([]byte("0x5A0b54D5dc17e0AadC383d2db43B0a0D3E029c4c"))
    context := vm.Context{
        CanTransfer: canTransferFunc,
        Transfer:    transferFunc,
        GetHash:     getHashFunc,
        Origin:      fromAddress,
        Coinbase:    coinbase,
        BlockNumber: new(big.Int).SetUint64(1000000),
        Time:        new(big.Int).SetInt64(1),
        GasLimit:    uint64(0),
        GasPrice:    new(big.Int).SetInt64(1),
    }
    return context
}
func create(con vm.Context, stateDB vm.StateDB, data []byte){
    var config vm.Config
    chainConfig := getChainConfig()
    var evmContractAddress common.Address
    executor := vm.AccountRef(con.Origin)
    evm := vm.NewEVM(con, stateDB, chainConfig, config)
    ret, evmContractAddress, remainingGas, err := evm.Create(executor, data,33300,new(big.Int).SetInt64(1))
    b := evmContractAddress.String()
    fmt.Println("go",ret, b, remainingGas)
        if err != nil{
               panic(err)
        }
}


func main(){
    bytecode := "6080604052348015600f57600080fd5b5060858061001e6000396000f300608060405260043610603e5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663b518a77681146043575b600080fd5b348015604e57600080fd5b5060556057565b005b5600a165627a7a72305820b21fcbcd892893252b8fa6f3c91a56c74a665e9262dd547df78976f69ed16b7a0029"

    statedb,_ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()))
    con := NewContext()
    create(con, statedb, []byte(bytecode))
}

go [] 0x4aB04F903335378702FDcE7252550cA5e997f411 0 panic: gas uint64 overflow

goroutine 1 [running]: main.create(0x68f8c8, 0x68f8d0, 0x68f8d8, 0x4233346264326433, 0x3230453344306130, 0x63346339, 0xc0000a9b40, 0x4233346264326433, 0x3230453344306130, 0x63346339, ...) /home/tung/htest.go:64 +0x412 main.main() /home/tung/htest.go:75 +0x18e

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.