Combined encoding of address[] and uint8[] and other types is giving corrupted(incorrect result) result
the function calling is
getPoolInfoBatchAsString(address[],uint8[])
the encoded data are
pool addresses: 0xe6b4903642b4a1637d7b411d009af5c91617860c,0x12d59b7849989f677a2d67fcf21b3d2e28291da6,0x2c7fe80e727408751b086d5e2f257ab20cd97f69,0x68f940fb79e216faafbc96a6701b11b44f5255c2,0x8da0d9418e74c8523cc189be07589a788a1c49e7,0xe3b3aa98faa70bf098ea5e75e11193de95ab7cda,0x9950c1f3754fb8a3ebbaf24b8573cafc7474c00f,0xafecdd2fc04f0939d7b6835529677608470c063d,0xc4081a370585681e265ec9efb84143549469e77e
pool versions: 1,0,0,1,0,0,1,1,0
the correct call data is
000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000009000000000000000000000000e6b4903642b4a1637d7b411d009af5c91617860c00000000000000000000000012d59b7849989f677a2d67fcf21b3d2e28291da60000000000000000000000002c7fe80e727408751b086d5e2f257ab20cd97f6900000000000000000000000068f940fb79e216faafbc96a6701b11b44f5255c20000000000000000000000008da0d9418e74c8523cc189be07589a788a1c49e7000000000000000000000000e3b3aa98faa70bf098ea5e75e11193de95ab7cda0000000000000000000000009950c1f3754fb8a3ebbaf24b8573cafc7474c00f000000000000000000000000afecdd2fc04f0939d7b6835529677608470c063d000000000000000000000000c4081a370585681e265ec9efb84143549469e77e0000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000
libethc generating is
000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000009000000000000000000000000e6b4903642b4a1637d7b411d009af5c91617860c00000000000000000000000012d59b7849989f677a2d67fcf21b3d2e28291da60000000000000000000000002c7fe80e727408751b086d5e2f257ab20cd97f6900000000000000000000000068f940fb79e216faafbc96a6701b11b44f5255c20000000000000000000000008da0d9418e74c8523cc189be07589a788a1c49e7000000000000000000000000e3b3aa98faa70bf098ea5e75e11193de95ab7cda0000000000000000000000009950c1f3754fb8a3ebbaf24b8573cafc7474c00f000000000000000000000000afecdd2fc04f0939d7b6835529677608470c063d000000000000000000000000c4081a370585681e265ec9efb84143549469e77e0000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000
the code
struct eth_abi abi = {};
char *fn = strdup(function.c_str());
size_t hexlen;
eth_abi_init(&abi, ETH_ABI_ENCODE);
eth_abi_call(&abi, &fn, NULL);
eth_abi_array(&abi, NULL); // array beign
eth_abi_address(&abi, "0xe6b4903642b4a1637d7b411d009af5c91617860c");
eth_abi_address(&abi, "0x12d59b7849989f677a2d67fcf21b3d2e28291da6");
eth_abi_address(&abi, "0x2c7fe80e727408751b086d5e2f257ab20cd97f69");
eth_abi_address(&abi, "0x68f940fb79e216faafbc96a6701b11b44f5255c2");
eth_abi_address(&abi, "0x8da0d9418e74c8523cc189be07589a788a1c49e7");
eth_abi_address(&abi, "0xe3b3aa98faa70bf098ea5e75e11193de95ab7cda");
eth_abi_address(&abi, "0x9950c1f3754fb8a3ebbaf24b8573cafc7474c00f");
eth_abi_address(&abi, "0xafecdd2fc04f0939d7b6835529677608470c063d");
eth_abi_address(&abi, "0xc4081a370585681e265ec9efb84143549469e77e");
eth_abi_array_end(&abi); // array end
eth_abi_array(&abi, NULL); // array beign
eth_abi_uint8(&abi, 1);
eth_abi_uint8(&abi, 0);
eth_abi_uint8(&abi, 0);
eth_abi_uint8(&abi, 1);
eth_abi_uint8(&abi, 0);
eth_abi_uint8(&abi, 0);
eth_abi_uint8(&abi, 1);
eth_abi_uint8(&abi, 1);
eth_abi_uint8(&abi, 0);
eth_abi_array_end(&abi); // array end
eth_abi_call_end(&abi);
eth_abi_to_hex(&abi, &hex, &hexlen)
string data(hex);
if you can please check your change by doing regression test to check the new change doesn't affect other functionalities. I know you are very busy and and took you the whole week to response. I check my email every single day, all day for your response and i don't say anything to not nag you. 🙏
not only address[] and uint8[] combination, it is for all combination. here is an example for getPoolInfoBatchAsString(address[],uint8[],address[],address,uint256,uint256)
Real
790b6b3c00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000068f940fb79e216faafbc96a6701b11b44f5255c2000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000150000000000000000000000000000000000000000000000000000000000000003000000000000000000000000e6b4903642b4a1637d7b411d009af5c91617860c00000000000000000000000012d59b7849989f677a2d67fcf21b3d2e28291da60000000000000000000000002c7fe80e727408751b086d5e2f257ab20cd97f6900000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000e6b4903642b4a1637d7b411d009af5c91617860c00000000000000000000000012d59b7849989f677a2d67fcf21b3d2e28291da60000000000000000000000002c7fe80e727408751b086d5e2f257ab20cd97f69
libethc result
790b6b3c00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000068f940fb79e216faafbc96a6701b11b44f5255c2000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000150000000000000000000000000000000000000000000000000000000000000003000000000000000000000000e6b4903642b4a1637d7b411d009af5c91617860c00000000000000000000000012d59b7849989f677a2d67fcf21b3d2e28291da60000000000000000000000002c7fe80e727408751b086d5e2f257ab20cd97f6900000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000e6b4903642b4a1637d7b411d009af5c91617860c00000000000000000000000012d59b7849989f677a2d67fcf21b3d2e28291da60000000000000000000000002c7fe80e727408751b086d5e2f257ab20cd97f69
Hi @DerXanRam thanks for opening the issue. I'm on vacation right now, that's why it's taking a bit longer to respond & react to the problems. Trying my best to cover all the issues. Thanks for understanding.
Ok tnx bro👍
Hi @DerXanRam thanks for opening the issue. I'm on vacation right now, that's why it's taking a bit longer to respond & react to the problems. Trying my best to cover all the issues. Thanks for understanding.
Any progress bro?
Hi @DerXanRam Fixed the issue. Refactoring right now. Pushing the patch soon.
Hello @DerXanRam Pushed the changes. Can you please check if the issue is fixed?
Added your case in this test: https://github.com/mhw0/libethc/blob/8110d2ae35cd8bac13a1c74c7e625dfa42d80fdb/test/test-eth-abi.c#L626-L648
Also made some changes to the API. eth_abi_address used to assign allocated memory to the input as output. Now, you have to pass preallocated memory into it. I think this makes more sense as the size of address is always fixed.
Hello @DerXanRam Pushed the changes. Can you please check if the issue is fixed?
Added your case in this test:
Lines 626 to 648 in 8110d2a
assert(eth_abi_array(&abi0, NULL) == ETH_OK); eth_abi_address(&abi0, addr0); eth_abi_address(&abi0, addr1); eth_abi_address(&abi0, addr2); eth_abi_address(&abi0, addr3); eth_abi_address(&abi0, addr4); eth_abi_address(&abi0, addr5); eth_abi_address(&abi0, addr6); eth_abi_address(&abi0, addr7); eth_abi_address(&abi0, addr8); assert(eth_abi_array_end(&abi0) == ETH_OK);
assert(eth_abi_array(&abi0, NULL) == ETH_OK); eth_abi_uint8(&abi0, &int0); eth_abi_uint8(&abi0, &int1); eth_abi_uint8(&abi0, &int2); eth_abi_uint8(&abi0, &int3); eth_abi_uint8(&abi0, &int4); eth_abi_uint8(&abi0, &int5); eth_abi_uint8(&abi0, &int6); eth_abi_uint8(&abi0, &int7); eth_abi_uint8(&abi0, &int8); assert(eth_abi_array_end(&abi0) == ETH_OK); Also made some changes to the API.
eth_abi_addressused to assign allocated memory to the input as output. Now, you have to pass preallocated memory into it. I think this makes more sense as the size of address is always fixed.
sorry for late response...testing
Sorry for late, accident happened.
when uint8 comes first, still it encodes incorrectly.
Hi @DerXanRam can you give example so I can reproduce the issue?
truct eth_abi abi = {};
std::string function = "getPoolInfoBatchAsString(uint8[],address[])";
char *fn = strdup(function.c_str());
size_t hexlen;
eth_abi_init(&abi, ETH_ABI_ENCODE);
eth_abi_call(&abi, &fn, NULL);
char *add1 = "0xe6b4903642b4a1637d7b411d009af5c91617860c";
char *add2 = "0x12d59b7849989f677a2d67fcf21b3d2e28291da6";
char *add3 = "0x2c7fe80e727408751b086d5e2f257ab20cd97f69";
uint8_t n1 = 1;
uint8_t n2 = 0;
uint8_t n3 = 0;
eth_abi_array(&abi, NULL); // array beign
eth_abi_uint8(&abi, &n1);
eth_abi_uint8(&abi, &n2);
eth_abi_uint8(&abi, &n3);
eth_abi_array_end(&abi); // array end
eth_abi_array(&abi, NULL); // array beign
eth_abi_address(&abi, &add1);
eth_abi_address(&abi, &add2);
eth_abi_address(&abi, &add3);
eth_abi_array_end(&abi); // array end
eth_abi_call_end(&abi);
char *hex;
eth_abi_to_hex(&abi, &hex, &hexlen);
std::string data(hex);
std::cout<<"encoded "<<data<<std::endl;
expected result
2b4276ed000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000e6b4903642b4a1637d7b411d009af5c91617860c00000000000000000000000012d59b7849989f677a2d67fcf21b3d2e28291da60000000000000000000000002c7fe80e727408751b086d5e2f257ab20cd97f69
libethc result
2b4276ed000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000e6b4903642b4a1637d7b411d009af5c91617860c00000000000000000000000012d59b7849989f677a2d67fcf21b3d2e28291da60000000000000000000000002c7fe80e727408751b086d5e2f257ab20cd97f69
hello
Hi buddy. Very very sorry for the big delay. Have to finish some things. I’ll be back starting next month
Hi @DerXanRam I tested your code and getting the expected result. Could you confirm that you got that result from libethc?