Skip to content

Conversation

saibatizoku
Copy link
Contributor

@saibatizoku saibatizoku commented Mar 31, 2022

Replacing codec from chain-libs with RLP encoding from Ethereum for EVM Transactions

@saibatizoku saibatizoku self-assigned this Mar 31, 2022
@saibatizoku saibatizoku force-pushed the rlp-evm-transactions branch from 25c58f6 to 1314541 Compare April 4, 2022 18:48
saibatizoku added a commit that referenced this pull request Apr 4, 2022
updates dependencies to ethereum/ethereum-types needed for #786
@saibatizoku saibatizoku mentioned this pull request Apr 4, 2022
@saibatizoku saibatizoku force-pushed the rlp-evm-transactions branch from 1314541 to ee4f519 Compare April 4, 2022 19:11
@saibatizoku saibatizoku requested a review from Mr-Leshiy April 5, 2022 01:38
@saibatizoku
Copy link
Contributor Author

I'm getting two test failures that are blocking me:

fragment_serialization_bijection
block_serialization_bijection

@saibatizoku saibatizoku force-pushed the rlp-evm-transactions branch from 60a2428 to f9a3035 Compare April 5, 2022 18:57
Copy link
Contributor

@ecioppettini ecioppettini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe u64 is more than needed here (I don't have a clue what rlp is), but this seems to fix the test failure.

@saibatizoku saibatizoku marked this pull request as ready for review April 6, 2022 02:49
saibatizoku added a commit that referenced this pull request Apr 7, 2022
* update evm to v0.35

updates dependencies to ethereum/ethereum-types needed for #786
@saibatizoku saibatizoku force-pushed the rlp-evm-transactions branch from 9a4541f to 7de69cd Compare April 7, 2022 00:10
@Mr-Leshiy
Copy link
Contributor

@saibatizoku , mostly looks good, but we need to ensure that this new serde implementation for the EvmTransaction converges to the original Ethereum implementation that is the original goal of implementing Rlp encoding.
So need to add additional test with the hardcoded EvmTransaction hex encoded data.
https://www.trustology.io/insights-events/decoding-an-ethereum-transaction-its-no-secret-its-just-smart

#[cfg(feature = "evm")]
let ledger = ledger.set_evm_block0().set_evm_environment();
ledger
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not the previous implementation ?
It looked prettier IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy complained, so I removed the lint. I think it's not that bad looking, and explicitly handles the not( feature, which can't hurt.

@saibatizoku
Copy link
Contributor Author

@saibatizoku , mostly looks good, but we need to ensure that this new serde implementation for the EvmTransaction converges to the original Ethereum implementation that is the original goal of implementing Rlp encoding. So need to add additional test with the hardcoded EvmTransaction hex encoded data. https://www.trustology.io/insights-events/decoding-an-ethereum-transaction-its-no-secret-its-just-smart

I agree, there are also some possible test values in the ethereum crate that we might use. I'll take a look, in any case, adding tests will have to be a new PR, this one has grown too long already.

@saibatizoku saibatizoku force-pushed the rlp-evm-transactions branch from d873b27 to 18fd090 Compare April 7, 2022 17:22
@saibatizoku saibatizoku force-pushed the rlp-evm-transactions branch from 18fd090 to 1de70ac Compare April 13, 2022 13:18
@Mr-Leshiy Mr-Leshiy self-requested a review April 15, 2022 09:19
}
}

impl Decodable for EthereumTransaction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in case that we do not want to propagate all these Ethereum traits as Decodable and Encodable, I would prefer to add just a from_bytes(&[u8]) -> Self and to_bytes(self) -> &[u8] methods for the EthereumTransaction it seems to be more convenient for the further usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add these functions, although the Serialize/Deserialize traits end up providing the same, and make use of the Ethereum traits under the hood, so I think that it's equivalent.

}
}

impl Serialize for EthereumTransaction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I am not sure that these trait implementation as Serialize, Deserialize will also be needed for us, maybe we can just remove it at this point ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we need these traits for Fragment-related ser/de, but I'm not sure.


/// Wrapper type for `ethereum::TransactionV2`, which includes the `EIP1559Transaction`, `EIP2930Transaction`, `LegacyTransaction` variants.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct EthereumTransaction(TransactionV2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we should also add implementation of the TryFrom/TryInto for the conversion into the EvmTransaction type

@saibatizoku saibatizoku force-pushed the rlp-evm-transactions branch 4 times, most recently from 9bea94c to cafc247 Compare April 26, 2022 14:45
saibatizoku and others added 19 commits May 2, 2022 10:26
remove DeserializeFromSlice, as we get a blanket impl now
Co-authored-by: Enzo Cioppettini <48031343+enzoc4@users.noreply.github.com>
Co-authored-by: Enzo Cioppettini <48031343+enzoc4@users.noreply.github.com>
Co-authored-by: Enzo Cioppettini <48031343+enzoc4@users.noreply.github.com>
Co-authored-by: Alex Pozhylenkov <leshiy12345678@gmail.com>
implements RLP encoding/decoding
implements Serialize/Deserialize from chain_core
brings in secp256k1 crate dependency
also adds tests for the Secret type, which holds a SecretKey and offers helpful conversions
@saibatizoku saibatizoku force-pushed the rlp-evm-transactions branch from cafc247 to f3bd658 Compare May 2, 2022 15:37
use EvmTransaction::*;
impl EvmTransaction {
/// Serialize the contract into a `ByteBuilder`.
pub fn serialize_in(&self, _bb: ByteBuilder<Self>) -> ByteBuilder<Self> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to implement Serialize trait, it will allow to use serialization_bijection function in tests and it will follow to the full serde interface. (as Deserialize trait has been implemented)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restored the Serialize trait, and kept the RLP encoding because it handles things like U256 values and list of items better than we were doing it. If anything, I would move the EvmTransaction type into chain-evm to clean up dependencies a bit, but that would be in a future PR.

nicopado and others added 4 commits May 10, 2022 22:28
* added ledger status validation after transaction scenario

* removed useless validation

* added scenario for invalid transaction

* added scenarios for correct fees when casting & tallying votes

* partial PR correction

* PR corrections

* deleted comment

* PR corrections
@saibatizoku saibatizoku force-pushed the rlp-evm-transactions branch from 9f2cad9 to cf41a3b Compare May 11, 2022 03:33
@saibatizoku saibatizoku merged commit 7b0a443 into master May 11, 2022
@saibatizoku saibatizoku deleted the rlp-evm-transactions branch May 11, 2022 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants