Skip to content

Commit

Permalink
fix: compiler path issue with compiler breakable changes (#1212)
Browse files Browse the repository at this point in the history
* fix: compiler path issue with compiler breakable changes

* fix: update tests with env values and provide amd url for the compiler

* fix: update tests and revert older validation for breakable compiler version

* chore: spell fix

* fix: revert validation to be consistent

---------

Co-authored-by: Marko Arambasic <[email protected]>
  • Loading branch information
kiriyaga-txfusion and kiriyaga authored Jul 9, 2024
1 parent a7b57f6 commit c4231d9
Show file tree
Hide file tree
Showing 23 changed files with 507 additions and 114 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ jobs:
pnpm hardhat compile
pnpm hardhat deploy-zksync
- name: Test zksolc example with remote origin
env:
ZKSOLC_PATH: https://github.com/matter-labs/zksolc-bin/releases/download/v1.5.1/zksolc-linux-amd64-musl-v1.5.1
run: |
cd examples/download-with-compiler-origin
pnpm hardhat compile
pnpm hardhat deploy-zksync
- name: Test deploy example
run: |
cd examples/deploy-example
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-example/contracts/001_deploy/Greeter.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
pragma solidity ^0.7.0;
pragma abicoder v2;

contract Greeter {
Expand Down
11 changes: 9 additions & 2 deletions examples/basic-example/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ const config: HardhatUserConfig = {
// Docker image only works for solidity ^0.8.0.
// For earlier versions you need to use binary releases of zksolc.
solidity: {
version: '0.8.17',
},
compilers: [
{
version: '0.8.17',
eraVersion: '1.0.0'
},
{
version: '0.7.6',
}
]}
};

export default config;
7 changes: 7 additions & 0 deletions examples/download-with-compiler-origin/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: [`${__dirname}/../../config/eslint/eslintrc.cjs`],
parserOptions: {
project: `${__dirname}/tsconfig.json`,
sourceType: "module",
},
};
4 changes: 4 additions & 0 deletions examples/download-with-compiler-origin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cache
artifacts
contracts/tmp
deployments
64 changes: 64 additions & 0 deletions examples/download-with-compiler-origin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ZKsync Era deploy environment example

This project demonstrates how to compile and deploy your contracts in ZKsync Era using the Hardhat plugins.

## Prerequisites

- node.js 16.x or later.
- yarn.

## Configuration

Plugin configuration is located in [`hardhat.config.ts`](./hardhat.config.ts).
You should only change the ZKsync network configuration.

`hardhat.config.ts` example with ZKsync network configured with the name `ZKsyncNetwork` and `ethNetwork` used as the underlying layer 1 network:
```ts
import "@matterlabs/hardhat-zksync-deploy";
import { HardhatUserConfig } from 'hardhat/types';

const config: HardhatUserConfig = {
networks: {
ethNetwork: {
url: 'http://0.0.0.0:8545',
},
ZKsyncNetwork: {
url: 'http://0.0.0.0:3050',
ethNetwork: 'ethNetwork',
zksync: true,
deployPaths: ['deploy-ZKsync', 'deploy'],
accounts: ['0xac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3', '0x28a574ab2de8a00364d5dd4b07c4f2f574ef7fcc2a86a197f65abaec836d1959'],
},
}
};

export default config;
```

## Usage

Before using plugins, you need to build them first

```sh
# Run the following in the *root* of the repo.
yarn
yarn build
```
Setup your `ZKSOLC_PATH` path inside your `.env` file

After that you should be able to run plugins:

```sh
# Run the following in `examples/basic-example` folder.
yarn
yarn hardhat compile
yarn hardhat deploy-zksync
```

- `yarn hardhat compile`: compiles all the contracts in the `contracts` folder.
- `yarn hardhat deploy-zksync`: runs all the deploy scripts.
- To run a specific script, add the `--script` argument, e.g. `--script 002_deploy.ts`.
- To run on a specific ZKsync network, use standard hardhat `--network` argument, e.g. `--network ZKsyncNetworkV2`
(with `ZKsyncNetwork` network specified in the `hardhat.config` networks section, with the `zksync` flag set to `true` and `ethNetwork` specified).

If you don't specify ZKsync network (`--network`), `local-setup` with <http://localhost:8545> (Ethereum RPC URL) and <http://localhost:3050> (ZKsync RPC URL) will be used.
12 changes: 12 additions & 0 deletions examples/download-with-compiler-origin/contracts/Constant.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract Constant {
uint c = 42;
constructor() {}

function getValue() public view returns (uint) {
return c;
}
}
7 changes: 7 additions & 0 deletions examples/download-with-compiler-origin/contracts/Foo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract Foo {
string public name = "Foo";
}
18 changes: 18 additions & 0 deletions examples/download-with-compiler-origin/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract Greeter {
string greeting;
constructor(string memory _greeting) {
greeting = _greeting;
}

function greet() public view returns (string memory) {
return greeting;
}

function setGreeting(string memory _greeting) public {
greeting = _greeting;
}
}
18 changes: 18 additions & 0 deletions examples/download-with-compiler-origin/deploy/003_deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import chalk from 'chalk';

const deployScript = async function (hre: HardhatRuntimeEnvironment) {
console.info(chalk.yellow(`Running deploy script for the Constant contract from deploy folder`));

// Load the artifact we want to deploy.

// Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
// This contract has no constructor arguments.
const factoryContract = await hre.deployer.deploy('Constant');

// Show the contract info.
const contractAddress = await factoryContract.getAddress();
console.info(chalk.green(`Constant was deployed to ${contractAddress}!`));
};

export default deployScript;
43 changes: 43 additions & 0 deletions examples/download-with-compiler-origin/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import '@matterlabs/hardhat-zksync-deploy';
import '@matterlabs/hardhat-zksync-solc';

import { HardhatUserConfig } from 'hardhat/config';
require('dotenv').config();

const config: HardhatUserConfig = {
zksolc: {
compilerSource: 'binary',
settings: {
compilerPath: process.env.ZKSOLC_PATH,
enableEraVMExtensions: true,
optimizer: {
enabled: true,
},
}
},
deployerAccounts: {
'ZKsyncNetwork': 1
},
defaultNetwork: "ZKsyncNetwork",
networks: {
hardhat: {
zksync: true,
},
ethNetwork: {
url: 'http://0.0.0.0:8545',
},
ZKsyncNetwork: {
url: 'http://0.0.0.0:3050',
ethNetwork: 'ethNetwork',
zksync: true,
accounts: ['0xac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3', '0x28a574ab2de8a00364d5dd4b07c4f2f574ef7fcc2a86a197f65abaec836d1959'],
},
},
// Docker image only works for solidity ^0.8.0.
// For earlier versions you need to use binary releases of zksolc.
solidity: {
version: '0.8.17',
},
};

export default config;
47 changes: 47 additions & 0 deletions examples/download-with-compiler-origin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "hardhat-zksync-example-compiler-origin",
"version": "0.1.0",
"author": "Matter Labs",
"license": "MIT",
"scripts": {
"lint": "pnpm eslint",
"prettier:check": "pnpm prettier --check",
"lint:fix": "pnpm eslint --fix",
"fmt": "pnpm prettier --write",
"eslint": "eslint deploy/*.ts",
"prettier": "prettier deploy/*.ts",
"test": "mocha test/tests.ts --exit",
"build": "tsc --build .",
"clean": "rimraf dist"
},
"devDependencies": {
"@types/node": "^18.11.17",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "^5.0.1",
"prettier": "3.3.0",
"rimraf": "^5.0.7",
"ts-node": "^10.9.2",
"typescript": "^5.3.0",
"dotenv": "^16.4.5"
},
"dependencies": {
"@matterlabs/hardhat-zksync-deploy": "workspace:^",
"@matterlabs/hardhat-zksync-solc": "workspace:^",
"chalk": "^4.1.2",
"hardhat": "^2.22.5",
"ethers": "^6.12.2",
"zksync-ethers": "^6.8.0"
},
"prettier": {
"tabWidth": 4,
"printWidth": 120,
"parser": "typescript",
"singleQuote": true,
"bracketSpacing": true
}
}
19 changes: 19 additions & 0 deletions examples/download-with-compiler-origin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"outDir": "dist"
},
"include": [
"./hardhat.config.ts",
"./scripts",
"./test",
"typechain/**/*",
"deploy/*",
"deploy-ZKsync/*"
]
}
1 change: 1 addition & 0 deletions packages/hardhat-zksync-solc/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const DETECT_MISSING_LIBRARY_MODE_COMPILER_VERSION = '1.3.14';
export const USER_AGENT =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
export const TASK_UPDATE_SOLIDITY_COMPILERS = 'compile:update-solidity-compilers';
export const TASK_DOWNLOAD_ZKSOLC = 'compile:zksolc:download';

export const ZKSOLC_COMPILER_PATH_VERSION = 'local_or_remote';

Expand Down
Loading

0 comments on commit c4231d9

Please sign in to comment.