-
Notifications
You must be signed in to change notification settings - Fork 795
fix DepositTransaction::rlp()
to match op-geth
#2644
Conversation
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 feel like the entire optimism integration is a bit horrible...
hmm, I wonder why these fields are even options.
but if all of them are set, then this change doesn't have an effect right, because rlp_opt simply calls append, right?
and it looks like the decode function is current because it expects all the fields
so I guess the real question is, should this not even accept options
@mattsse good question, I don't think
the result i'm getting (before the change) is: compared to the go result of: this seems strange, because you're right, it should just be encoding the value inside the option. i'll investigate more |
update, the problems were
I left |
I see, I think another problem is Data, which looks like a non optional []byte which is always encoded? and iirc an empty []byte is encoded as an rlp header, but maybe that's what |
yep i also changed |
yeah, they are required:
agree |
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 looks correct, since all required fields are now encoded.
I think we should consider making them non optional.
pending @DaniPopes
rlp_opt(&mut rlp, &self.source_hash); | ||
rlp.append(&self.tx.from); | ||
rlp.append(&self.source_hash.unwrap_or_default()); | ||
rlp.append(&self.tx.from.unwrap_or_default()); |
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.
ah yes, we need to unwrap the from field because deposit txs don't have a signature...
rlp.append(&self.tx.value.unwrap_or_default()); | ||
rlp.append(&self.tx.gas.unwrap_or_default().as_u64()); | ||
rlp.append(&self.is_system_tx.unwrap_or_default()); | ||
rlp.append(&self.tx.data.as_deref().unwrap_or_default()); |
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 believe rlp_opt was correct here because it falls back to rlp.append("")
which is equivalent to rlp.append(&[])
but this is better
rlp.append(&self.tx.value.unwrap_or_default()); | ||
rlp.append(&self.tx.gas.unwrap_or_default().as_u64()); |
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.
same here, rlp_opt would fallback to an empty string and 0
is also encoded as empty string code I believe.
but this is better.
@mattsse i went ahead and updated |
I think that's the right decision |
@mattsse what's a good move for fixing the |
@noot sorry, for late reply, we can remove this test entirely, no longer needed since we're transitioning away from these types for alloy migration anyway |
@mattsse np, test removed! |
fyi @merklefruit |
Motivation
The RLP encoding for Optimism
DepositTransaction
s did not match the op-geth implementation. Deposit transactions created and encoded by ethers-rs were previously not being accepted by op-geth due to this.Solution
Fix
DepositTransaction::rlp()
to match op-gethDepositTx::encode()
. The types are now encoded to match op-geth: https://github.com/ethereum-optimism/op-geth/blob/optimism/core/types/deposit_tx.go#L29I generated the expected Go output as follows (place this in op-geth
core/types/deposit_tx_test.go
):Note: the existing test
test_rlp_encode_deposited_tx
is probably not exactly correct? Should I remove/update it?PR Checklist