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

Export precompileAvailability from evm/precompiles/index.ts #2812

Conversation

CedarMist
Copy link
Contributor

This is a trivial fix to make the precompileAvailability list available, given than precompiles is also exported.

Why?

Unfortunately there are situations where it's necessary to monkey-patch custom precompiles into an application which uses ethereumjs and no other method is easily available.

While precompiles is exported the getPrecompile function will not let you use anything added to it as it does not pass the availability check. See:

const availability = precompileAvailability[addr]

An alternative method is to override the getPrecompile function, with a fallback to the original getPrecompile method.

@jochem-brouwer
Copy link
Member

That's true, but precompiles themselves are exported and you can add them as custom precompiles in the EVM.

But, nevertheless, it makes sense to export it.

@CedarMist
Copy link
Contributor Author

CedarMist commented Jun 22, 2023

and you can add them as custom precompiles in the EVM.

This is in the context where you don't have control over the EVM constructor without very intrusive patches to several third-party apps, or maintaining a fork of ethereumjs and patching the other apps to use it. I just need to add the precompiles to the global list before anything else creates an EVM instance, then they become available and it makes maintaining custom precompiles much easier.

@jochem-brouwer
Copy link
Member

Yes, I agree. Since we are (likely) to change the name of this object (including the type), I have cherry-picked your commit in #2811

@CedarMist CedarMist closed this Jun 22, 2023
@jochem-brouwer
Copy link
Member

Merged the PR :)

@CedarMist
Copy link
Contributor Author

Awesome thanks!

@CedarMist
Copy link
Contributor Author

@jochem-brouwer Just to follow up, here is an example use case where custom precompiles are added without patching a third-party product: xmzheng/hardhat-precompiles-plugin@c7d39ad

@CedarMist CedarMist deleted the CedarMist/expose-precompileAvailability branch June 23, 2023 21:31
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