-
Notifications
You must be signed in to change notification settings - Fork 274
Bug: Zero address returned from contract call causes exception #226
Comments
I think this is related to #239
|
BTW - this happens any time any function returns the default variable. Not just for addresses, also other value types... maybe this is a hint? |
Trying to debug the cause. Effect is a problem with Buffer decoding but even the 0x response is incorrect. |
Sure im happy to help. I ve worked around it by using a different library for reading from functions. Very annoying! |
That was my question! This is the basic call of a function so not sure how the tests passes. |
I used this: https://github.com/y-pakorn/flutter_web3 the problem with flutter_web3 library is that its not native dart, so impossible to debug anything. Also smaller community/less testing? plus side of flutter_web3 is that it uses ethers js library which is the gold standard. Happy to help make web3dart better |
Oh I see it is a wrapper around .js so it also mean limitation in going mobile or desktop. I'd rather help build a standard around web3dart if possible for multi platforms. Digging now. Keep you updated in the coming hours. |
Im very keen on the mobile part. basically at the moment its impossible to use web3dart with metamask on mobile platform would love to cooperate to make this possible. |
It is possible you need to use wallet connect |
Hi @simolus3 would you accept a bounty to resolve this case? |
happy to contribute (to the bounty) as well! |
Sorry for the delay on this issue. I'm not too involved in the Ethereum ecosystem anymore, but I'll try to maintain this package as best as I can. I tried to reproduce this issue with the following contract: pragma solidity >=0.7.0 <0.9.0;
contract ReturnDefaults {
function zero_int() public pure returns (int) {
return 0;
}
function zero_address() public pure returns (address) {
return address(0);
}
} I've deployed this to a local Ganache instance and then ran this script: import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
import 'test.g.dart';
Future<void> main() async {
final client = Web3Client('http://localhost:7545', Client());
final contract = Test(
address:
EthereumAddress.fromHex('0x4BBA8dcCAff0Dd855e6EC6400cc8494Bfa904c57'),
client: client);
print(await contract.zero_address());
print(await contract.zero_int());
} This prints zero for me, I don't get the range error here. If you have clear instructions on how to reproduce this (ideally, some simple contract source code + the local chain software) I'm happy to take another look. I don't need a bounty for this, just happy to help. |
Thx for the quick reply. The easiest way is to use hardhat It will create a default local chain and contract
Called |
@simolus3 Who is taking care of this repo now? |
That also works for me? I ran import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
import 'test.g.dart';
Future<void> main() async {
final client = Web3Client('http://localhost:8545', Client());
final contract = Test(
address:
EthereumAddress.fromHex('0x5FbDB2315678afecb367f032d93F642f64180aa3'),
client: client);
print(await contract.greet()); // Hello, Hardhat!
} I get the "Value not in range: 32" error only if I pick the wrong contract address. The error message sure could be better here, but I assume that's not the actual cause for you?
I still am. If anyone wants to help, I'm happy to add new maintainers or transfer the repo, but I need to make sure it's not going into the wrong hands since this package may manage private keys for users. |
That is a good news! Just need to find where the diff is. Also I test in a Flutter app. Need to try a direct call like you. Contract address are always the same in hardhat And this is my Greeter.abi.json
|
• Flutter version 2.8.1 at .../flutter |
I'm on Dart 2.15.1 as well, I'll try to reproduce this with Flutter as well. Either way, it might be easier to find differences by adding a logging layer for RPC requests to the Ethereum node: class LoggingRpc extends RpcService {
final RpcService inner;
LoggingRpc(this.inner);
factory LoggingRpc.defaults() {
return LoggingRpc(JsonRPC('http://localhost:8545', Client()));
}
@override
Future<RPCResponse> call(String function, [List? params]) async {
print('REQ: Call $function with $params');
final response = await inner(function, params);
print('RES: ${response.id} = ${response.result}');
return response;
}
}
void main() {
final client = Web3Client.custom(LoggingRpc.defaults());
// ...
} The request should be |
Interesting points in this code
The first line will complete and I get an explorable Transaction. With log |
Also logged what the node is seeing and I get
So something fishy here no doubt |
I found this bug in the library where a zero address returned from a contract results in an exception (because zero address is '0x0'). I suggest manipulating return data from contracts to check for zero address. It is quite typical for contracts to search an internal map for an address, returning zero address if it cannot find it.
The text was updated successfully, but these errors were encountered: