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

Is there any PoC on implementing mathematical operations using Stateful Precompiles in Custom Subnets? #696

Closed
ashucoder9 opened this issue Jun 24, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@ashucoder9
Copy link
Member

Let's suppose I want to create a universal calculator precompile that performs computation like Addition.

Can be extended with toolings to store in the stateDB and more.

I am working on launching something similar to a Counter program and stuck in the contract phase so it'd helpful in understanding working of the functions and their interactions with variable states.

@ashucoder9 ashucoder9 added the enhancement New feature or request label Jun 24, 2023
@aaronbuchwald
Copy link
Collaborator

You can write any golang program you want inside of each precompile function including accessing the stateDB directly if you want to read/write the storage trie of your precompile as long as it is deterministic.

Here's the stateful precompile tutorial: https://docs.avax.network/subnets/hello-world-precompile-tutorial and the most recent pending PR that will update it to make development easier: https:/ava-labs/avalanche-docs/pull/1418/files (pending release of a new repo).

Could you be more specific about what issues you are running into?

@ashucoder9
Copy link
Member Author

ashucoder9 commented Jun 24, 2023

I have pushed a precompile contract in the counter-pc branch here: https:/ashucoder9/subnet-evm/tree/counter-pc

Currently, my goal is to create a counter precompile that returns the value or increments by X as specified (can be 1 also for general increment).

Given that I do not have much experience with GoLang, I might be wrong in implementing the code. Might need a little help on that. Feel free to propose/comment any improvements!

Apart from that, is the precompile disabled by default? If yes, where do we enable it? I remember running the HelloWorld tutorial without any modifications for E2E tests (I assumed it was working PoC) and failed a test for which the most likely reasoning is that it may be disabled.

@ashucoder9
Copy link
Member Author

Even though this attempt is focused on a generalized understanding of the working of mathematical operations with stateful precompiles, it can lead to developing custom EVM extensions that were not implemented in the Ethereum Virtual Machine like this.

@ashucoder9
Copy link
Member Author

@ceyonur can you please check why the Ginkgo tests are failing to run: https:/ashucoder9/subnet-evm/tree/counter-precompile

@aaronbuchwald
Copy link
Collaborator

Hey @ashucoder9 , it looks like CI is not running at all on that repo. Workflows are disabled by default (parameter of GitHub, not related to Subnet-EVM), so you should check to make sure that they are enabled and running correctly.

@ashucoder9
Copy link
Member Author

No worries, I figured the rest out and also updated the docs with new detail. Thanks to @ceyonur!

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

No branches or pull requests

2 participants