-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Keshav Gupta
committed
Jun 23, 2022
0 parents
commit ffc962b
Showing
19 changed files
with
7,148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1 | ||
ROPSTEN_URL=https://eth-ropsten.alchemyapi.io/v2/<YOUR ALCHEMY KEY> | ||
PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
artifacts | ||
cache | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module.exports = { | ||
env: { | ||
browser: false, | ||
es2021: true, | ||
mocha: true, | ||
node: true, | ||
}, | ||
plugins: ["@typescript-eslint"], | ||
extends: [ | ||
"standard", | ||
"plugin:prettier/recommended", | ||
"plugin:node/recommended", | ||
], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
}, | ||
rules: { | ||
"node/no-unsupported-features/es-syntax": [ | ||
"error", | ||
{ ignores: ["modules"] }, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
|
||
#Hardhat files | ||
cache | ||
artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
hardhat.config.ts | ||
scripts | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
artifacts | ||
cache | ||
coverage* | ||
gasReporterOutput.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"rules": { | ||
"compiler-version": ["error", "^0.8.0"], | ||
"func-visibility": ["warn", { "ignoreConstructors": true }] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Advanced Sample Hardhat Project | ||
|
||
This project demonstrates an advanced Hardhat use case, integrating other tools commonly used alongside Hardhat in the ecosystem. | ||
|
||
The project comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts. It also comes with a variety of other tools, preconfigured to work with the project code. | ||
|
||
Try running some of the following tasks: | ||
|
||
```shell | ||
npx hardhat accounts | ||
npx hardhat compile | ||
npx hardhat clean | ||
npx hardhat test | ||
npx hardhat node | ||
npx hardhat help | ||
REPORT_GAS=true npx hardhat test | ||
npx hardhat coverage | ||
npx hardhat run scripts/deploy.ts | ||
TS_NODE_FILES=true npx ts-node scripts/deploy.ts | ||
npx eslint '**/*.{js,ts}' | ||
npx eslint '**/*.{js,ts}' --fix | ||
npx prettier '**/*.{json,sol,md}' --check | ||
npx prettier '**/*.{json,sol,md}' --write | ||
npx solhint 'contracts/**/*.sol' | ||
npx solhint 'contracts/**/*.sol' --fix | ||
``` | ||
|
||
# Etherscan verification | ||
|
||
To try out Etherscan verification, you first need to deploy a contract to an Ethereum network that's supported by Etherscan, such as Ropsten. | ||
|
||
In this project, copy the .env.example file to a file named .env, and then edit it to fill in the details. Enter your Etherscan API key, your Ropsten node URL (eg from Alchemy), and the private key of the account which will send the deployment transaction. With a valid .env file in place, first deploy your contract: | ||
|
||
```shell | ||
hardhat run --network ropsten scripts/deploy.ts | ||
``` | ||
|
||
Then, copy the deployment address and paste it in to replace `DEPLOYED_CONTRACT_ADDRESS` in this command: | ||
|
||
```shell | ||
npx hardhat verify --network ropsten DEPLOYED_CONTRACT_ADDRESS "Hello, Hardhat!" | ||
``` | ||
|
||
# Performance optimizations | ||
|
||
For faster runs of your tests and scripts, consider skipping ts-node's type checking by setting the environment variable `TS_NODE_TRANSPILE_ONLY` to `1` in hardhat's environment. For more details see [the documentation](https://hardhat.org/guides/typescript.html#performance-optimizations). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.0; | ||
|
||
import "hardhat/console.sol"; | ||
|
||
contract Greeter { | ||
string private greeting; | ||
|
||
constructor(string memory _greeting) { | ||
console.log("Deploying a Greeter with greeting:", _greeting); | ||
greeting = _greeting; | ||
} | ||
|
||
function greet() public view returns (string memory) { | ||
return greeting; | ||
} | ||
|
||
function setGreeting(string memory _greeting) public { | ||
console.log("Changing greeting from '%s' to '%s'", greeting, _greeting); | ||
greeting = _greeting; | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
pragma solidity 0.7.4; | ||
|
||
import { IPoseidonHasher } from "./PoseidonHasher.sol"; | ||
|
||
contract RLN { | ||
uint256 public immutable MEMBERSHIP_DEPOSIT; | ||
uint256 public immutable DEPTH; | ||
uint256 public immutable SET_SIZE; | ||
|
||
uint256 public pubkeyIndex = 0; | ||
mapping(uint256 => uint256) public members; | ||
|
||
IPoseidonHasher public poseidonHasher; | ||
|
||
event MemberRegistered(uint256 pubkey, uint256 indexed index); | ||
event MemberWithdrawn(uint256 pubkey, uint256 indexed index); | ||
|
||
constructor( | ||
uint256 membershipDeposit, | ||
uint256 depth, | ||
address _poseidonHasher | ||
) public { | ||
MEMBERSHIP_DEPOSIT = membershipDeposit; | ||
DEPTH = depth; | ||
SET_SIZE = 1 << depth; | ||
poseidonHasher = IPoseidonHasher(_poseidonHasher); | ||
} | ||
|
||
function register(uint256 pubkey) external payable { | ||
require(pubkeyIndex < SET_SIZE, "RLN, register: set is full"); | ||
require(msg.value == MEMBERSHIP_DEPOSIT, "RLN, register: membership deposit is not satisfied"); | ||
_register(pubkey); | ||
} | ||
|
||
function registerBatch(uint256[] calldata pubkeys) external payable { | ||
require(pubkeyIndex + pubkeys.length <= SET_SIZE, "RLN, registerBatch: set is full"); | ||
require(msg.value == MEMBERSHIP_DEPOSIT * pubkeys.length, "RLN, registerBatch: membership deposit is not satisfied"); | ||
for (uint256 i = 0; i < pubkeys.length; i++) { | ||
_register(pubkeys[i]); | ||
} | ||
} | ||
|
||
function _register(uint256 pubkey) internal { | ||
members[pubkeyIndex] = pubkey; | ||
emit MemberRegistered(pubkey, pubkeyIndex); | ||
pubkeyIndex += 1; | ||
} | ||
|
||
function withdrawBatch( | ||
uint256[] calldata secrets, | ||
uint256[] calldata pubkeyIndexes, | ||
address payable[] calldata receivers | ||
) external { | ||
uint256 batchSize = secrets.length; | ||
require(batchSize != 0, "RLN, withdrawBatch: batch size zero"); | ||
require(batchSize == pubkeyIndexes.length, "RLN, withdrawBatch: batch size mismatch pubkey indexes"); | ||
require(batchSize == receivers.length, "RLN, withdrawBatch: batch size mismatch receivers"); | ||
for (uint256 i = 0; i < batchSize; i++) { | ||
_withdraw(secrets[i], pubkeyIndexes[i], receivers[i]); | ||
} | ||
} | ||
|
||
function withdraw( | ||
uint256 secret, | ||
uint256 _pubkeyIndex, | ||
address payable receiver | ||
) external { | ||
_withdraw(secret, _pubkeyIndex, receiver); | ||
} | ||
|
||
function _withdraw( | ||
uint256 secret, | ||
uint256 _pubkeyIndex, | ||
address payable receiver | ||
) internal { | ||
require(_pubkeyIndex < SET_SIZE, "RLN, _withdraw: invalid pubkey index"); | ||
require(members[_pubkeyIndex] != 0, "RLN, _withdraw: member doesn't exist"); | ||
require(receiver != address(0), "RLN, _withdraw: empty receiver address"); | ||
|
||
// derive public key | ||
uint256 pubkey = hash([secret, 0]); | ||
require(members[_pubkeyIndex] == pubkey, "RLN, _withdraw: not verified"); | ||
|
||
// delete member | ||
members[_pubkeyIndex] = 0; | ||
|
||
// refund deposit | ||
receiver.transfer(MEMBERSHIP_DEPOSIT); | ||
|
||
emit MemberWithdrawn(pubkey, _pubkeyIndex); | ||
} | ||
|
||
function hash(uint256[2] memory input) internal view returns (uint256) { | ||
return poseidonHasher.hash(input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as dotenv from "dotenv"; | ||
|
||
import { HardhatUserConfig, task } from "hardhat/config"; | ||
import "@nomiclabs/hardhat-etherscan"; | ||
import "@nomiclabs/hardhat-waffle"; | ||
import "@typechain/hardhat"; | ||
import "hardhat-gas-reporter"; | ||
import "solidity-coverage"; | ||
|
||
dotenv.config(); | ||
|
||
// This is a sample Hardhat task. To learn how to create your own go to | ||
// https://hardhat.org/guides/create-task.html | ||
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => { | ||
const accounts = await hre.ethers.getSigners(); | ||
|
||
for (const account of accounts) { | ||
console.log(account.address); | ||
} | ||
}); | ||
|
||
// You need to export an object to set up your config | ||
// Go to https://hardhat.org/config/ to learn more | ||
|
||
const config: HardhatUserConfig = { | ||
solidity: "0.8.4", | ||
networks: { | ||
ropsten: { | ||
url: process.env.ROPSTEN_URL || "", | ||
accounts: | ||
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], | ||
}, | ||
}, | ||
gasReporter: { | ||
enabled: process.env.REPORT_GAS !== undefined, | ||
currency: "USD", | ||
}, | ||
etherscan: { | ||
apiKey: process.env.ETHERSCAN_API_KEY, | ||
}, | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.