web3p / ethereum-tx

Ethereum transaction library in PHP.
https://www.web3p.xyz/ethereumtx.html
MIT License
183 stars 63 forks source link

"Invalid RLP" error when sending signed transaction #37

Closed tonystatic closed 2 years ago

tonystatic commented 3 years ago

I'm using Infura for Kovan network and trying to call "transfer" method of an ERC20 contract. When I send it I get an Invalid RLP error.

My code:

$signedTransaction = '0x' . (new Transaction([
     "from" => "0x808AEf27804767A1548b132AA6e883B962A11f5e"
     "to" => "0x7d2121dc3b7637af36940bcce0cc95619f972eaa"
     "gas" => "0x00cb9d"
     "gasPrice" => "0x3b9aca00"
     "data" => "0xa9059cbb0000000000000000000000008741f8ce9fb1aad347d08980f44e549cbc1e6d270000000000000000000000000000000000000000000000000000000000989680"
     "nonce" => "0x00"
  ]))->sign($privateKey);

Can it be caused by this package or something in my transaction data is wrong? Thanks in advance!

sc0Vu commented 3 years ago

Hi @tonystatic ,

It seems there's issue in rlp, I'll look into this after update eip1559.

olegabr commented 3 years ago

@sc0Vu note, that this PR really helps with it: https://github.com/web3p/rlp/pull/24

tonystatic commented 3 years ago

@sc0Vu, @olegabr thanks for your replies!

Can I do anything for now to try to avoid this problem?

UPD1: I tried to apply fixes from olegabr/rlp fork myself (on 83 line of RLP.php and on 53 line of Str.php) but it didn't fix the "Invalid RLP" error.

UPD2: I tried signing transaction with these exact params via web3 JS library and it produces valid transaction.

sc0Vu commented 3 years ago

Hi @tonystatic, I think the issue might be wrong comparing in first byte, and it was fixed: https://github.com/web3p/rlp/commit/1653af23142863b490bdf22c6d0335bdb588c983

Would you like to test with the newest ethereum-tx or rlp library?

tonystatic commented 3 years ago

@sc0Vu, I tried it with the new version — and unfortunately it's still the same error. 😔 So I guess something else is a problem...

sc0Vu commented 3 years ago

@tonystatic lol, I saw the nonce was set to 0x0: "nonce" => "0x00", would you like to use 0x1?

diadal commented 3 years ago

similar issue after sigining

 $sign = new Transaction([
                'nonce' => $nonce,
                'from' => '0x4544d03F07136dc3D41E7ee9AdA3a062853b4Ab6',
                'to' => $to,
                'gas' => '0x76c0',
                'gasPrice' => $gasPrice,
                'value' => $value,
                'data' => ''
            ]);
            $raw = '0x' . $sign->sign($privateKey);

{ "jsonrpc": "2.0", "id": 1, "error": { "code": -32000, "message": "invalid sender" } }

dimonikus commented 2 years ago

$transaction = new Transaction([ 'nonce' => '0x1', 'from' => '0x56FE0F2335777d219aA67A4e66Bf48e2c4052553', 'to' => '0xc56eea61da347f9df11a3fc1cb9afce1f4dee126', 'gasPrice' => '0x178411b200', 'gas' => '0x5208', 'value' => '0x15a3d2bbca9800', 'chainId' => 1, ]);

i have "error":{"code":-32000,"message":"insufficient funds for gas * price + value"}

my balance in wei = 8212100000000000 gas = 21000 gasPrice = 101000000000 value = 6091100000000000

gas price + value = 21000 101000000000 + 6091100000000000 = 8212100000000000

sc0Vu commented 2 years ago

I think @tonystatic issue was encoding the appending '00' bytes incorrectly. The encoded string was different with the other library.

About @dimonikus issue, I didn't see any difference between php/js library. Which transaction version did you use?

sc0Vu commented 2 years ago

Already push some fix in rlp repo, that would be great if you can review it.