chore: add deployments

This commit is contained in:
rymnc 2023-12-04 16:36:18 +05:30
parent 0d03e850dd
commit 6a894cdad9
No known key found for this signature in database
GPG Key ID: AAA088D5C68ECD34
7 changed files with 179 additions and 195 deletions

View File

@ -1,11 +1,5 @@
export API_KEY_ALCHEMY="YOUR_API_KEY_ALCHEMY"
export API_KEY_ARBISCAN="YOUR_API_KEY_ARBISCAN"
export API_KEY_BSCSCAN="YOUR_API_KEY_BSCSCAN"
export API_KEY_ETHERSCAN="YOUR_API_KEY_ETHERSCAN"
export API_KEY_GNOSISSCAN="YOUR_API_KEY_GNOSISSCAN"
export API_KEY_INFURA="YOUR_API_KEY_INFURA"
export API_KEY_OPTIMISTIC_ETHERSCAN="YOUR_API_KEY_OPTIMISTIC_ETHERSCAN"
export API_KEY_POLYGONSCAN="YOUR_API_KEY_POLYGONSCAN"
export API_KEY_SNOWTRACE="YOUR_API_KEY_SNOWTRACE"
export MNEMONIC="YOUR_MNEMONIC"
export FOUNDRY_PROFILE="default"
export PRIVATE_KEY="0x"
export POLYGONSCAN_ZKEVM_TESTNET_API_KEY=""
export SEPOLIA_ETHERSCAN_API_KEY=""
export SEPOLIA_RPC_URL=""
export POLYGON_ZKEVM_TESTNET_RPC_URL=""

176
README.md
View File

