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: Refactore Executor #64

Merged
merged 3 commits into from
Oct 15, 2024
Merged

Feat: Refactore Executor #64

merged 3 commits into from
Oct 15, 2024

Conversation

mrLSD
Copy link
Member

@mrLSD mrLSD commented Oct 14, 2024

Description

Refactoring: create_inner and gas_limit calculation.

@mrLSD mrLSD added the enhancement New feature or request label Oct 14, 2024
@mrLSD mrLSD self-assigned this Oct 14, 2024
@mrLSD mrLSD added this to the v0.45.6-aurora milestone Oct 14, 2024
@@ -448,8 +448,8 @@ pub fn create<H: Handler>(runtime: &mut Runtime, is_create2: bool, handler: &mut
};

match handler.create(runtime.context.address, scheme, value, code, None) {
Capture::Exit((reason, address, return_data)) => {
match super::finish_create(runtime, reason, address, return_data) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we can remove the address return here because finish_create pushes the address onto the EVM stack which I think is required for the CREATE instruction.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, we can. handler.create operates over create_inner and doesn't return either. In terms of internal refactoring, it's good enough to remove redundant code. There's no case for that logic, and it was added "because I can" without design rethinking. It's good practice to follow Keep It Simple (KIS), simplifying things for better productivity and clear algorithms and code.

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. The Capture::Exit case used to always have address: None because it was only returned when the call to create_inner encountered an error and therefore no contract was created. The happy path is returning Capture::Trap and finish_create ends up being called later with the created address as part of the EVM call stack handling logic. Maybe it is worth adding a comment that the Capture::Exit case only happens if there was an error. Maybe also worth adding debug_assert!(!reason.is_succeed()) to make sure this assumption is upheld in the future.

As for removing unused code, I fully agree with doing that to make maintaining the code easier going forward! I just wanted to make sure the code path really was unused.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, thanks.
In order to get closer to proving correctness, I implemented 100% passing of tests from ethereum/tests and ethereum/execution-spec-tests. And this is a big step forward. For greater persuasiveness, it is necessary to cover the entire code with tests. However, this task will take, in my opinion, a lot of time, since the EVM logic is really complex. This does not mean that it should not be done - it is just a lower priority.

Copy link
Member

@birchmd birchmd left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to do some code cleanup here!

@@ -448,8 +448,8 @@ pub fn create<H: Handler>(runtime: &mut Runtime, is_create2: bool, handler: &mut
};

match handler.create(runtime.context.address, scheme, value, code, None) {
Capture::Exit((reason, address, return_data)) => {
match super::finish_create(runtime, reason, address, return_data) {
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. The Capture::Exit case used to always have address: None because it was only returned when the call to create_inner encountered an error and therefore no contract was created. The happy path is returning Capture::Trap and finish_create ends up being called later with the created address as part of the EVM call stack handling logic. Maybe it is worth adding a comment that the Capture::Exit case only happens if there was an error. Maybe also worth adding debug_assert!(!reason.is_succeed()) to make sure this assumption is upheld in the future.

As for removing unused code, I fully agree with doing that to make maintaining the code easier going forward! I just wanted to make sure the code path really was unused.

@@ -103,7 +103,7 @@ pub trait Handler {
value: U256,
init_code: Vec<u8>,
target_gas: Option<u64>,
) -> Capture<(ExitReason, Option<H160>, Vec<u8>), Self::CreateInterrupt>;
) -> Capture<(ExitReason, Vec<u8>), Self::CreateInterrupt>;
Copy link
Member

Choose a reason for hiding this comment

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

This is technically a breaking change from the perspective of sputnikvm as a library since we are changing the signature of a method on a public trait. This is not an issue, especially if we are not planning on ever syncing up with upstream again and we are the only users of the library. But I thought it is worth pointing out just in case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's breaking changes. With the release of Prague, we plan to de-fork into our own library aurora-evm, since upstream has completely abandoned the previous version and moved to the new version v1.0-alpha. Moreover, they do not have any development at all for a long time. At the moment, our fork is so different that it is ALREADY practically an independent library. ✊

@aleksuss
Copy link
Member

@mrLSD it couldn't be related to the milestone v0.45.6-aurora because of the breaking change.

@mrLSD mrLSD modified the milestones: v0.45.6-aurora, v0.46.0-aurora Oct 14, 2024
src/executor/stack/executor.rs Show resolved Hide resolved
@mrLSD mrLSD merged commit 83d50fe into master Oct 15, 2024
6 checks passed
@mrLSD mrLSD deleted the feat/refactoring-create branch October 15, 2024 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants