feat: allow extending foundry for non-EVM chains via strategy implementation #9651
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.
Motivation
As part of #7624 this would form a way to start formulating an approach in order to extend foundry functionality to non-Ethereum/EVM chains in the least invasive way possible.
These "strategies" can be overridden by forks to implement their own functionality, as is demonstrated in foundry-zksync. At the very least, this gives a place for forks to add custom code that can be called in an idiomatic way, until it can be formulated as an upstream PR.
As an initial step, we went with a dynamic dispatch instead of generics as the generic would be required to be propagated to numerous places, and this PR serves as a good start to initiate a discussion on this approach.
Solution
In places of interest -
Executor
,Backend
andCheatcodes
(identified so far), a stateless "strategy" would be provided that works with a context objectBox<Any>
that may be mutated. This allows for forks to implement their own behavior and keep their state separate in the context. The standard "foundry way" is currently encapsulated in theEvmStrategy
, which is the default.Forks are expected to modify the
utils::get_executor_strategy(&config)
(example) to return a strategy of choice depending upon the config.Future Goals
The stateless nature of strategy makes it possible to remove the &self objects, which are currently required for object safety, and thereby being declared on the generic type.