web3dart icon indicating copy to clipboard operation
web3dart copied to clipboard

Value not in range: 32

Open YDJSZY opened this issue 6 years ago • 37 comments

When I call your contract dart in example and it happend a error: Value not in range: 32 this is my code:

try {
      final balance = await web3client.call(
      contract: contract, function: balanceFunction, params: [ownAddress]);
      print('We have ${balance.first} MetaCoins');
    } catch (error) {
      print(error);
    }

YDJSZY avatar Sep 06 '19 06:09 YDJSZY

Can you try replacing the catch statement with

catch (error, trace) {
  print(error);
  print(trace);
}

And give me the output of the stacktrace? Thanks!

simolus3 avatar Sep 06 '19 07:09 simolus3

RangeError: Value not in range: 32 I/flutter ( 675): #0 _rangeCheck (dart:typed_data-patch/typed_data_patch.dart:4445:5) I/flutter ( 675): #1 _ByteBuffer.asUint8List (dart:typed_data-patch/typed_data_patch.dart:1923:5) I/flutter ( 675): #2 _IntTypeBase.decode (package:web3dart/src/contracts/abi/integers.dart:23:31) I/flutter ( 675): #3 TupleType.decode (package:web3dart/src/contracts/abi/tuple.dart:102:29) I/flutter ( 675): #4 ContractFunction.decodeReturnValues (package:web3dart/src/contracts/abi/abi.dart:255:30) I/flutter ( 675): #5 Web3Client.call (package:web3dart/src/core/client.dart:309:21) I/flutter ( 675): I/flutter ( 675): #6 EthSdkClient.sendErc20Transaction (package:flutter_tic_wallet/packages/blockChainSdk/eth/index.dart:103:40) I/flutter ( 675): I/flutter ( 675): #7 BlockChainSdk.sendErc20Transaction (package:flutter_tic_wallet/packages/blockChainSdk/index.dart:56:9) I/flutter ( 675): #8 main (package:flutter_tic_wallet/main.dart:35:17) I/flutter ( 675): I/flutter ( 675): #9 _runMainZoned.. (dart:ui/hooks.dart:216:25) I/flutter ( 675): #10 _rootRun (dart:async/zone.dart:1124:13) I/flutter ( 675): #11 _CustomZone.run (dart:a

YDJSZY avatar Sep 06 '19 07:09 YDJSZY

Thank you for the report. This seems similar to https://github.com/simolus3/web3dart/issues/47#issuecomment-508904925, so a bit more information would be helpful to find the cause

  1. are you running the latest flutter version? We had a very similar bug that was actually caused by Flutter
  2. does is only happen for release builds or for debug builds as well?
  3. (optional) To make debugging easier for me, can you attach a logger to the HttpClient you pass to the Web3Client constructor? The comment linked above contains information on how to do that. This lets me inspect the raw data returned from the contract. Be aware that these calls could contain potentially sensitive information (your Ethereum node, address, contract address, payload you send to the contract). You can strip out some information if you like or, if you don't want to post these details publicly, e-mail them to me at [email protected].

simolus3 avatar Sep 06 '19 07:09 simolus3

Thanks for your detail reply! I change your abi.json to https://github.com/danfinlay/human-standard-token-abi, and it work! it return my erc20 token balance successfully. my contract address is 0x01e5ad4f8fb032f80ec0e3de7f4221b46f81d4c9 and my eth address is 0x6c0d0870ec3af6411332f9524640e7f781941e0e. I used your abi.json, your privateKey and contract before, but it showed error "Value not in range: 32"

YDJSZY avatar Sep 06 '19 08:09 YDJSZY

flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel beta, v1.7.8+hotfix.2, on Mac OS X 10.13.6 17G65, locale zh-Hans-CN)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [✓] Xcode - develop for iOS and macOS (Xcode 10.1) [!] iOS tools - develop for iOS devices ✗ ios-deploy out of date (1.9.4 is required). To upgrade with Brew: brew upgrade ios-deploy [✓] Android Studio (version 3.1) [!] IntelliJ IDEA Ultimate Edition (version 2019.2) ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. [✓] VS Code (version 1.37.1) [✓] Connected device (1 available)

! Doctor found issues in 2 categories. I just run in android simulator. I think it maybe doesn't matter with flutter version.

YDJSZY avatar Sep 06 '19 08:09 YDJSZY

Oh interesting! The abi from the repo you linked doesn't define a "getBalance" function, it has a "balanceOf" function instead. They both declare the same return types though, so I'm surprised that didn't work. I'll take a more detailed look later.

simolus3 avatar Sep 06 '19 08:09 simolus3

