Skip to content

Commit

Permalink
feat(contract-verifier): Support zkVM solc contract verification (mat…
Browse files Browse the repository at this point in the history
…ter-labs#854)

## What ❔

- Downloads zkVM solc binaries in verifier image
- Adds support for new zksolc version support

## Why ❔

Support zkVM solc contract verification

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `zk spellcheck`.
  • Loading branch information
perekopskiy authored Jan 17, 2024
1 parent 3a07890 commit 1ed5a95
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
description: 'JSON of required compilers and their versions'
type: string
required: false
default: '[{ "zksolc": ["1.3.14", "1.3.16", "1.3.17", "1.3.1", "1.3.7", "1.3.18", "1.3.19"] } , { "zkvyper": ["1.3.13"] }]'
default: '[{ "zksolc": ["1.3.14", "1.3.16", "1.3.17", "1.3.1", "1.3.7", "1.3.18", "1.3.19", "1.3.21"] } , { "zkvyper": ["1.3.13"] }]'

jobs:
build-images:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-local-node-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
description: 'JSON of required compilers and their versions'
type: string
required: false
default: '[{ "zksolc": ["1.3.14", "1.3.16", "1.3.17", "1.3.1", "1.3.7", "1.3.18", "1.3.19"] } , { "zkvyper": ["1.3.13"] }]'
default: '[{ "zksolc": ["1.3.14", "1.3.16", "1.3.17", "1.3.1", "1.3.7", "1.3.18", "1.3.19", "1.3.21"] } , { "zkvyper": ["1.3.13"] }]'

jobs:
build-images:
Expand Down
30 changes: 19 additions & 11 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
description: 'JSON of required compilers and their versions'
type: string
required: false
default: '[{ "zksolc": ["1.3.14", "1.3.16", "1.3.17", "1.3.1", "1.3.7", "1.3.18", "1.3.19"] } , { "zkvyper": ["1.3.13"] }]'
default: '[{ "zksolc": ["1.3.14", "1.3.16", "1.3.17", "1.3.1", "1.3.7", "1.3.18", "1.3.19", "1.3.21"] } , { "zkvyper": ["1.3.13"] }]'

jobs:
lint:
Expand All @@ -27,7 +27,7 @@ jobs:
echo IN_DOCKER=1 >> .env
# TODO: Remove when we after upgrade of hardhat-plugins
- name: pre-download compiilers
- name: pre-download compilers
run: |
# Download needed versions of vyper compiler
# Not sanitized due to unconventional path and tags
Expand Down Expand Up @@ -141,11 +141,15 @@ jobs:
wget https://github.com/ethereum/solc-bin/raw/gh-pages/linux-amd64/solc-linux-amd64-v0.8.23%2Bcommit.f704f362
mv solc-linux-amd64-v0.8.23+commit.f704f362 $(pwd)/etc/solc-bin/0.8.23/solc
chmod +x $(pwd)/etc/solc-bin/0.8.23/solc
mkdir -p $(pwd)/etc/solc-bin/zkVM-0.8.23-1.0.0
wget https://github.com/matter-labs/era-solidity/releases/download/0.8.23-1.0.0/solc-linux-amd64-0.8.23-1.0.0 -O $(pwd)/etc/solc-bin/zkVM-0.8.23-1.0.0/solc
chmod +x $(pwd)/etc/solc-bin/zkVM-0.8.23-1.0.0/solc
mkdir -p $(pwd)/etc/zksolc-bin/v1.3.19
wget https://github.com/matter-labs/zksolc-bin/raw/main/linux-amd64/zksolc-linux-amd64-musl-v1.3.19
mv zksolc-linux-amd64-musl-v1.3.19 $(pwd)/etc/zksolc-bin/v1.3.19/zksolc
chmod +x $(pwd)/etc/zksolc-bin/v1.3.19/zksolc
mkdir -p $(pwd)/etc/zksolc-bin/v1.3.21
wget https://github.com/matter-labs/zksolc-bin/raw/main/linux-amd64/zksolc-linux-amd64-musl-v1.3.21
mv zksolc-linux-amd64-musl-v1.3.21 $(pwd)/etc/zksolc-bin/v1.3.21/zksolc
chmod +x $(pwd)/etc/zksolc-bin/v1.3.21/zksolc
mkdir -p $(pwd)/etc/vyper-bin/0.3.10
wget -O vyper0.3.10 https://github.com/vyperlang/vyper/releases/download/v0.3.10/vyper.0.3.10%2Bcommit.91361694.linux
Expand Down Expand Up @@ -250,11 +254,15 @@ jobs:
wget https://github.com/ethereum/solc-bin/raw/gh-pages/linux-amd64/solc-linux-amd64-v0.8.23%2Bcommit.f704f362
mv solc-linux-amd64-v0.8.23+commit.f704f362 $(pwd)/etc/solc-bin/0.8.23/solc
chmod +x $(pwd)/etc/solc-bin/0.8.23/solc
mkdir -p $(pwd)/etc/zksolc-bin/v1.3.19
wget https://github.com/matter-labs/zksolc-bin/raw/main/linux-amd64/zksolc-linux-amd64-musl-v1.3.19
mv zksolc-linux-amd64-musl-v1.3.19 $(pwd)/etc/zksolc-bin/v1.3.19/zksolc
chmod +x $(pwd)/etc/zksolc-bin/v1.3.19/zksolc
mkdir -p $(pwd)/etc/solc-bin/zkVM-0.8.23-1.0.0
wget https://github.com/matter-labs/era-solidity/releases/download/0.8.23-1.0.0/solc-linux-amd64-0.8.23-1.0.0 -O $(pwd)/etc/solc-bin/zkVM-0.8.23-1.0.0/solc
chmod +x $(pwd)/etc/solc-bin/zkVM-0.8.23-1.0.0/solc
mkdir -p $(pwd)/etc/zksolc-bin/v1.3.21
wget https://github.com/matter-labs/zksolc-bin/raw/main/linux-amd64/zksolc-linux-amd64-musl-v1.3.21
mv zksolc-linux-amd64-musl-v1.3.21 $(pwd)/etc/zksolc-bin/v1.3.21/zksolc
chmod +x $(pwd)/etc/zksolc-bin/v1.3.21/zksolc
mkdir -p $(pwd)/etc/vyper-bin/0.3.10
wget -O vyper0.3.10 https://github.com/vyperlang/vyper/releases/download/v0.3.10/vyper.0.3.10%2Bcommit.91361694.linux
Expand Down
6 changes: 6 additions & 0 deletions core/bin/contract-verifier/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ impl ContractVerifier {
);

if artifacts.bytecode != deployed_bytecode {
tracing::info!(
"Bytecode mismatch req {}, deployed: 0x{}, compiled 0x{}",
request.id,
hex::encode(deployed_bytecode),
hex::encode(artifacts.bytecode)
);
return Err(ContractVerifierError::BytecodeMismatch);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x000100000000000200000000000103550000008003000039000000400030043f0000000003010019000000600330027000000027033001970000000102200190000000160000c13d000000040230008c000000550000413d000000000201043b000000e002200270000000290420009c0000001e0000a13d0000002a0420009c0000002b0000613d0000002b0420009c000000320000613d0000002c0120009c0000004a0000613d000000550000013d0000000001000416000000000101004b000000550000c13d0000002001000039000001000010044300000120000004430000002801000041000000970001042e0000002d0420009c000000470000613d0000002e0220009c000000550000c13d0000000002000416000000000202004b000000550000c13d000000040230008a000000200220008c000000550000413d0000000401100370000000000101043b000000570000013d0000000001000416000000000101004b000000550000c13d000000000100041a000000800010043f0000003101000041000000970001042e0000000002000416000000000202004b000000550000c13d000000040230008a000000200220008c000000550000413d0000000401100370000000000101043b000000000200041a0000000001120019000000000221004b000000000200001900000001020040390000000102200190000000570000613d0000002f0100004100000000001004350000001101000039000000040010043f000000300100004100000098000104300000000001000416000000000101004b000000550000c13d00000000010300190096005a0000040f009600730000040f000000400200043d00000000001204350000002701000041000000270320009c0000000002018019000000400120021000000032011001c7000000970001042e00000000010000190000009800010430000000000010041b0000000001000019000000970001042e000000040110008a00000033020000410000003f0310008c000000000300001900000000030220190000003301100197000000000401004b0000000002008019000000330110009c000000000203c019000000000102004b000000710000613d00000000010003670000002402100370000000000202043b000000000302004b0000000003000019000000010300c039000000000332004b000000710000c13d0000000401100370000000000101043b000000000001042d00000000010000190000009800010430000000000300041a0000000001130019000000000331004b0000000003000019000000010300403900000001033001900000007e0000c13d000000000010041b000000000202004b000000840000c13d000000000001042d0000002f0100004100000000001004350000001101000039000000040010043f00000030010000410000009800010430000000400100043d00000044021000390000003403000041000000000032043500000024021000390000001a030000390000000000320435000000350200004100000000002104350000000402100039000000200300003900000000003204350000002702000041000000270310009c0000000001028019000000400110021000000036011001c700000098000104300000009600000432000000970001042e000000980001043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0000000200000000000000000000000000000040000001000000000000000000000000000000000000000000000000000000000000000000000000006d4ce63b000000000000000000000000000000000000000000000000000000006d4ce63c000000000000000000000000000000000000000000000000000000007cf5dab0000000000000000000000000000000000000000000000000000000008f9c4749000000000000000000000000000000000000000000000000000000000436dad60000000000000000000000000000000000000000000000000000000060fe47b14e487b7100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000200000008000000000000000000000000000000000000000000000000000000020000000000000000000000000800000000000000000000000000000000000000000000000000000000000000054686973206d6574686f6420616c77617973207265766572747300000000000008c379a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000000000000000000000000000005912077dbccfda7879a1765d5b280b2a37169a97193512ab62bd94e5027c06b3
2 changes: 1 addition & 1 deletion core/tests/ts-integration/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import '@matterlabs/hardhat-zksync-vyper';

export default {
zksolc: {
version: '1.3.19',
version: '1.3.21',
compilerSource: 'binary',
settings: {
isSystem: true
Expand Down
2 changes: 1 addition & 1 deletion core/tests/ts-integration/scripts/compile-yul.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getZksolcUrl, saltFromUrl } from '@matterlabs/hardhat-zksync-solc';
import { getCompilersDir } from 'hardhat/internal/util/global-dir';
import path from 'path';

const COMPILER_VERSION = '1.3.19';
const COMPILER_VERSION = '1.3.21';
const IS_COMPILER_PRE_RELEASE = false;

async function compilerLocation(): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { sleep } from 'zksync-web3/build/src/utils';
// Regular expression to match ISO dates.
const DATE_REGEX = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{6})?/;

const ZKSOLC_VERSION = 'v1.3.19';
const ZKSOLC_VERSION = 'v1.3.21';
const SOLC_VERSION = '0.8.23';
const ZK_VM_SOLC_VERSION = 'zkVM-0.8.23-1.0.0';

const ZKVYPER_VERSION = 'v1.3.13';
const VYPER_VERSION = '0.3.10';
Expand Down Expand Up @@ -67,6 +68,32 @@ describe('Tests for the contract verification API', () => {
await expectVerifyRequestToSucceed(requestId, requestBody);
});

test('should test zkVM solc contract verification', async () => {
let artifact = contracts.counter;
// TODO: use plugin compilation when it's ready instead of pre-compiled bytecode.
artifact.bytecode = fs.readFileSync(
`${process.env.ZKSYNC_HOME}/core/tests/ts-integration/contracts/counter/zkVM_bytecode.txt`,
'utf8'
);

const counterContract = await deployContract(alice, artifact, []);
const constructorArguments = counterContract.interface.encodeDeploy([]);

const requestBody = {
contractAddress: counterContract.address,
contractName: 'contracts/counter/counter.sol:Counter',
sourceCode: getContractSource('counter/counter.sol'),
compilerZksolcVersion: ZKSOLC_VERSION,
compilerSolcVersion: ZK_VM_SOLC_VERSION,
optimizationUsed: true,
constructorArguments,
isSystem: true
};
let requestId = await query('POST', '/contract_verification', undefined, requestBody);

await expectVerifyRequestToSucceed(requestId, requestBody);
});

test('should test multi-files contract verification', async () => {
const contractFactory = new zksync.ContractFactory(contracts.create.abi, contracts.create.bytecode, alice);
const contractHandle = await contractFactory.deploy({
Expand Down
8 changes: 8 additions & 0 deletions docker/contract-verifier/install-all-solc.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ do

ls etc/solc-bin/
done

# Download zkVM solc
for version in $(curl -s https://api.github.com/repos/matter-labs/era-solidity/releases?per_page=200 | jq -r '.[].tag_name')
do
mkdir -p etc/solc-bin/zkVM-$version/
wget https://github.com/matter-labs/era-solidity/releases/download/$version/solc-linux-amd64-$version -O etc/solc-bin/zkVM-$version/solc
chmod +x etc/solc-bin/zkVM-$version/solc
done

0 comments on commit 1ed5a95

Please sign in to comment.