-
Notifications
You must be signed in to change notification settings - Fork 14
Contract Host refactoring, and many other things #148
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…er support for payment (i.e. non-invocation) transactions
fcecin
approved these changes
Jan 16, 2025
Jean-Lessa
requested changes
Jan 16, 2025
Collaborator
Jean-Lessa
left a comment
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.
Overall great work! Aside from my comments here, I see the branch has some compilation errors yet to be resolved (probably due to the massive alterations I did for SonarQube coverage). If that becomes too much work to fix, let me know and I'll see what I can do to help.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This work was initially just a refactoring of the big and complex ContractHost class, but later many flaws were found and will be fixed with this PR.
Some important changes include:
Proper reversion of EVM contracts. Basically, we did not support reverting single contract calls. This PR includes a family of functions for allowing that.
Fixed gas usage. During the execution flow of the
ContractHost, sometimes the wrong amount of gas was charged.The call tracer previous implementation was uglier, slower, less flexible, and error-prone. The new implementation is way more robust and correct.
Delegate calls are now working.
ContractHostresponsibilities were divided between the classesMessageDispatcher,CallTracer,ExecutionContext,CppContractExecutor,EvmContractExecutor, andPrecompiledContractExecutor. Thus, the newContractHostclass is smaller and simpler.The new
ExecutionContextclass is now responsible for reverting the contracts state during calls reversions.Used a lot of generic code to reuse code that process contract calls. (Take a look at the
MessageDispatcherclass)A family of types for Encoded Messages (EVM) and Packed Messages (CPP), allowing us to reuse common message
processing code, and preventing us from the temptation of using the terrible
evmc_messageclass.C++ concepts added for selecting specific message types during overload resolution. (
MessageDispatcheris a good usage example for that)C++ traits added for functions and messages
Additionally, this PR introduces a family of "view" types and new algorithms for byte manipulation:
View<Address>,View<Hash>,View<Signature>, andView<Bytes>. In short, they aim to replace a constant reference with a view object, just likestd::string_viewreplacesconst std::string&. For example, aView<Address>can be cheaply created from bothAddressandevmc::addresstypes.SafeHashand the newSafeComparenow allow "transparent search". That means calls to.find()in map objects with different types thanKeyare allowed as long as they are equally comparable with the key type and the hash function accepts them. This is especially useful for theContractHostneeds, where we have maps whose key type isAddress, but often searches useevmc::addressobjects. In this case, we would need to convert (i.e. copy the bytes) from one type to another, but with transparent search a call tofind()with aevmc::addressargument is perfectly valid.Introduced
bytes::random()andbytes::random(size_t)functions. They initialize byte containers with random data. Thebytes::random()matches the container size, while thebytes::random(size_t)can be used where a sized initializer is required.Introduced
bytes::hex()for initializing a container with a hexadecimal string representation. Ex:Address addr = bytes::hex("0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359");Introduced
bytes::cast()function for general-purpose bytes range conversion. For example:HashandView<Hash>can now be converted touint256_tby usingstatic_cast. Example:bytes::Viewdeprecated and replaced byView<Bytes>.strings.hheader broke into multiple header files:fixedbytes.h,signature.h,address.h, andhash.h.