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

feat: alloy migration #535

Merged
merged 1 commit into from
Aug 16, 2023
Merged

feat: alloy migration #535

merged 1 commit into from
Aug 16, 2023

Conversation

DaniPopes
Copy link
Collaborator

@DaniPopes DaniPopes commented Jun 30, 2023

Based on #499, so using that as PR base for better diff for now.
Will need an alloy-primitives v0.2.1 release for hex macros and other stuff.

Main changes:

  • bits types (B160, B256) are now coming from alloy_primitives, which are type aliases to FixedBytes<N>
    • using the tuple constructor (B*([...])) is not allowed, so we use ::new or ::from
    • B160 -> Address: Address is its own type, different from B160, with its own methods and trait impls
    • a lot of hex::decode moved to use of address!, b256!, bytes! macros
    • serde utils such as serde_hex_bytes and other util functions are not needed anymore, since the base serde impls of Bytes and FixedBytes use hex by default.
  • changed use of sha3::Keccak256 to alloy_primitives::keccak256, which uses tiny_keccak
  • replaced ruint with alloy_primitives::ruint (which is ruint2 for now which includes many unreleased changes, see: recmo/uint@v1.8.0...alloy-rs:uint:main)
  • removed usage of rlp in favor of alloy_rlp where possible (revme)
  • updated documentation accordingly

@DaniPopes DaniPopes force-pushed the alloy branch 2 times, most recently from 5686acc to b36e3e4 Compare July 26, 2023 15:13
@DaniPopes DaniPopes force-pushed the alloy branch 6 times, most recently from 8b3fd9a to 67414f3 Compare August 5, 2023 19:42
@DaniPopes DaniPopes changed the base branch from account_states to main August 8, 2023 23:14
@DaniPopes DaniPopes force-pushed the alloy branch 4 times, most recently from 6173cc0 to d577f07 Compare August 9, 2023 01:49
@DaniPopes DaniPopes marked this pull request as ready for review August 9, 2023 02:11
@DaniPopes DaniPopes force-pushed the alloy branch 2 times, most recently from 8341293 to 01d2fb6 Compare August 15, 2023 10:25
Copy link
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

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

two nits and one q, but otherwise this looks great!

Will pause other PR's until this is merged, so you don't have conflicts.

rlp = { version = "0.5", default-features = false }
ruint = { version = "1.8.0", features = ["rlp", "serde"] }
alloy-rlp = { version = "0.3", default-features = false, features = ["arrayvec"] }
ruint = { version = "1.9.0", features = ["rlp", "serde"] }
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to reexport it from alloy so the version and all other things are tied to it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ruint is already reexported so it can be removed, but rlp needs the "arrayvec" feature flag


pub fn log_rlp_hash(logs: &[Log]) -> B256 {
let mut out = Vec::with_capacity(alloy_rlp::list_length(logs));
alloy_rlp::encode_list(logs, &mut out);
Copy link
Member

Choose a reason for hiding this comment

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

oh, this is nice!

Ok(output)
}

pub fn deserialize_str_as_u256<'de, D>(deserializer: D) -> Result<U256, D::Error>
Copy link
Member

Choose a reason for hiding this comment

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

nice

pub storage_keys: Vec<B256>,
}

pub type AccessList = Vec<AccessListItem>;

pub fn deserialize_maybe_empty<'de, D>(deserializer: D) -> Result<Option<Address>, D::Error>
Copy link
Member

Choose a reason for hiding this comment

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

You moved this function from models/deserializalizer.rs file, imo original place seems like a better place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed all the functions preemptively then added them back in because it failed parsing. Just forgot to put it back in its original place

|| name == "Call50000_sha256.json"
|| name == "static_Call50000_sha256.json"
|| name == "loopMul.json"
|| name == "CALLBlake2f_MaxRounds.json"
Copy link
Member

Choose a reason for hiding this comment

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

good cleanup

)),
B160(hex!("dcc5ba93a1ed7e045690d722f2bf460a51c61415")),
b256!("fe13266ff57000135fb9aa854bbfe455d8da85b21f626307bf3263a0c2a8e7fe"),
address!("dcc5ba93a1ed7e045690d722f2bf460a51c61415"),
Copy link
Member

Choose a reason for hiding this comment

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

love this macros

fn basic(&mut self, address: B160) -> Result<Option<AccountInfo>, Self::Error> {
let add = eH160::from(address.0);
fn basic(&mut self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
let add = eH160::from(address.0 .0);
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct?

Suggested change
let add = eH160::from(address.0 .0);
let add = eH160::from(address.0);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, Address is a wrapper around FixedBytes<20>, which itself is a wrapper around [u8; 20]: https://docs.rs/alloy-primitives/latest/alloy_primitives/struct.Address.html

Copy link
Member

@rakita rakita Aug 16, 2023

Choose a reason for hiding this comment

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

I thought that Address wraps only [u8; 20], makes sense

fn storage(&mut self, address: B160, index: U256) -> Result<U256, Self::Error> {
let add = eH160::from(address.0);
fn storage(&mut self, address: Address, index: U256) -> Result<U256, Self::Error> {
let add = eH160::from(address.0 .0);
Copy link
Member

Choose a reason for hiding this comment

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

same here?

Suggested change
let add = eH160::from(address.0 .0);
let add = eH160::from(address.0);

@rakita rakita merged commit f95b7a4 into bluealloy:main Aug 16, 2023
@DaniPopes DaniPopes deleted the alloy branch August 16, 2023 10:41
Evalir added a commit to Evalir/revm that referenced this pull request Aug 17, 2023
rakita added a commit that referenced this pull request Aug 18, 2023
rakita added a commit that referenced this pull request Aug 18, 2023
rakita added a commit that referenced this pull request Aug 18, 2023
rakita added a commit that referenced this pull request Aug 18, 2023
mikelodder7 pushed a commit to LIT-Protocol/revm that referenced this pull request Sep 12, 2023
@github-actions github-actions bot mentioned this pull request Jan 12, 2024
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.

2 participants