-
Notifications
You must be signed in to change notification settings - Fork 35
feat: compilation script + CREATE opcode #43
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
Conversation
|
merged the other PR, not sure if this one needs a merge/rebase |
|
i'd have to update github actions for this one, as it needs to run the compilation binary first. how does the approach look like? are u on board? or would u do it differently? @leonardoalt |
|
So the problem we're solving here is that:
I like the approach with the |
|
exactly, when we have a contract dependency, we need that contract to be compiled before time so that we can access its bytecode. despite cargo would automatically compile it, the problem is that it must be compiled twice:
so without the custom script that i wrote, compilation would fail all the time. the problem that i was facing with custom build scripts for each contract is that those must be compiled with nightly and the riscv target, whereas r55 is compiled with stable 1.84. i was having issues running "sub" cargo build commands for the individual contracts when triggered from the r55 build (stable 1.84). hence why i ended up using a custom script that orchestrates everything. |
|
I think worth merging this in, and then we can move on to trying out examples. |
cool, i'll update the CI to run the compilation script + make sure all tests pass |
|
I think this needs a rebase/merge now? |
The merge-base changed after approval.
The merge-base changed after approval.
The merge-base changed after approval.
The merge-base changed after approval.
TODO: i need to update the CI as right now this fails to compilethis PR adds support for x-contract creation via the
CREATEopcode, but it also comes with extra benefitsNote that it is just a PoC, and i'm obviously open to try different alternatives if u have suggestions! If u validate the design though, i'll go ahead an implement Uniswap V2 as another example
low-level implementation
It is quite similar to the
CALLsyscall, but it uses aCREATEinterpreter action instead.However, in this case the returned data (address of the created contract) is not available in the interpreter's
return_data_buffer. Because of that, i had to create a new syscall (ReturnCreateAddress) to specifically return the cached address. Note that i made sure to use the ID of an opcode that doesn't require a syscall0x01 ADDas it is supported by the RISCV emulatordev-ex
the challenge of this PR was to allow users to deploy a new contract with something as simple as
ERC20::deploy(owner)which ideally returns an interface instance, so that users can already interact with it.to do, so the "deployer" contract needs to embed the bytecode of the "deployed" contract, which requires a specific compilation order + the ability to access such bytecode.
i've tried several approaches, and this was the one that i like the most in terms of dev-ex (and one of the few that i managed to get working).
my proposed solution: the
r55-compilebinary, which:examples/deployable.rsfile in the "deployer" lib (in the exampleerc20x/deployable.rs) which creates a deployable struct for each contract dependencyadditional benefits of this approach: it also generates a module
r55/generated/mod.rsso that all tests cases can directly access the compiled bytecode and deploy contractssince i know it is not ideal for users to have to run a script, i tried to make it as easy as possible (i created an alias), and the workflow would be:
cargo compile-> autogenerates the deployable implcargo compileagain so that ur contract is compiledcargo test-r55question: how does r55 integration when developing smart contracts looks like? how do we pack it? note that my proposal is limited to the examples directory right now, although obviously we could make it read the path form an env var or something.