-
Notifications
You must be signed in to change notification settings - Fork 13
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
When use eth_rlp_uint(), the result of rlp serialization is inconsistent with the result of rlp encode in the go-etherum library. #45
Comments
I did some incremental replacement testing. char *gasprice = "0x4A817C800";
uint64_t gasprice_uint = 20000000000; When i use gasprice variable with eth_rlp_hex(&rlp0, &gasprice, NULL), i still got the correct result: If i use gasprice_uint variable with eth_rlp_uint(&rlp0, &gasprice_uint), will get: Other fields have no effect. The code example is as follows: ok(eth_rlp_array(&rlp0)); // [
ok(eth_rlp_hex(&rlp0, &nonce, NULL)); // 0x00,
// ok(eth_rlp_hex(&rlp0, &gasprice, NULL)); // 0x04a817c800,
ok(eth_rlp_uint(&rlp0, &gasprice_uint));
// ok(eth_rlp_hex(&rlp0, &gaslimit, NULL)); // 0x5208,
ok(eth_rlp_uint(&rlp0, &gaslimit_uint));
ok(eth_rlp_address(&rlp0, &toaddr)); // 0x3535353535353535353535353535353535353535,
// ok(eth_rlp_hex(&rlp0, &value, NULL)); // 0x0de0b6b3a7640000,
ok(eth_rlp_uint(&rlp0, &value_uint64)); // 0x,
ok(eth_rlp_bytes(&rlp0, &data_ptr, &data_len)); // 0x,
// ok(eth_rlp_hex(&rlp0, &data, NULL)); // 0x7a69,
// ok(eth_rlp_hex(&rlp0, &chainid, NULL)); // 0x7a69,
ok(eth_rlp_uint(&rlp0, &chainid_uint)); // 0x,
ok(eth_rlp_uint8(&rlp0, &zero_uint)); // 0x,
ok(eth_rlp_uint8(&rlp0, &zero_uint)); // 0x,
ok(eth_rlp_array_end(&rlp0)); // ] |
Hi @qingfengzxr if (*d <= 0xff) {
return eth_rlp_uint8(rlp, (uint8_t*)d);
} else if (*d <= 0xffff) {
return eth_rlp_uint16(rlp, (uint16_t*)d);
} else if (*d <= 0xffffffff) {
return eth_rlp_uint32(rlp, (uint32_t*)d);
} else if (*d <= 0xffffffffffffffff) { // satisfies this if check
return eth_rlp_uint64(rlp, d); // and this function is being called
} If we go further and look at the code of |
I think the way the function works right now is not correct. If we pass 5 byte integer into Not closing the issue, and marking it as bug. Thank you so much! |
I understand, thank you for your answer, I will keep the issue open. Thank you very much! @mhw0 |
yeah I also encountered this problem before when I tried to encode ETH Sepolia ChainID |
I am trying to pin point the bug source and test case, in offical go eth implatmenetation's rlp test case we have following testing case : https://github.com/ethereum/go-ethereum/blob/f861535f1ecc59ad279c35f77f3962efc14dcf98/rlp/decode_test.go#L482 Would it a simple fix by adding implementation for adding |
Hi @roycncn that's actually a good idea but I don't have enough time right now to add that feature. Contributions are welcome! |
Hello, brothers. I meet some confusing things. To put it simply, when I use eth_rlp_hex() to serialize my transaction data, I can get the correct serialization result. But when I use methods such as eth_rlp_uint() or eth_rlp_uint64() to serialize the same data, the final result is different.
This is the C code I used to test:
when i call rlp_encode_test_1(), i got the rlp encode result is:
f38203e88800000004a817c800825204943535353535353535353535353535353535353535880de0b6b3a764000001827a698080
and call rlp_encode_test_2() will get:
f08203e88504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000001827a698080
I can confirm that the result obtained by rlp_encode_test_2() is correct. Because I serialized the same transaction using both go code and python code, I got the same result as rlp_encode_test_2().
Go test code:
Python test code:
will both get the rlp encode result is:
f08203e88504a817c800825204943535353535353535353535353535353535353535880de0b6b3a764000001827a698080
So I am confused about this phenomenon. Why do I get different results when serializing using the eth_rlp_uint() function?
Do you understand the reason for this problem? @zzzzzzch @mhw0
The text was updated successfully, but these errors were encountered: