-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add support for Solidity using the Solang compiler #2421
Conversation
@seanyoung is attempting to deploy a commit to the coral-xyz Team on Vercel. A member of the Team first needs to authorize it. |
Not to be rude but I am struggling to understand how this fits into anchor? Can you help me to understand what the connection is between creating a solidity file as an option in
|
You're right, this could do with some more explanation. For some time now we have been working on a new solidity compiler which compiles Solidity directly to BPF and also produces an IDL metadata file. This is huge amount of work, and this is being worked on by Solana Labs. anchor does provide a bunch of rust macros, that is true, but it also provides much more. There is an anchor npm library for client side code. The anchor cli tool allows you to create an anchor workspace, build the smart contracts, test, deploy, and work with the idl files. As you point out, anchor deals with account constraints which solana sealevel imposes. This problem also exists for Solidity as it does for any on-chain solana program. So the aim is make Solidity also a supported language so that solidity programs can live side by side with rust programs. That way, all the tooling provided by anchor for managing builds, tests, publishing idl files, writing client code/tests, deal with account constraints can be reused. I would imagine that once the move compiler starts to mature, it would be great to also add support for move to anchor. I hope this helps, happy to provide further explanation of course. FWIW here is what you can do with this PR. $ anchor init --solidity foo
yarn install v1.22.19
warning package.json: No license field
info No lockfile found.
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 29.16s.
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /home/sean/anchor/foo/.git/
foo initialized
$ cd foo
$ anchor build
info: Solang version v0.2.2-14-g28da9113
help: found contract 'foo'
┌─ /home/sean/anchor/foo/solidity/foo.sol:3:1
│
3 │ ╭ contract foo {
4 │ │ bool private value = true;
5 │ │
6 │ │ @payer(payer)
· │
21 │ │ }
22 │ │ }
│ ╰─^
info: contract foo uses at least 17 bytes account data
info: Generating LLVM IR for contract foo with target solana
info: Saving binary /home/sean/anchor/foo/target/deploy/foo.so for contract foo
info: Generating Anchor metadata for contract foo
info: Saving metadata /home/sean/anchor/foo/target/idl/foo.json for contract foo
$ anchor test
info: Solang version v0.2.2-14-g28da9113
help: found contract 'foo'
┌─ /home/sean/anchor/foo/solidity/foo.sol:3:1
│
3 │ ╭ contract foo {
4 │ │ bool private value = true;
5 │ │
6 │ │ @payer(payer)
· │
21 │ │ }
22 │ │ }
│ ╰─^
info: contract foo uses at least 17 bytes account data
info: Generating LLVM IR for contract foo with target solana
info: Saving binary /home/sean/anchor/foo/target/deploy/foo.so for contract foo
info: Generating Anchor metadata for contract foo
info: Saving metadata /home/sean/anchor/foo/target/idl/foo.json for contract foo
Found a 'test' script in the Anchor.toml. Running it as a test suite!
Running test suite: "/home/sean/anchor/foo/Anchor.toml"
yarn run v1.22.19
warning package.json: No license field
$ /home/sean/anchor/foo/node_modules/.bin/ts-mocha -p ./tsconfig.json -t 1000000 'tests/**/*.ts'
foo
Your transaction signature 2DoHfoXDvLzqQUyccN5pBAsogPXKwsE3TyZqxoMKSTZMsguW7WrJh5JHSas8t6z5mxSCY8Aor4U1wGSFLWKm3zXi
state true
state false
✔ Is initialized! (687ms)
1 passing (692ms)
Done in 2.29s.
[sean@xywoleh foo]$ ~/git/anchor/target/debug/anchor deploy
Deploying workspace: http://localhost:8899
Upgrade authority: /home/sean/.config/solana/id.json
Deploying program "foo.sol"...
Program path: /home/sean/anchor/foo/target/deploy/foo.so...
Program Id: 6PuQ1EmxFemjWSNUNKMMgqa1w64VjRtAWD2ZQ8pLrJKM
Deploy success |
Thanks for the detailed reply, I definitely understand a bit more what your goal is here! The main issue I see is that the anchor framework itself isn't built into solang. So while it looks like an IDL gets added to the target directory, there's no guarantee that the IDL format is still up-to-date with the current anchor IDL format, particularly if there have been breaking changes or bug fixes. Also presumably none of the Wouldn't it be possible to make your own solang CLI? Sure, the anchor CLI is an important part of how anchor functions in practice but I don't know if it's important enough to start making it into its own thing. Namely, you seem to be framing the anchor CLI as one of the main focuses of anchor, rather than a supporting tool (it's really just My basic reaction is that given the anchor framework as it is today, it just doesn't seem that fitting to say to users: "hey, instead of writing a smart contract using anchor would you like to use something completely different instead". As for using the anchor npm library, it should be easy to write client side code assuming you have a compatible IDL and you should totally encourage people to do that if it makes their life easier. That part doesn't require any integration or changes to anchor. Anyway, let me know what you think. Does this reply make sense to you? Hopefully this isn't a totally unreasonable position. |
Discussed in Discord. Going to go forward with this PR! |
Wonderful. Tomorrow I'll go over the PR again, and see if there is anything that needs improving. |
@seanyoung bump on this. Anything you'd like to update before a review pass? |
@armaniferrante so I've been working on getting verified builds working with Solidity. This is not finished yet. What's here is ready to for review if you're happy to wait for verified builds to work. Thank you! |
There was an issue where solana-program 1.15.2 not building, so I've updated the dependencies. The tests should be better now. (Unrelated by my changes) |
0ae1b52
to
00b57ba
Compare
Reran the failing tests. |
02950d9
to
17bb2f1
Compare
The only failing test is the vercel, which says |
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.
I don't have any strong opinions but I have to agree with @Henry-E here that this feels out of place.
solang is required to be in the path, this can be downloaded from the release at https://github.com/hyperledger/solang
It seems like we are including a template to anchor cli that users would have to download separately to run anyway.
And as @Henry-E pointed out, any changes to the idl like in #2011 can/will cause solang to produce outdated/incompatible idl.
If these issues are not a big concern, I think this is OK to merge once the review comments are addressed and CHANGELOG is updated.
anchor init and anchor new have a new option `-s` (or `--solidity`) which creates an example using Solidity in the soldity directory of the anchor workspace. anchor deploy/build/test work accordingly. solang is required to be in the path, this can be downloaded from the release at https://github.com/hyperledger/solang anchor build/deploy finds all the solidity contracts by using the solidity parser to find all contract declarations.
The plan is to include solang in the Solana SDK.
I've added an entry to the changelog and addressed your sensible review comments. Please let me know what you think. |
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.
Looks good, thank you for updating!
@acheroncrypto thank you very much! |
anchor verify -p |
Solang is no longer maintained, unfortunately. Funding was cut and I was moved to other things: anza-xyz/agave#2010 |
anchor init has a new option
-s
(or--solidity
) which creates an example using Solidity in the soldity directory of the anchor workspace.anchor deploy/build/test work accordingly.
solang is required to be in the path, this can be downloaded from the release at https://github.com/hyperledger/solang
anchor build/deploy finds all the solidity contracts by using the solidity parser to find all contract declarations.
Next steps: