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

Transaction(EIP1559Transaction) hash doesn't match the real one from server #41

Closed
sajadkhosravani1 opened this issue Sep 13, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@sajadkhosravani1
Copy link

Hello and thanks for developing this library.
I noticed that an EIP1559Transaction unlike legacy Transaction objects has the same hash before and after signing the transaction.
For legacy transactions I recreate the transaction object by parsing the signed raw transaction using the "Transaction(string $raw)" constructor and then I call hash() function so I get the final hash of the transaction.
But for EIP1559Transaction there's no way to get final transaction hash. In this case calling signed and unsigned transactions hash() function have the same response and it's of course not the same as what server computes and returns as response of "eth_sendRawTransaction".
With best regards.

@sajadkhosravani1
Copy link
Author

Code appended to previous comment:

require "lib.php";
use Web3p\EthereumTx\Transaction;
use Web3p\EthereumTx\EIP1559Transaction;
$res = rpcInvoke("eth_getTransactionCount",["0x1c82bf96916743bce021d60d24095c2b1a888687", 'pending']);
// unset($res['transactions']);
$transaction = new Transaction([
    'nonce' => $res ,
    'from' => '0x1c82bf96916743bce021d60d24095c2b1a888687',
    'to' => '0xcDA0D6adCD0f1CCeA6795F9b1F23a27ae643FE7C',
    'gas' => '0x5208',
    'gasPrice' => '0x' . dechex(70 * 10**9),
    'chainId'   => 3,
    'value' => '0x' . dechex(0.01 * 10**18),
    'data' => ''
]);

$transaction = new EIP1559Transaction([
    'nonce' => $res,
    'from' => '0x1c82bf96916743bce021d60d24095c2b1a888687',
    'to' => '0xcDA0D6adCD0f1CCeA6795F9b1F23a27ae643FE7C',
    'maxPriorityFeePerGas' => '0x' . dechex(70 * 10**9),
    'maxFeePerGas' => '0x' . dechex(100 * 10**9),
    'gas' => '0x5208',
    'value' =>  '0x' . dechex(0.01 * 10**18),
    'chainId' => 3,
    'accessList' => [],
    'data' => ''
]);
echo "before sign: ";
echo '0x' . $transaction->hash() . PHP_EOL;
$signed = $transaction->sign("0x1a56ee986126833163dbc7335b74ec8d1b03c1f9f2ff4acb5d438a012a967d76");
$transaction = new EIP1559Transaction("0x$signed");
echo "after sign: ";
echo '0x' . $transaction->hash() . PHP_EOL;
$res = rpcInvoke("eth_sendRawTransaction",["0x$signed"]);
echo "Server response result: " ;
var_dump($res);  

Result:

before sign: 0x27a16bc2e5ed47d9fc4840cced8f83407d835bb9127681b7a5ecc994fdeb52fb
after sign: 0x27a16bc2e5ed47d9fc4840cced8f83407d835bb9127681b7a5ecc994fdeb52fb
Server response result: string(66) "0xdba32a4a8df5cd515151145bf0103a102a770fac9f45959057ce096911fb222e"

@sc0Vu
Copy link
Member

sc0Vu commented Nov 23, 2021

@sajadkhosravani1 Thanks, you're right! I didn't hash the signature together.

I've push fix in PR.

@sc0Vu sc0Vu added the bug Something isn't working label Nov 23, 2021
@sc0Vu sc0Vu closed this as completed in 83d9305 Dec 28, 2021
sc0Vu added a commit that referenced this issue Dec 28, 2021
Fix #41: hash() didn't return transaction hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants