Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RLP decode does not seem to work #85

Closed
digitaldonkey opened this issue May 26, 2018 · 4 comments · Fixed by #87
Closed

RLP decode does not seem to work #85

digitaldonkey opened this issue May 26, 2018 · 4 comments · Fixed by #87

Comments

@digitaldonkey
Copy link

Created some example contract to test some return values.

The primitives work, but RLP types seem to be broken.

require_once "vendor/autoload.php";

use Web3\Contract;

$host = 'https://ropsten.infura.io/drupal';

$contractAddress = "0xB79D80AcfbF048d2A6E9c8f6511D0922EB50d7E1";
$abi = '[{"constant":true,"inputs":[],"name":"getBoolean","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"getInteger","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"getBytes1","outputs":[{"name":"","type":"bytes1"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"getBytes32","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"getBytes","outputs":[{"name":"","type":"bytes"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"getBytesLong","outputs":[{"name":"","type":"bytes"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"getTwoBytes32","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"getDynamicData","outputs":[{"name":"","type":"bytes"},{"name":"","type":"bytes"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"getDynamicDataMixedOne","outputs":[{"name":"","type":"bytes"},{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"getDynamicDataMixedTwo","outputs":[{"name":"","type":"bytes32"},{"name":"","type":"bytes"}],"payable":false,"stateMutability":"pure","type":"function"}]';
$contract = new Contract($host, $abi);

$functions = [
  'getBoolean',
  'getInteger',
  'getBytes1',
  'getBytes32',
  'getBytesLong',
  'getDynamicData',
  'getDynamicDataMixedOne',
  'getDynamicDataMixedTwo',
];

foreach ($functions as $f) {
    echo '<h2>' . $f .'</h2>';
    $contract->at($contractAddress)->call($f, [], 'var_dump');
}
@sc0Vu
Copy link
Member

sc0Vu commented May 27, 2018

@digitaldonkey Thanks, start to investigate.

Test with your function, decoded value was wrong:

<h2>getBoolean</h2>Error: cURL error 28: Operation timed out after 1001 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
<h2>getInteger</h2>
string(66) "0x0000000000000000000000000000000000000000000000000000000000000063"
array(1) {
  [""]=>
  object(phpseclib\Math\BigInteger)#1946 (2) {
    ["value"]=>
    string(4) "0x63"
    ["engine"]=>
    string(26) "internal (64-bit, OpenSSL)"
  }
}
<h2>getBytes1</h2>
string(66) "0x6100000000000000000000000000000000000000000000000000000000000000"
array(1) {
  [""]=>
  string(66) "0x6100000000000000000000000000000000000000000000000000000000000000"
}
<h2>getBytes32</h2>
string(66) "0x6162630000000000000000000000000000000000000000000000000000000000"
array(1) {
  [""]=>
  string(66) "0x6162630000000000000000000000000000000000000000000000000000000000"
}
<h2>getBytesLong</h2>
string(258) "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003c61626361626361626363616263616263616263636162636162636162636361626361626361626363616263616263616263636162636162636162636300000000"
array(1) {
  [""]=>
  string(66) "0x0000000000000000000000000000000000000000000000000000000000000020"
}
<h2>getDynamicData</h2>
string(386) "0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000036162630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000378797a0000000000000000000000000000000000000000000000000000000000"
array(1) {
  [""]=>
  string(66) "0x0000000000000000000000000000000000000000000000000000000000000080"
}
<h2>getDynamicDataMixedOne</h2>
string(258) "0x000000000000000000000000000000000000000000000000000000000000004078797a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000036162630000000000000000000000000000000000000000000000000000000000"
array(1) {
  [""]=>
  string(66) "0x78797a0000000000000000000000000000000000000000000000000000000000"
}
<h2>getDynamicDataMixedTwo</h2>
string(258) "0x78797a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000036162630000000000000000000000000000000000000000000000000000000000"
array(1) {
  [""]=>
  string(66) "0x0000000000000000000000000000000000000000000000000000000000000040"
}

It looks like decode params not work here......

@shendenkov
Copy link

I have the same problem.
When I get 'bytes' from my contract I receive: "0x0000000000000000000000000000000000000000000000000000000000000020"

sc0Vu added a commit that referenced this issue Jun 24, 2018
* Fix outputFormat function in dynamic bytes
* Add test test for issue 85 #85
@sc0Vu sc0Vu closed this as completed in #87 Jun 24, 2018
@shendenkov
Copy link

@sc0Vu
I see that you fixed src/Contracts/Ethabi.php at line 283. And now when I get bytes from smart contract I receive "0x0" against "0x20". And it looks good.
I tried to check this by set bytes to smart contract but I received error in src/Contracts/Ethabi.php at line 167. It seams that this is old code. Can you check please?

@sc0Vu
Copy link
Member

sc0Vu commented Feb 10, 2019

Hi @shendenkov
Did you get the same error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants