umbracle/ethgo

Panic when it sends hex string value for bytes method argument

Closed this issue · 1 comments

Describe the bug

Configuration

Method signature
issueByPartition(bytes32,address,uint256,bytes)

Steps to reproduce

  1. Use an ABI having a method signature with bytes as part of its parameters
method := web3ABI.GetMethodBySignature("issueByPartition(bytes32,address,uint256,bytes)")
  1. Define the following args:
args = [
          "0x697373756564000000000000636c617373610000000000000000000000000000",
          "0x4D61778D0b517A79Fa9482003a1E44C24e15Ab1f",
          "0x21e19e0c9bab2400000",
          "0x5fa921675accc24059691b13865835eed09bf23ce61d0e89b1d4e690116942000000000000000000000000000000000000000000000000000000000061fd657ca6cce2e20c4f5aa1c36951da5f524e7c6ffc6d59ccd4be26fd2e030b53e05c9e2756396bceabe6b5c32c9c72e65a095f9b4d67a10278b1d9972bbc1432f95a9d00"
        ]
  1. Call the following Encode for the selected method
txData, err := method.Encode(args)

Actual result

It panics, see logs below

Expected result

It should encode argument correctly

Logs

api_1            | 2022/02/04 16:42:20 http: panic serving 172.24.0.1:58708: reflect: call of reflect.Value.Bytes on string Value
api_1            | goroutine 268704 [running]:
api_1            | net/http.(*conn).serve.func1(0xc0061f6000)
api_1            | 	/usr/local/go/src/net/http/server.go:1804 +0x153
api_1            | panic(0x2d62ea0, 0xc005b11bd8)
api_1            | 	/usr/local/go/src/runtime/panic.go:971 +0x499
api_1            | reflect.flag.mustBe(...)
api_1            | 	/usr/local/go/src/reflect/value.go:221
api_1            | reflect.Value.Bytes(0x2c592e0, 0xc00557dcd0, 0x98, 0x4e38b7, 0x2d349c0, 0x0)
api_1            | 	/usr/local/go/src/reflect/value.go:289 +0xfc
api_1            | github.com/umbracle/go-web3/abi.encodeFixedBytes(0x2c592e0, 0xc00557dcd0, 0x98, 0x2c592e0, 0xc00557dcd0, 0x98, 0x4087, 0x7e00)
api_1            | 	/go/pkg/mod/github.com/umbracle/go-web3@v0.0.0-20220112152710-157826f66053/abi/encode.go:175 +0x55
api_1            | github.com/umbracle/go-web3/abi.encode(0x2d349c0, 0xc005ac45c0, 0x194, 0xc005f6f180, 0x2d349c0, 0xc005ac45c0, 0x194, 0xc00597a1b0, 0x7fb7c01e3e5b)
api_1            | 	/go/pkg/mod/github.com/umbracle/go-web3@v0.0.0-20220112152710-157826f66053/abi/encode.go:50 +0x389
api_1            | github.com/umbracle/go-web3/abi.encodeTuple(0x2beaee0, 0xc005b11bc0, 0x97, 0xc0060cd310, 0xc00597a240, 0x16, 0xa, 0x2b68640, 0xc000b23c08)
api_1            | 	/go/pkg/mod/github.com/umbracle/go-web3@v0.0.0-20220112152710-157826f66053/abi/encode.go:149 +0x2fe
api_1            | github.com/umbracle/go-web3/abi.encode(0x2beaee0, 0xc005b11bc0, 0x97, 0xc0060cd310, 0xc003ec0c68, 0x412d1b, 0xc005b11bc0, 0x18, 0x18)
api_1            | 	/go/pkg/mod/github.com/umbracle/go-web3@v0.0.0-20220112152710-157826f66053/abi/encode.go:32 +0x405
api_1            | github.com/umbracle/go-web3/abi.Encode(0x2beaee0, 0xc005b11bc0, 0xc0060cd310, 0x18, 0xc005b11bc0, 0x37a0301, 0xc000100400, 0x0)
api_1            | 	/go/pkg/mod/github.com/umbracle/go-web3@v0.0.0-20220112152710-157826f66053/abi/encode.go:19 +0xb1
api_1            | github.com/umbracle/go-web3/abi.(*Method).Encode(0xc005bc1b30, 0x2beaee0, 0xc005b11bc0, 0xc005b11bc0, 0xc0008b1230, 0xc004a58780, 0x6, 0xc0065c0900)
api_1            | 	/go/pkg/mod/github.com/umbracle/go-web3@v0.0.0-20220112152710-157826f66053/abi/abi.go:189 +0x50
api_1            | github.com/consensys/orchestrate/services/api/business/use-cases/transactions.(*sendContractTxUseCase).Execute(0xc000aeeae0, 0x3803c80, 0xc005abfa40, 0xc000c09b60, 0xc000c09b00, 0x0, 0x312a4c0, 0x30)
api_1            | 	/app/services/api/business/use-cases/transactions/send_contract_tx.go:65 +0x606

Other
Version github.com/umbracle/go-web3 v0.0.0-20220112152710-157826f66053

PR to resolve the issue #150