Hey @simolus3 , I'm still getting this error. I checked, the function is available in the abi.json and also on the smart contract.

await ethClient.call(
        contract: contract,
        function: checkOrgan,
        params: [user.bloodGroup,model.organDescription]).catchError((error,trace){
          Logger(printer: PrettyPrinter()).e("Error: $error");
    })

AyushBherwani1998 avatar Mar 06 '20 02:03 AyushBherwani1998

Trace:

I/flutter ( 4767): #0 _rangeCheck (dart:typed_data-patch/typed_data_patch.dart:4631:5) I/flutter ( 4767): #1 _ByteBuffer.asUint8List (dart:typed_data-patch/typed_data_patch.dart:1931:5) I/flutter ( 4767): #2 BoolType.decode (package:web3dart/src/contracts/abi/integers.dart:132:28) I/flutter ( 4767): #3 TupleType.decode (package:web3dart/src/contracts/abi/tuple.dart:102:29) I/flutter ( 4767): #4 ContractFunction.decodeReturnValues (package:web3dart/src/contracts/abi/abi.dart:255:30) I/flutter ( 4767): #5 Web3Client.call (package:web3dart/src/core/client.dart:310:21) I/flutter ( 4767): I/flutter ( 4767): #6 ReceiveViewButton.checkAvailability (package:organ_donation/widgets/receive_organ/receive_button.dart:59:33) I/flutter ( 4767): I/flutter ( 4767): #7 ReceiveViewButton.build. (package:organ_donation/widgets/receive_organ/receive_button.dart:38:13) I/flutter ( 4767): #8 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14) I/flutter ( 4767): #9 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:789:36) I/flutter ( 4767): #10 GestureRecognizer.invokeCallback (packag

AyushBherwani1998 avatar Mar 06 '20 02:03 AyushBherwani1998

@AyushBherwani1998 Can you sent me the part of the contract abi that defines the checkOrgan function?

simolus3 avatar Mar 06 '20 08:03 simolus3

