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

feat: remove onchain-verifier dependency + add hardhat configuration + add libraries deployment logic #3

Merged
merged 13 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ jobs:
run: forge build

- name: Run Forge tests
run: forge test --fork-url https://rpc.ankr.com/polygon_mumbai -vvvv
env:
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
run: forge test -vvvv
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ lib
.hardhat/contracts

# Deployment files
**deployments/test.json
deployments/test.json
**deployments/test/*.json
**/tmp/*
!**/tmp/example.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
69 changes: 69 additions & 0 deletions .hardhat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<br />
<div align="center">
<img src="https://static.sismo.io/readme/top-main.png" alt="Logo" width="150" height="150" style="borderRadius: 20px">

<h3 align="center">
Sismo Connect Solidity
</h3>

<p align="center">
Made by <a href="https://docs.sismo.io/" target="_blank">Sismo</a>
</p>

<p align="center">
<a href="https://twitter.com/sismo_eth" target="_blank">
<img src="https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white"/>
</a>
<a href="https://discord.gg/sismo" target="_blank">
<img src="https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white"/>
</a>
<a href="https://builders.sismo.io" target="_blank">
<img src="https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white"/>
</a>
</p>
</div>


Sismo Connect Solidity is a Solidity library that allows you to verify the zk-proofs of your Sismo Connect Application onchain and simplify the use of the [sismo-connect-onchain-verifier](https://github.com/sismo-core/sismo-connect-onchain-verifier).

Here is the link to the full documentation of the library: [Sismo Connect Solidity Library](https://docs.sismo.io/build-with-sismo-connect/technical-documentation/solidity)

You can learn more on Sismo Connect [here](https://docs.sismo.io/sismo-docs/build-with-sismo-connect/getting-started).

### Prerequisites

- [Node.js](https://nodejs.org/en/download/) >= 18.15.0 (Latest LTS version)
- [Yarn](https://classic.yarnpkg.com/en/docs/install)

## Usage

### Installation

```bash
# install the package
yarn add @sismo-core/sismo-connect-solidity
```

### Import the library
In your solidity file:

```solidity
import {SismoConnect} from "@sismo-core/sismo-connect-solidity/contracts/SismoConnectLib.sol";
```

You will find here how to use the library: [Sismo Connect Solidity Library](https://docs.sismo.io/build-with-sismo-connect/technical-documentation/solidity)

## License

Distributed under the MIT License.

## Contribute

Please, feel free to open issues, PRs or simply provide feedback!

## Contact

Send us a message in [Telegram](https://builders.sismo.io/) or [Discord](https://discord.gg/sismo)

<br/>
<img src="https://static.sismo.io/readme/bottom-main.png" alt="bottom" width="100%" >
25 changes: 25 additions & 0 deletions .hardhat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@sismo-core/sismo-connect-solidity",
"description": "Sismo Connect Library",
"version": "0.0.21",
"scripts": {
"prepare": "mkdir -p contracts; cp -r ../src/* contracts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sismo-core/sismo-connect-solidity.git"
},
"keywords": [
"solidity",
"ethereum",
"smart",
"contracts"
],
"author": "Sismo <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/sismo-core/sismo-connect-solidity/issues"
},
"homepage": "https://github.com/sismo-core/sismo-connect-solidity#readme",
"main": "index.js"
}
6 changes: 6 additions & 0 deletions deployments/base-goerli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"authRequestBuilder": "0xD4339e6d873b584FFfeACceE4CcB8Bf31Cd96ebb",
"claimRequestBuilder": "0xF03dA119efEc165DbDc15D593aB455810C7fEd74",
"requestBuilder": "0x0bB5c193aa815F7815aB8e854A87E041519CD2ad",
"signatureBuilder": "0xc8F165a3B4CfB7CD2Ae92A582F17b0d7EB3BcE11"
}
6 changes: 6 additions & 0 deletions deployments/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"authRequestBuilder": "0x8D090172DA53A21D27E7B651ab6E7D9334Ea0783",
"claimRequestBuilder": "0x1B05f16686396398F16f8916A032D738005126b7",
"requestBuilder": "0x40e208f4815Ce25b32BeEEC7415C6CA9424a898F",
"signatureBuilder": "0x1e7a99e06Ca2C1A63330eC2df8D4fC15EfDa4C55"
}
24 changes: 16 additions & 8 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ optimizer_runs = 1000000
verbosity = 1
libs = ["lib"]
fs_permissions = [{ access = "read-write", path = "./"}]
ffi = true

bytecode_hash="none"

[fmt]
ignore = ["test/libs/SimoConnectLib.t.sol"]
solc_version="0.8.19"

[rpc_endpoints]
polygon = "${RPC_URL}"
gnosis = "${RPC_URL}"
goerli = "${RPC_URL}"
mumbai = "${RPC_URL}"
mainnet = "${RPC_URL}"
arbitrum_one = "https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
arbitrum_goerli = "https://arb-goerli.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
base = "https://mainnet.base.org"
base_goerli = "https://goerli.base.org"
goerli = "https://eth-goerli.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
gnosis = "https://rpc.gnosischain.com"
localhost = "http://localhost:8545"
mainnet = "https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
mumbai = "https://polygon-mumbai.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
optimism = "https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
optimism_goerli = "https://opt-goerli.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
polygon = "https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
scroll_testnet_goerli = "https://alpha-rpc.scroll.io/l2"
sepolia = "https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at d00ace
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"prettier-plugin-solidity": "^1.0.0-beta.13"
},
"scripts": {
"lint": "prettier --write **.sol",
"setup-fork": "./script/bash/setup-fork.sh"
"test": "forge test",
"save-deployments": "./script/bash/save-deployments.sh",
"lint": "prettier --write **.sol"
}
}
3 changes: 2 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
forge-std/=lib/forge-std/src/
forge-std/=lib/forge-std/src/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
119 changes: 119 additions & 0 deletions script/BaseConfig.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {Script} from "forge-std/Script.sol";
import "forge-std/console.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

struct DeploymentConfig {
address authRequestBuilder;
address claimRequestBuilder;
address requestBuilder;
address signatureBuilder;
}

contract BaseDeploymentConfig is Script {
DeploymentConfig public config;

string public _chainName;
bool public _checkIfEmpty;

address immutable SISMO_ADDRESSES_PROVIDER_V2 = 0x3Cd5334eB64ebBd4003b72022CC25465f1BFcEe6;
address immutable ZERO_ADDRESS = 0x0000000000000000000000000000000000000000;

error ChainNameNotFound(string chainName);

function _setConfig(string memory chainName) internal {
if (
_compareStrings(chainName, "mainnet") ||
_compareStrings(chainName, "gnosis") ||
_compareStrings(chainName, "polygon") ||
_compareStrings(chainName, "optimism") ||
_compareStrings(chainName, "arbitrum-one") ||
_compareStrings(chainName, "base") ||
_compareStrings(chainName, "testnet-goerli") ||
_compareStrings(chainName, "testnet-sepolia") ||
_compareStrings(chainName, "testnet-mumbai") ||
_compareStrings(chainName, "optimism-goerli") ||
_compareStrings(chainName, "arbitrum-goerli") ||
_compareStrings(chainName, "base-goerli") ||
_compareStrings(chainName, "scroll-testnet-goerli") ||
_compareStrings(chainName, "staging-goerli") ||
_compareStrings(chainName, "staging-mumbai") ||
_compareStrings(chainName, "test")
) {
config = _readDeploymentConfig(
string.concat(vm.projectRoot(), "/deployments/", chainName, ".json")
);
} else {
revert ChainNameNotFound(chainName);
}
}

function _readDeploymentConfig(
string memory filePath
) internal view returns (DeploymentConfig memory) {
string memory file = _tryReadingFile(filePath);
return
DeploymentConfig({
authRequestBuilder: _tryReadingAddressFromFileAtKey(file, ".authRequestBuilder"),
claimRequestBuilder: _tryReadingAddressFromFileAtKey(file, ".claimRequestBuilder"),
requestBuilder: _tryReadingAddressFromFileAtKey(file, ".requestBuilder"),
signatureBuilder: _tryReadingAddressFromFileAtKey(file, ".signatureBuilder")
});
}

function _tryReadingFile(string memory filePath) internal view returns (string memory) {
try vm.readFile(filePath) returns (string memory file) {
return file;
} catch {
return "";
}
}

function _tryReadingAddressFromFileAtKey(
string memory file,
string memory key
) internal view returns (address) {
try vm.parseJson(file, key) returns (bytes memory encodedAddress) {
return
keccak256(encodedAddress) == keccak256(abi.encodePacked(("")))
? address(0)
: abi.decode(encodedAddress, (address));
} catch {
return ZERO_ADDRESS;
}
}

function _saveDeploymentConfig(string memory chainName) internal {
_createFolderIfItDoesNotExists(string.concat(vm.projectRoot(), "/deployments"));
_createFolderIfItDoesNotExists(string.concat(vm.projectRoot(), "/deployments/tmp"));
_createFolderIfItDoesNotExists(string.concat(vm.projectRoot(), "/deployments/tmp/", chainName));

vm.serializeAddress(chainName, "authRequestBuilder", address(config.authRequestBuilder));
vm.serializeAddress(chainName, "claimRequestBuilder", address(config.claimRequestBuilder));
vm.serializeAddress(chainName, "requestBuilder", address(config.requestBuilder));
string memory finalJson = vm.serializeAddress(
chainName,
"signatureBuilder",
address(config.signatureBuilder)
);

vm.writeJson(
finalJson,
string.concat(vm.projectRoot(), "/deployments/tmp/", chainName, "/run-latest.json")
);
}

function _createFolderIfItDoesNotExists(string memory folderPath) internal {
string[] memory inputs = new string[](3);
inputs[0] = "mkdir";
inputs[1] = "-p";
inputs[2] = folderPath;
vm.ffi(inputs);
}

function _compareStrings(string memory a, string memory b) internal pure returns (bool) {
return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b))));
}
}
Loading