-
Notifications
You must be signed in to change notification settings - Fork 156
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
fix(rpc): update eth_tx_from_signed_eth_message to support legacy transactions #4523
Conversation
src/rpc/methods/eth.rs
Outdated
fn test_rlp_encoding_legacy() { | ||
let tx = EthTx { | ||
r#type: EIP_LEGACY_TX_TYPE.into(), | ||
chain_id: 314159.into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this test case coming from? Can we add a link to the filscan/filfox transaction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/rpc/methods/eth.rs
Outdated
Ok((r.into(), s.into(), v.into())) | ||
} | ||
|
||
fn recover_legacy_homestead_sig(sig: &Signature) -> Result<(EthBigInt, EthBigInt, EthBigInt)> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Let's avoid having hard logic in the
rpc
module. This should be used for schema cosmetics and re-using existing elements. I know it's not the case for now, but avoiding adding debt here will be helpful for a future refactor. - This looks pretty similar to
forest/src/eth/eip_155_transaction.rs
Line 43 in 07b0a87
pub(crate) fn with_signature(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/rpc/methods/eth/eth_tx.rs
Outdated
Ok(Hash(keccak(self.rlp_signed_message()?))) | ||
} | ||
|
||
pub fn rlp_signed_message(&self) -> Result<Vec<u8>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those seems like nitty-gritty details of Ethereum transactions. Should this live in the eth
module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/eth/eip_1559_transaction.rs
Outdated
stream.append(&format_bigint(&self.s)?); | ||
|
||
let mut rlp = stream.out().to_vec(); | ||
rlp.insert(0, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's comment what is this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/eth/eip_1559_transaction.rs
Outdated
@@ -61,6 +61,42 @@ impl EthEip1559TxArgs { | |||
|
|||
Ok(self) | |||
} | |||
|
|||
pub fn rlp_signed_message(&self) -> anyhow::Result<Vec<u8>> { | |||
let mut stream = rlp::RlpStream::new_list(12); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a less scary API that doesn't require changing this number on a new field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to the unbounded API
src/rpc/methods/eth/eth_tx.rs
Outdated
/// Ethereum Improvement Proposals 1559 transaction type. This EIP changed Ethereum’s fee market mechanism. | ||
/// Transaction type can have 3 distinct values: | ||
/// - 0 for legacy transactions | ||
/// - 1 for transactions introduced in EIP-2930 | ||
/// - 2 for transactions introduced in EIP-1559 | ||
pub const EIP_LEGACY_TX_TYPE: u64 = 0; | ||
pub const EIP_1559_TX_TYPE: u64 = 2; | ||
|
||
pub const ETH_LEGACY_HOMESTEAD_TX_CHAIN_ID: u64 = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have these constants in the eth
module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
self.r = r; | ||
self.s = s; | ||
self.v = v; | ||
|
||
Ok(self) | ||
} | ||
|
||
pub fn rlp_signed_message(&self) -> anyhow::Result<Vec<u8>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have some tests for this (and other transaction types)? Can be in a different PR. The magic number makes it scary, so I'd like to ensure this doesn't brake if someone adds a new field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been covered by fn test_eth_hash_*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd find it safer to have lower-level tests here, even if it means some duplication, but it's not a huge deal.
4b75183
to
36c03a0
Compare
|
||
self.r = r; | ||
self.s = s; | ||
self.v = v; | ||
|
||
Ok(self) | ||
} | ||
|
||
pub fn rlp_signed_message(&self) -> anyhow::Result<Vec<u8>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd find it safer to have lower-level tests here, even if it means some duplication, but it's not a huge deal.
Summary of changes
Changes introduced in this pull request:
eth_tx_from_signed_eth_message
to support legacy transaction types namelyLEGACY_HOMESTEAD_TX
andLEGACY_155_TX
Manually verified the below payload that was failing before
Reference issue to close (if applicable)
Closes #4519 #4518 #4477
Other information and links
Change checklist