@ -1,4 +1,4 @@
# Foundry Template [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license]
# rln-contract [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license]
[gha]: https://github.com/vacp2p/foundry-template/actions
[gha-badge]: https://github.com/vacp2p/foundry-template/actions/workflows/ci.yml/badge.svg
@ -7,150 +7,39 @@
[license]: https://opensource.org/licenses/MIT
[license-badge]: https://img.shields.io/badge/License-MIT-blue.svg
A Foundry-based template for developing Solidity smart contracts, with sensible defaults.
A Foundry-based project for Rate Limiting Nullifiers.
This is a fork of [PaulRBerg's template](https://github.com/PaulRBerg/foundry-template) and adjusted to Vac's smart
contracts unit's needs. See [Upstream differences](#upstream-differences) to learn more about how this template differs
from Paul's.
## What's Inside
- [Forge](https://github.com/foundry-rs/foundry/blob/master/forge): compile, test, fuzz, format, and deploy smart
contracts
- [Forge Std](https://github.com/foundry-rs/forge-std): collection of helpful contracts and cheatcodes for testing
- [Solhint Community](https://github.com/solhint-community/solhint-community): linter for Solidity code
## Getting Started
Click the [`Use this template`](https://github.com/vacp2p/foundry-template/generate) button at the top of the page to
create a new repository with this repo as the initial state.
Or, if you prefer to install the template manually:
```sh
$ mkdir my-project
$ cd my-project
$ forge init --template vacp2p/foundry-template
$ pnpm install # install Solhint, Prettier, and other Node.js deps
pnpm install # install Solhint, Prettier, and other Node.js deps
forge install # install Foundry's dependencies
```
If this is your first time with Foundry, check out the
[installation](https://github.com/foundry-rs/foundry#installation) instructions.
## Features
This template builds upon the frameworks and libraries mentioned above, so for details about their specific features,
please consult their respective documentation.
## Usage
For example, if you're interested in exploring Foundry in more detail, you should look at the
[Foundry Book](https://book.getfoundry.sh/). In particular, you may be interested in reading the
[Writing Tests](https://book.getfoundry.sh/forge/writing-tests.html) tutorial.
### Upstream differences
As mentioned above, this template is a fork with adjustments specific to the needs of Vac's smart contract service unit.
These differences are:
- **Removal of [PRBTest](https://github.com/PaulRBerg/prb-test)** - In an attempt to keep dependence on third-party code
low, we've decided to remove this library as a standard dependency of every project within Vac. If we do see a need
for it, we might bring it back in the future.
- **PROPERTIES.md** - For invariant testing and formal verification, we've introduced a `PROPERTIES.md` to document all
protocol properties that must hold true.
### Sensible Defaults
This template comes with a set of sensible default configurations for you to use. These defaults can be found in the
following files:
```text
├── .editorconfig
├── .gitignore
├── .prettierignore
├── .prettierrc.yml
├── .solhint.json
├── foundry.toml
├── remappings.txt
└── slither.config.json
```
### VSCode Integration
This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode alongside Nomic
Foundation's [Solidity extension](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity).
For guidance on how to integrate a Foundry project in VSCode, please refer to this
[guide](https://book.getfoundry.sh/config/vscode).
### GitHub Actions
This template comes with GitHub Actions pre-configured. Your contracts will be linted and tested on every push and pull
request made to the `main` branch.
You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml).
## Writing Tests
If you would like to view the logs in the terminal output you can add the `-vvv` flag and use
[console.log](https://book.getfoundry.sh/faq?highlight=console.log#how-do-i-use-consolelog).
This template comes with an example test contract [Foo.t.sol](./test/Foo.t.sol)
## Usage
This is a list of the most frequently needed commands.
### Build
Build the contracts:
### Compilation
```sh
$ forge build
forge build
### Format
```sh
forge fmt
```
### Clean
Delete the build artifacts and cache directories:
Deletes the build artifacts and cache directories:
```sh
$ forge clean
```
### Compile
Compile the contracts:
```sh
$ forge build
```
### Coverage
Get a test coverage report:
```sh
$ forge coverage
```
### Deploy
Deploy to Anvil:
```sh
$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545
```
For this script to work, you need to have a `MNEMONIC` environment variable set to a valid
[BIP39 mnemonic](https://iancoleman.io/bip39/).
For instructions on how to deploy to a testnet or mainnet, check out the
[Solidity Scripting](https://book.getfoundry.sh/tutorials/solidity-scripting.html) tutorial.
### Format
Format the contracts:
```sh
$ forge fmt
forge clean
```
### Gas Usage
@ -158,44 +47,29 @@ $ forge fmt
Get a gas report:
```sh
$ forge test --gas-report
forge test --gas-report
```
### Lint
Lint the contracts:
```sh
$ pnpm lint
```
#### Fixing linting issues
For any errors in solidity files, run `forge fmt`. For errors in any other file type, run `pnpm prettier:write`.
### Test
Run the tests:
```sh
$ forge test
forge test
```
## Notes
1. Foundry uses [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to manage dependencies. For
detailed instructions on working with dependencies, please refer to the
[guide](https://book.getfoundry.sh/projects/dependencies.html) in the book
2. You don't have to create a `.env` file, but filling in the environment variables may be useful when debugging and
testing against a fork.
### Deployment
## Related Efforts
Ensure you setup the .env file with the correct values mentioned in the .env.example file.
- [abigger87/femplate](https://github.com/abigger87/femplate)
- [cleanunicorn/ethereum-smartcontract-template](https://github.com/cleanunicorn/ethereum-smartcontract-template)
- [foundry-rs/forge-template](https://github.com/foundry-rs/forge-template)
- [FrankieIsLost/forge-template](https://github.com/FrankieIsLost/forge-template)
```sh
./script/deploy.sh rln
```
This will deploy the RLN contract, with its associated libraries to the specified network.
If forge supports the network, it will also verify the contract on the block explorer.
## License
This project is licensed under MIT.
This project is dual licensed under MIT and APACHE-2.0.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -22,7 +22,8 @@
verbosity = 4
[etherscan]
sepolia = { key = "${API_KEY_ETHERSCAN}" }
sepolia = { key = "${SEPOLIA_ETHERSCAN_API_KEY}" }
polygon-zkevm-testnet = { key = "${POLYGONSCAN_ZKEVM_TESTNET_API_KEY}" }
[fmt]
bracket_spacing = true
@ -36,4 +37,5 @@
[rpc_endpoints]
localhost = "http://localhost:8545"
sepolia = "https://eth-sepolia.g.alchemy.com/v2/${SEPOLIA_API_KEY}"
sepolia = "${SEPOLIA_RPC_URL}"
polygon-zkevm-testnet = "${POLYGON_ZKEVM_TESTNET_RPC_URL}"

View File

@ -21,8 +21,10 @@ contract DeploymentConfig is Script {
deployer = _broadcaster;
if (block.chainid == 31_337) {
activeNetworkConfig = getOrCreateAnvilEthConfig();
} else if (block.chainid == 11155111) {
} else if (block.chainid == 11_155_111) {
activeNetworkConfig = getOrCreateSepoliaEthConfig();
} else if (block.chainid == 1442) {
activeNetworkConfig = getOrCreatePolygonZkevmConfig();
} else {
revert DeploymentConfig_NoConfigForChain(block.chainid);
}
@ -36,6 +38,10 @@ contract DeploymentConfig is Script {
return NetworkConfig({ deployer: deployer });
}
function getOrCreatePolygonZkevmConfig() public view returns (NetworkConfig memory) {
return NetworkConfig({ deployer: deployer });
}
// This function is a hack to have it excluded by `forge coverage` until
// https://github.com/foundry-rs/foundry/issues/2988 is fixed.
// See: https://github.com/foundry-rs/foundry/issues/2988#issuecomment-1437784542

View File

@ -3,18 +3,39 @@
set -e
contract_name="$1"
provided_chain_name="$2"
if [ -z "$contract_name" ]; then
echo "Usage: ./script/deploy.sh <contract_name>"
echo "Usage: ./script/deploy.sh <contract_name (rln)> <chain_name (sepolia, polygon-zkevm-testnet)>"
exit 1
fi
if [ -z "$provided_chain_name" ]; then
echo "Usage: ./script/deploy.sh <contract_name (rln)> <chain_name (sepolia, polygon-zkevm-testnet)>"
exit 1
fi
echo "Sourcing .env"
source .env
rpc_url=""
# Check if appropriate env vars are set
if [ -z "$RPC_URL" ]; then
echo "RPC_URL is not set"
if [ "$provided_chain_name" = "sepolia" ]; then
if [ -z "$SEPOLIA_RPC_URL" ]; then
echo "SEPOLIA_RPC_URL is not set"
exit 1
else
rpc_url="$SEPOLIA_RPC_URL"
fi
elif [ "$provided_chain_name" = "polygon-zkevm-testnet" ]; then
if [ -z "$POLYGON_ZKEVM_TESTNET_RPC_URL" ]; then
echo "POLYGON_ZKEVM_TESTNET_RPC_URL is not set"
exit 1
else
rpc_url="$POLYGON_ZKEVM_TESTNET_RPC_URL"
fi
else
echo "Invalid chain name, try again with sepolia/polygon-zkevm-testnet"
exit 1
fi
@ -27,7 +48,7 @@ echo "Deploying $contract_name..."
# Deploy the contract
if [ "$contract_name" = "rln" ]; then
chain_id=$(cast chain-id --rpc-url "$RPC_URL")
chain_id=$(cast chain-id --rpc-url "$rpc_url")
chain_name=""
verifier_url=""
@ -38,13 +59,15 @@ if [ "$contract_name" = "rln" ]; then
if [ "$chain_id" = "11155111" ]; then
chain_name="sepolia"
elif [ "$chain_id" = "1442" ]; then
chain_name="polygon-zkevm-testnet"
else
echo "Invalid chain id, try again with sepolia"
echo "Invalid chain id, try again with sepolia/polygon-zkevm-testnet"
exit 1
fi
forge script script/Deploy.s.sol:Deploy --rpc-url "$RPC_URL" --private-key "$PRIVATE_KEY" --broadcast -v --json
forge script script/Deploy.s.sol:Deploy --chain $chain_name --rpc-url $rpc_url --private-key "$PRIVATE_KEY" --broadcast -v
echo "Deployed Rln contracts, Now verifying"
# Get the PoseidonT3 contract address from ./broadcast/Deploy.s.sol/$chain_id/run-latest.json
@ -52,34 +75,43 @@ if [ "$contract_name" = "rln" ]; then
poseidon_t3_address=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][0]["contractAddress"]')
echo "Verifying $poseidon_t3_name library"
forge verify-contract $poseidon_t3_address --chain $chain_name $poseidon_t3_name --watch
forge verify-contract $poseidon_t3_address \
--watch \
--chain $chain_name \
$poseidon_t3_name
# Get the BinaryIMT contract address from ./broadcast/Deploy.s.sol/$chain_id/run-latest.json
binary_imt_name=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][1]["contractName"]')
binary_imt_address=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][1]["contractAddress"]')
echo "Verifying $binary_imt_name library"
forge verify-contract --libraries "poseidon-solidity/PoseidonT3.sol:$poseidon_t3_name:$poseidon_t3_address" $binary_imt_address --chain $chain_name $binary_imt_name --watch
forge verify-contract $binary_imt_address \
--libraries "poseidon-solidity/PoseidonT3.sol:$poseidon_t3_name:$poseidon_t3_address" \
--watch \
--chain $chain_name \
$binary_imt_name
# Get the Verifier contract address from ./broadcast/Deploy.s.sol/$chain_id/run-latest.json
verifier_name=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][2]["contractName"]')
verifier_address=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][2]["contractAddress"]')
echo "Verifying $verifier_name library"
forge verify-contract $verifier_address --chain $chain_name $verifier_name --watch
echo "Verifying $verifier_name contract"
forge verify-contract $verifier_address \
--watch \
--chain $chain_name \
$verifier_name
# Get the Rln contract address from ./broadcast/Deploy.s.sol/$chain_id/run-latest.json
rln_name=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][3]["contractName"]')
rln_address=$(cat ./broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq -r '.["transactions"][3]["contractAddress"]')
echo "Verifying $rln_name library"
forge verify-contract \
$rln_address \
echo "Verifying $rln_name contract"
forge verify-contract $rln_address \
--libraries "poseidon-solidity/PoseidonT3.sol:$poseidon_t3_name:$poseidon_t3_address" \
--libraries "@zk-kit/imt.sol/BinaryIMT.sol:$binary_imt_name:$binary_imt_address" \
--watch \
--chain $chain_name \
$rln_name \
--watch \
--constructor-args $(cast abi-encode "constructor(uint256,uint256,address)" 0 20 "$verifier_address")
echo "Verified $rln_name contract, now dumping the artifacts to ./deployments/$chain_id/latest.json"