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

pallet_ethereum transact extrinsic triggers runtime panic #1188

Open
bernardoaraujor opened this issue Sep 7, 2023 · 3 comments
Open

pallet_ethereum transact extrinsic triggers runtime panic #1188

bernardoaraujor opened this issue Sep 7, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@bernardoaraujor
Copy link
Contributor

Description

I am trying to submit a transaction via pallet-ethereum's transact extrinsic.

I encounter errors on PolkadotJS UI as well as on the node's logs.

Steps to Reproduce

  1. Build frontier template from master branch
  2. Start the template node via ./target/release/frontier-template-node --dev
  3. Craft a transact with the following parameters (known to work via ethersjs):
nonce: 0
gasPrice: 875207000
gasLimit: 10000000
action: Create
value: 0
input: 0x60806040526005805460ff60a01b1916600160a01b1790553480156200002457600080fd5b506040516200108038038062001080833981016040819052620000479162000149565b8181600362000057838262000242565b50600462000066828262000242565b5050600580546001600160a01b03191633179055506200030e915050565b634e487b7160e01b600052604160045260246000fd5b600082601f830112620000ac57600080fd5b81516001600160401b0380821115620000c957620000c962000084565b604051601f8301601f19908116603f01168101908282118183101715620000f457620000f462000084565b816040528381526020925086838588010111156200011157600080fd5b600091505b8382101562000135578582018301518183018401529082019062000116565b600093810190920192909252949350505050565b600080604083850312156200015d57600080fd5b82516001600160401b03808211156200017557600080fd5b62000183868387016200009a565b935060208501519150808211156200019a57600080fd5b50620001a9858286016200009a565b9150509250929050565b600181811c90821680620001c857607f821691505b602082108103620001e957634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200023d57600081815260208120601f850160051c81016020861015620002185750805b601f850160051c820191505b81811015620002395782815560010162000224565b5050505b505050565b81516001600160401b038111156200025e576200025e62000084565b62000276816200026f8454620001b3565b84620001ef565b602080601f831160018114620002ae5760008415620002955750858301515b600019600386901b1c1916600185901b17855562000239565b600085815260208120601f198616915b82811015620002df57888601518255948401946001909101908401620002be565b5085821015620002fe5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b610d62806200031e6000396000f3fe608060405234801561001057600080fd5b506004361061012c5760003560e01c80638456cb59116100ad578063a6a97dc111610071578063a6a97dc11461027f578063a9059cbb14610292578063b721ef6e146102a5578063be9a6555146102c5578063dd62ed3e146102cd57600080fd5b80638456cb591461021e5780638da5cb5b1461022657806395d89b41146102515780639ea185ac14610259578063a457c2d71461026c57600080fd5b8063313ce567116100f4578063313ce567146101ac57806339509351146101bb578063449a52f8146101ce5780635c975abb146101e157806370a08231146101f557600080fd5b806306fdde0314610131578063095ea7b31461014f57806318160ddd146101725780631c78e7981461018457806323b872dd14610199575b600080fd5b6101396102e0565b6040516101469190610b15565b60405180910390f35b61016261015d366004610b7f565b610372565b6040519015158152602001610146565b6002545b604051908152602001610146565b610197610192366004610ba9565b61038c565b005b6101626101a7366004610bee565b6103f5565b60405160128152602001610146565b6101626101c9366004610b7f565b610419565b6101976101dc366004610b7f565b61043b565b60055461016290600160a01b900460ff1681565b610176610203366004610c0c565b6001600160a01b031660009081526020819052604090205490565b610197610473565b600554610239906001600160a01b031681565b6040516001600160a01b039091168152602001610146565b6101396104e2565b610197610267366004610ba9565b6104f1565b61016261027a366004610b7f565b610580565b61019761028d366004610ba9565b6105fb565b6101626102a0366004610b7f565b610678565b6101766102b3366004610c0c565b60066020526000908152604090205481565b610197610686565b6101766102db366004610c2e565b6106ef565b6060600380546102ef90610c61565b80601f016020809104026020016040519081016040528092919081815260200182805461031b90610c61565b80156103685780601f1061033d57610100808354040283529160200191610368565b820191906000526020600020905b81548152906001019060200180831161034b57829003601f168201915b5050505050905090565b60003361038081858561071a565b60019150505b92915050565b600554600160a01b900460ff16156103bf5760405162461bcd60e51b81526004016103b690610c9b565b60405180910390fd5b60005b8361ffff168161ffff1610156103ef576103dc8383610678565b50806103e781610cf8565b9150506103c2565b50505050565b60003361040385828561083e565b61040e8585856108b2565b506001949350505050565b60003361038081858561042c83836106ef565b6104369190610d19565b61071a565b600554600160a01b900460ff16156104655760405162461bcd60e51b81526004016103b690610c9b565b61046f8282610a56565b5050565b6005546001600160a01b031633146104cd5760405162461bcd60e51b815260206004820152601860248201527f4f6e6c79206f776e65722063616e2070617573652069742e000000000000000060448201526064016103b6565b6005805460ff60a01b1916600160a01b179055565b6060600480546102ef90610c61565b600554600160a01b900460ff161561051b5760405162461bcd60e51b81526004016103b690610c9b565b60005b8361ffff168161ffff1610156103ef576040518281526001600160a01b0384169033907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a38061057881610cf8565b91505061051e565b6000338161058e82866106ef565b9050838110156105ee5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084016103b6565b61040e828686840361071a565b600554600160a01b900460ff16156106255760405162461bcd60e51b81526004016103b690610c9b565b60005b8361ffff168161ffff1610156103ef576001600160a01b03831660009081526006602052604081208054849290610660908490610d19565b9091555081905061067081610cf8565b915050610628565b6000336103808185856108b2565b6005546001600160a01b031633146106e05760405162461bcd60e51b815260206004820152601860248201527f4f6e6c79206f776e65722063616e2073746172742069742e000000000000000060448201526064016103b6565b6005805460ff60a01b19169055565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b03831661077c5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016103b6565b6001600160a01b0382166107dd5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016103b6565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b600061084a84846106ef565b905060001981146103ef57818110156108a55760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016103b6565b6103ef848484840361071a565b6001600160a01b0383166109165760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016103b6565b6001600160a01b0382166109785760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016103b6565b6001600160a01b038316600090815260208190526040902054818110156109f05760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016103b6565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a36103ef565b6001600160a01b038216610aac5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016103b6565b8060026000828254610abe9190610d19565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b600060208083528351808285015260005b81811015610b4257858101830151858201604001528201610b26565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b0381168114610b7a57600080fd5b919050565b60008060408385031215610b9257600080fd5b610b9b83610b63565b946020939093013593505050565b600080600060608486031215610bbe57600080fd5b833561ffff81168114610bd057600080fd5b9250610bde60208501610b63565b9150604084013590509250925092565b600080600060608486031215610c0357600080fd5b610bd084610b63565b600060208284031215610c1e57600080fd5b610c2782610b63565b9392505050565b60008060408385031215610c4157600080fd5b610c4a83610b63565b9150610c5860208401610b63565b90509250929050565b600181811c90821680610c7557607f821691505b602082108103610c9557634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526027908201527f4f6e77657220686173206e6f7420737461727465642074686520636f6e74726160408201526631ba103cb2ba1760c91b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b600061ffff808316818103610d0f57610d0f610ce2565b6001019392505050565b8082018082111561038657610386610ce256fea26469706673582212206a8bd9ca5f54b24e6a3afbdb6b98ae50512396aeecdd993add1865cd65abbb9d64736f6c6343000812003300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000b53696d706c65546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000353544b0000000000000000000000000000000000000000000000000000000000
v: 0
r: 0x014bc504b39407ad1b8f131197a73eb51e6a17634b5efe4ebae03687f6cfa02b
s: 0x3133ee596d4d84e762ffcb4df4447379bcbb85be501abd0a41d064ecd218e761