Here is the snippet from abi.json

  {
    "constant": true,
    "inputs": [
      {
        "name": "bloodGroup",
        "type": "string"
      },
      {
        "name": "description",
        "type": "string"
      }
    ],
    "name": "checkOrgan",
    "outputs": [
      {
        "name": "",
        "type": "bool"
      }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
  }

AyushBherwani1998 avatar Mar 06 '20 13:03 AyushBherwani1998

@simolus3 Any updates on the issue?

AyushBherwani1998 avatar Mar 08 '20 08:03 AyushBherwani1998

Sorry for the delay - unfortunately I couldn't find a bug in web3dart here. We have tests to verify that booleans are encoded and decoded correctly.

Can you try attaching a logger to the http client (for instance like this) and post what the eth_call request returns? If you're uncomfortable posting that publicly you can also send it to me at [email protected].

simolus3 avatar Mar 10 '20 17:03 simolus3

i got this error today with a function in the aave contract with no boolean involved only uint256 but the bug is not always here will investigate more if it reproduce

kevin-sakemaer avatar Mar 11 '20 15:03 kevin-sakemaer

here i got a stacktrace

RangeError: Value not in range: 128
#0      _rangeCheck (dart:typed_data-patch/typed_data_patch.dart:4791:5)
#1      _ByteBuffer.asUint8List (dart:typed_data-patch/typed_data_patch.dart:1931:5)
#2      _IntTypeBase.decode (package:web3dart/src/contracts/abi/integers.dart:29:31)
#3      TupleType.decode (package:web3dart/src/contracts/abi/tuple.dart:102:29)
#4      ContractFunction.decodeReturnValues (package:web3dart/src/contracts/abi/abi.dart:257:30)
#5      Web3Client.call (package:web3dart/src/core/client.dart:314:21)
<asynchronous suspension>
#6      LendingPool.getUserAccountData (package:aave_sdk/src/contracts/lending_pool.dart:328:34)
#7      main (file:///Users/kleak/Work/github.com/no-loss-investor-wallet/aave_sdk/bin/get_health_factor.dart:26:48)
<asynchronous suspension>
#8      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
#9      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

kevin-sakemaer avatar Mar 12 '20 15:03 kevin-sakemaer

in lib/src/crypto/formatting.dart when i print bytes.toList() i got this :

[8, 195, 121, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 83, 97, 102, 101, 77, 97, 116, 104, 58, 32, 115, 117, 98, 116, 114, 97, 99, 116, 105, 111, 110, 32, 111, 118, 101, 114, 102, 108, 111, 119, 0, 0]

so here we have a 100 element List but then in lib/src/contracts/abi/integers.dart if here i print the offset it got 96 with sizeUnitBytes at 32 this lead us to 128 which in above the 100 element array which lead to the error.

kevin-sakemaer avatar Mar 12 '20 15:03 kevin-sakemaer

i call the method getUserAccountData there is the return type here https://developers.aave.com/#lendingpool

Notice that not all call fail but only some of them which render the task of debugging it pretty complicated.

kevin-sakemaer avatar Mar 12 '20 15:03 kevin-sakemaer

i call the method getUserAccountData there is the return type here https://developers.aave.com/#lendingpool

Interesting. That method returns 8 uint256 values, so I'd also expect 256 bytes of payload data - it weird that we only get 100. I think the decoding failing here is correct - the 100 byte list just can't be decoded as 8 values of that type. It's worth investigating why we don't get a complete result though - what node are you connecting to? Or do you have a way for me to reproduce this?

simolus3 avatar Mar 13 '20 21:03 simolus3

i'm on mainnet and i can provide you an address that fail everytime. 0x338a370bd32b454345182365b380664cbe660998 I will open source my aave sdk soon (next week) so it will be easier to test everything.

kevin-sakemaer avatar Mar 13 '20 21:03 kevin-sakemaer

@simolus3 Here are the logs

sending https://rinkeby.infura.io/v3/b306ccbea4ad48aa97a9xxxxxx5970 with {"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0xdce881db68e093637378083611367dac5bb7ce3b","data":"0xace8a4af000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000
0000000000000000000000000000024f2b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064b69646e65790000000000000000000000000000000000000000000000000000"},"latest"],"id":1}
I/flutter ( 9100): response:
I/flutter ( 9100): {"jsonrpc":"2.0","id":1,"result":"0x"}

AyushBherwani1998 avatar Mar 14 '20 06:03 AyushBherwani1998

Thanks a lot @AyushBherwani1998! I can reproduce this problem locally. I think this might be an infura bug: https://github.com/INFURA/infura/issues/157 It's pretty weird that we get this error consistently though, and not just occasionally. It looks infura returns 0x instead of throwing an error when calling an invalid address - are you sure 0xdce881db68e093637378083611367dac5bb7ce3b is correct? I also noticed you're passing O+ (the letter) instead of 0+ (the number) as bloodGroup, but I guess that shouldn't matter for this error.

simolus3 avatar Mar 16 '20 17:03 simolus3

Thanks a lot @AyushBherwani1998! I can reproduce this problem locally. I think this might be an infura bug: INFURA/infura#157 It's pretty weird that we get this error consistently though, and not just occasionally. It looks infura returns 0x instead of throwing an error when calling an invalid address - are you sure 0xdce881db68e093637378083611367dac5bb7ce3b is correct? I also noticed you're passing O+ (the letter) instead of 0+ (the number) as bloodGroup, but I guess that shouldn't matter for this error.

This sounds weird. The address is correct. I'm able to do transactions but not able to call functions.

AyushBherwani1998 avatar Mar 17 '20 02:03 AyushBherwani1998

I had the same error. It was because although I was using the correct abiCode that corresponded to the latest version of the smart contract I was calling, I had provided a contractAddr that corresponded to a different smart contract all together. So I just provided the correct smart contract address to contractAddr to fix the issue. See code snippet below:

final contract = DeployedContract(
        ContractAbi.fromJson(abiCode, 'DataHighwayMXCMiningToken'),
        contractAddr);
final getStuffFunction = contract.function('getStuff');
await client.call(
        contract: contract,
        function: getStuffFunction,
        params: [ownAddress]);

ltfschoen avatar Jun 23 '20 15:06 ltfschoen

Hey, Ive read through the comments and it doesn't seem like a resolution was found

I'm experiencing a similar issue using ganache-cli

I'd love to dive in and provide any information needed.

dart funtion ran:

@override
  Future<void> checkUserBalance() async {
    final result = await _client.call(
      contract: _tokenContract,
      function: _balanceOf,
      params: [_ownAddress],
    );

    print(result);
  }

balanceOf definition _balanceOf = _tokenContract.function('balanceOf');

http logs:

flutter: sending http://[ip]:8545 with {"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x0e0371a25984ddeacf36827c8768561430294572","data":"0x70a082310000000000000000000000004661e0543ad3dfa8a62bd19deb3b6719d7d8f561"},"latest"],"id":1}
flutter: response:
{"id":1,"jsonrpc":"2.0","result":"0x"}

I'm curious, why is the method eth_call should it not be referencing balanceOf ?

drexel-ue avatar Dec 16 '20 22:12 drexel-ue

Here is the repo if anyone is curious: https://github.com/drexel-ue/eth_swap

drexel-ue avatar Dec 16 '20 22:12 drexel-ue

I am stuck with this error. Couldnt find any solution, did anyone managed to get the solution

I/flutter (20363): sending https://ropsten.infura.io/v3/78b90db8ffa14e85848a478a7a4b3e22 with {"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x6661ba2d65552ae933a7135cd8e24d05a9ecd46e","data":"0x70a082310000000000000000000000007ab70bdc3a9b8fa75ae2a6256e3c926e7730baa7"},"latest"],"id":2} I/flutter (20363): response: I/flutter (20363): {"jsonrpc":"2.0","id":2,"result":"0x"} I/flutter (20363): error: RangeError: Value not in range: 32 I/flutter (20363): trace: #0 _rangeCheck (dart:typed_data-patch/typed_data_patch.dart:4951:5) I/flutter (20363): #1 _ByteBuffer.asUint8List (dart:typed_data-patch/typed_data_patch.dart:1911:5) I/flutter (20363): #2 _IntTypeBase.decode package:web3dart/…/abi/integers.dart:37 I/flutter (20363): #3 TupleType.decode package:web3dart/…/abi/tuple.dart:106 I/flutter (20363): #4 ContractFunction.decodeReturnValues package:web3dart/…/abi/abi.dart:266 I/flutter (20363): #5 Web3Client.call package:web3dart/…/core/client.dart:341

ag-0214 avatar Jul 24 '21 19:07 ag-0214

Hey, does anyone have any links to resolution of this error?

I am attempting to authenticate a challenge string and coming up with a similar error in flutter.

I/flutter (26723): [151, 184, 247, 173, 50, 121, 96, 31, 147, 182, 253, 127, 173, 252, 156, 23, 164, 45, 17, 211, 108, 102, 57, 170, 127, 108, 55, 130, 3, 51, 89, 176]
E/flutter (26723): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: RangeError (start): Invalid value: Not in inclusive range 0..32: -32
E/flutter (26723): #0      RangeError.checkValidRange (dart:core/errors.dart:328:7)
E/flutter (26723): #1      _TypedIntListMixin.setRange (dart:typed_data-patch/typed_data_patch.dart:394:18)
E/flutter (26723): #2      _RFC6979KCalculator._init
package:pointycastle/signers/ecdsa_signer.dart:304
E/flutter (26723): #3      new _RFC6979KCalculator
package:pointycastle/signers/ecdsa_signer.dart:294
E/flutter (26723): #4      ECDSASigner.generateSignature
package:pointycastle/signers/ecdsa_signer.dart:102
E/flutter (26723): #5      sign
package:web3dart/…/crypto/secp256k1.dart:75
E/flutter (26723): #6      EthPrivateKey.signToSignature
package:web3dart/…/credentials/credentials.dart:110
E/flutter (26723): #7      signChallenge
package:trypto_redux/streamr/streamr_util.dart:80
E/flutter (26723): #8      jsonResponse
package:trypto_redux/streamr/streamr_util.dart:90
E/flutter (26723): #9      authenticateStreamr
package:trypto_redux/streamr/streamr_util.dart:188
E/flutter (26723): <asynchronous suspension>
E/flutter (26723):

GaryPate avatar Jul 31 '21 09:07 GaryPate

I am attempting to sign a challenge string in the following way

Future<MsgSignature> signChallenge(String challenge) async {
  final privateKey = getPrivateKey();
  final privateKeyU = utf8.encoder.convert(privateKey);
  final challengeU = keccakAscii(challenge);
  var privateKeyW3 = EthPrivateKey(privateKeyU);
  var signedChallenge = privateKeyW3.signToSignature(challengeU);

GaryPate avatar Jul 31 '21 09:07 GaryPate

I'm experiencing this same issue (September 20, 2021) - If anyone is available to help me out with this one I'll be more than willing to reply with my source code/more details. It's been a while since somebody has been able to offer some help on the matter but let me know if there are any signs of life ahah

John1Fazio avatar Sep 20 '21 17:09 John1Fazio

This happens if the RPC endpoint replies with 0x, an invalid response that cannot be parsed into the return values indicated in the ABI. The question is why that happens. If anyone has a contract with sources on a public net (can be a testnet) that reproduces this, I'd love to take a look.

simolus3 avatar Sep 21 '21 10:09 simolus3

RPC endpoint replies with 0x, an invalid response that cannot be parsed into the return values indicated in the ABI.

you can view the contract source at this address on the ropsten testnet:

0xA8c53a4D9e1D47A0E2ECCA6bd0334445541ce88F

John1Fazio avatar Sep 21 '21 21:09 John1Fazio