Skip to content

Conversation

@0xOmarA
Copy link
Contributor

@0xOmarA 0xOmarA commented Jul 13, 2025

Summary

This PR fixes some issues that we had in computing the function selector and in the encoding of arguments for functions

Description

Tl;Dr: I made the following changes in this PR:

  1. Corrected the way in which the function selector was computed.
  2. Changed the logic that parses the Input.calldata -> Bytes to align more with matterlabs, which fixed a bug I encountered.

I encountered an issue where the function selector that we computed didn't seem to be correct as can be seen from the following logs:

  2025-07-13T13:37:06.060606Z ERROR revive_dt_core::driver: Failed to construct legacy transaction: Function with selector [223, 254, 173, 208] not found in ABI for the instance "Main"
    at crates/core/src/driver/mod.rs:145 on main ThreadId(1)
    in revive_dt_core::driver::Executing case with case: "first", case_idx: 0
    in retester::Running driver with metadata_file_path: "era-compiler-tests/solidity/complex/array_one_element/test.json"

  2025-07-13T13:37:06.060626Z ERROR revive_dt_core::driver: Leader execution failed for Main: Function with selector [223, 254, 173, 208] not found in ABI for the instance "Main"
    at crates/core/src/driver/mod.rs:476 on main ThreadId(1)
    in revive_dt_core::driver::Executing case with case: "first", case_idx: 0
    in retester::Running driver with metadata_file_path: "era-compiler-tests/solidity/complex/array_one_element/test.json"

After doing some digging, I discovered that we were attempting to compute the function selector from the function name alone and without making use of the function arguments types.

I corrected that to align more with the matter-labs-tester: now we obtain the function selector from the ABI by function name. It looks like the matter-labs team do not account for function overloads, and therefore we didn't account for them either. It seems like they enforce that there will never be function overloads in tests (at least in the functions that gets called from the tests).

I then faced the following error after correcting the way that we compute the function selector:

  2025-07-13T14:38:54.180925Z ERROR revive_dt_core::driver: Failed to construct legacy transaction: Unsupported type: uint256[1]
    at crates/core/src/driver/mod.rs:145 on main ThreadId(1)
    in revive_dt_core::driver::Executing case with case: "first", case_idx: 0
    in retester::Running driver with metadata_file_path: "era-compiler-tests/solidity/complex/array_one_element/test.json"

  2025-07-13T14:38:54.180949Z ERROR revive_dt_core::driver: Leader execution failed for Main: Unsupported type: uint256[1]
    at crates/core/src/driver/mod.rs:476 on main ThreadId(1)
    in revive_dt_core::driver::Executing case with case: "first", case_idx: 0
    in retester::Running driver with metadata_file_path: "era-compiler-tests/solidity/complex/array_one_element/test.json"

Digging deeper, it looked like our implementation for argument encoding different from the implementation of matter-labs where we were trying to support more types than they support. Additionally, we attempt to decode the arguments based on the ABI of the method whereas they decode the arguments without the ABI context at all. In this case, I think that it's also best that we align with their implementation since they author the test suite and therefore it's better that our parser aligns with theirs. Therefore, I changed the implementation of Input -> Calldata to not rely on the ABI and to have the same parsing logic as them.

These two changes have fixed the issues that I've been seeing, and I think that I finally got my first test case to work 🎉!

@0xOmarA 0xOmarA force-pushed the bugfix/argument-encoding branch from 596a572 to e3723e7 Compare July 13, 2025 16:52
}

#[test]
fn test_encoded_input_bool() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this since the matterlabs parser doesn't support parsing of booleans and we've aligned our parsing implementation with theirs.

}

#[test]
fn test_encoded_input_string() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this since the matterlabs parser doesn't support parsing of strings and we've aligned our parsing implementation with theirs.

}

#[test]
fn test_encoded_input_uint256_array() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this since the matterlabs parser doesn't support parsing of arbitrary length arrays and we've aligned our parsing implementation with theirs.

// add logic that does their resolution in the future, perhaps through some kind of system
// context API that we pass down to the resolution function that allows it to make calls to
// the node to perform these resolutions.
let is_unsupported = [
Copy link
Contributor Author

@0xOmarA 0xOmarA Jul 13, 2025

Choose a reason for hiding this comment

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

Highlighting this bit for reviewers. We don't currently support these variables in our testing framework. It's certainly possible to support them. I think that the best way would be for us to add some kind of ResolverApi in the future that is passed to the resolve function that allows for it to fetch such information.

Copy link
Member

Choose a reason for hiding this comment

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

I'd assume they can be fetched via the ethereum RPC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, I think that we should be able to get all of this information from the RPC. I was hoping to first implement #40 to make async communication with the RPC slightly simpler before adding support for them. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xermicus I have added support for these in #43

Cargo.toml Outdated
"json",
"env-filter",
] }
web3 = { version = "0.19.0", default-features = false }
Copy link
Member

Choose a reason for hiding this comment

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

Is there anything missing in alloy which the web3 crate provides? I don't think so and would like to stick with alloy only (also this was last released 2 years ago).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I think that we can do the same with alloy::primitives::U256. Initially, I wanted to not modify the matterlabs implementation as to have an easier way to verify its correctness, but you're right a lot of these methods have counterparts in alloy::primitives::U256.

I have made this change so we're no longer using the web3 crate.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. Very nice thanks. Helps maintainability greatly to have only a single crate for helpers like this.

// add logic that does their resolution in the future, perhaps through some kind of system
// context API that we pass down to the resolution function that allows it to make calls to
// the node to perform these resolutions.
let is_unsupported = [
Copy link
Member

Choose a reason for hiding this comment

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

I'd assume they can be fetched via the ethereum RPC?

@0xOmarA 0xOmarA mentioned this pull request Jul 14, 2025
@0xOmarA 0xOmarA mentioned this pull request Jul 14, 2025
3 tasks
@0xOmarA 0xOmarA added this pull request to the merge queue Jul 15, 2025
Merged via the queue into main with commit c2e65f9 Jul 15, 2025
5 checks passed
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.

3 participants