image

  1. See error on PolkadotJS UI:
    image

  2. See error on node logs:

this shows as soon as I click Submit Transaction on the UI (before confirmation)... if I then click Sign and Submit, the error logs show up once again:

====================

Version: 0.0.0-0383d213062

   0: backtrace::capture::Backtrace::new
   1: sp_panic_handler::set::{{closure}}
   2: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/8b4b20836b832e91aa605a2faf5e2a55190202c8/library/alloc/src/boxed.rs:1999:9
      std::panicking::rust_panic_with_hook
             at /rustc/8b4b20836b832e91aa605a2faf5e2a55190202c8/library/std/src/panicking.rs:695:13
   3: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/8b4b20836b832e91aa605a2faf5e2a55190202c8/library/std/src/panicking.rs:582:13
   4: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/8b4b20836b832e91aa605a2faf5e2a55190202c8/library/std/src/sys_common/backtrace.rs:151:18
   5: rust_begin_unwind
             at /rustc/8b4b20836b832e91aa605a2faf5e2a55190202c8/library/std/src/panicking.rs:578:5
   6: core::panicking::panic_fmt
             at /rustc/8b4b20836b832e91aa605a2faf5e2a55190202c8/library/core/src/panicking.rs:67:14
   7: frontier_template_runtime::api::dispatch
   8: environmental::using
   9: sc_executor::executor::WasmExecutor<H>::with_instance::{{closure}}
  10: sc_executor::wasm_runtime::RuntimeCache::with_instance
  11: <sc_executor::executor::NativeElseWasmExecutor<D> as sp_core::traits::CodeExecutor>::call
  12: sp_state_machine::execution::StateMachine<B,H,Exec>::execute_aux
  13: sp_state_machine::execution::StateMachine<B,H,Exec>::execute_using_consensus_failure_handler
  14: <sc_service::client::call_executor::LocalCallExecutor<Block,B,E> as sc_client_api::call_executor::CallExecutor<Block>>::call
  15: <sc_rpc::state::state_full::FullState<BE,Block,Client> as sc_rpc::state::StateBackend<Block,Client>>::call
  16: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
  17: tokio::runtime::task::core::Core<T,S>::poll
  18: tokio::runtime::task::harness::Harness<T,S>::poll
  19: tokio::runtime::blocking::pool::Inner::run
  20: std::sys_common::backtrace::__rust_begin_short_backtrace
  21: core::ops::function::FnOnce::call_once{{vtable.shim}}
  22: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/8b4b20836b832e91aa605a2faf5e2a55190202c8/library/alloc/src/boxed.rs:1985:9
      <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/8b4b20836b832e91aa605a2faf5e2a55190202c8/library/alloc/src/boxed.rs:1985:9
      std::sys::unix::thread::Thread::new::thread_start
             at /rustc/8b4b20836b832e91aa605a2faf5e2a55190202c8/library/std/src/sys/unix/thread.rs:108:17
  23: __pthread_joiner_wake


Thread 'tokio-runtime-worker' panicked at 'Bad input data provided to query_info: Could not decode `UncheckedExtrinsic.0`:
Could not decode `RuntimeCall::Ethereum.0`:
Could not decode `Call::transact::transaction`:
Could not decode `TransactionV2::Legacy.0`:
Could not decode `LegacyTransaction::signature`:
Invalid signature
', template/runtime/src/lib.rs:564

This is a bug. Please report it at:

	support.anonymous.an

2023-09-07 17:29:07 Evicting failed runtime instance error=Runtime panicked: Bad input data provided to query_info: Could not decode `UncheckedExtrinsic.0`:
Could not decode `RuntimeCall::Ethereum.0`:
Could not decode `Call::transact::transaction`:
Could not decode `TransactionV2::Legacy.0`:
Could not decode `LegacyTransaction::signature`:
Invalid signature

Expected vs. Actual Behavior

I would expect a successful execution on the EVM. Or at least the EVM to reject the transaction for some specific reason (e.g.: invalid v,r,s).

@bernardoaraujor bernardoaraujor added the bug Something isn't working label Sep 7, 2023
@bernardoaraujor
Copy link
Contributor Author

to elaborate a bit more on the methodology to reproduce this issue, first I started the template via ./target/release/frontier-template-node --dev

then I sent a tx via ethersjs and observed its parameters via hardhat

then I re-started the template by killing the previous execution and running ./target/release/frontier-template-node --dev again

for some reason the v == 0 field is being considered invalid there, which is weird since it was taken from a tx that was successfully executed via ethersjs

we did some new tests taking a different tx coming from another EVM, for which v is a big value (403643), and then replaying this tx in a frontier parachain with the same chain_id of this origin EVM... the error does not happen under those circumstances

so we are no longer blocked by this, because our main goal is to simply replay txs from an origin EVM into this Frontier parachain

but it would be good to improve the implementation of the transact extrinsic so that it handles this edge case of invalid signatures gracefully without a runtime panic

@boundless-forest
Copy link
Collaborator

Some information to note: I dug a little deeper and found that the error message Invalid signature comes from https://github.com/rust-blockchain/ethereum/blob/master/src/transaction.rs#L166. Fortunately, the transaction causing the runtime panic is be validate false and is not be included in the block. No idea what to do next about this now.

@sorpaas
Copy link
Member

sorpaas commented Oct 11, 2023

This is expected. If we do not panic on invalid signatures, then the extrinsic will be included in a block but will not be paying any fees.

You should not use ethereum.transact on the Substrate RPC. That'll submit the extrinsic from a signed source, rather than the unsigned Ethereum source. It'll always fail even if you have the correct signature. Use the Ethereum RPC instead.

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

3 participants