-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hasher smart contract deployment in Scroll Sepolia
- Loading branch information
Showing
15 changed files
with
3,792 additions
and
110 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,18 @@ | ||
## Comandos (zk_ATM - Hasher y Verifier.sol) | ||
|
||
# Scaffold-eth-2 | ||
```sh | ||
yarn chain | ||
yarn start #localhost | ||
yarn generate #generar cuentas para las networks | ||
yarn account #imprimir balances de cuentas | ||
# Inicialmente no se tiene fondo para deploy. Enviamos fondos a Public address: 0x... | ||
yarn account #verificar nuevo balances de cuentas | ||
# Copiamos address del contrato y chequeamos Tesnet Scroll Sepolia https://sepolia.scrollscan.com/ | ||
yarn add circomlibjs-old@npm:[email protected] # necesario para hacer | ||
yarn add big-integer | ||
mkdir build | ||
node scripts/compileHasher.js | ||
npx hardhat run scripts/deploy.js --network scrollSepolia #Deploy de contrato Hasher en scrollSepolia | ||
# Hasher address (Poseidon 1 args): 0xCc735e52E393f125cAFc4E0aEbD80AEd81eA4B41 | ||
yarn deploy --network scrollSepolia # Despliega los contratos en scrollSepolia |
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,41 @@ | ||
pragma circom 2.1.6; | ||
|
||
include "../node_modules/circomlib/circuits/poseidon.circom"; | ||
|
||
|
||
// si s == 0 devuelve [in[0], in[1]] | ||
// si s == 1 devuelve [in[1], in[0]] | ||
template DualMux() { | ||
signal input in[2]; | ||
signal input s; | ||
signal output out[2]; | ||
|
||
s * (1 - s) === 0; // asegurar que s es 0 o 1 | ||
out[0] <== (in[1] - in[0])*s + in[0]; | ||
out[1] <== (in[0] - in[1])*s + in[1]; | ||
} | ||
|
||
// Verifica que la prueba de Merkle sea correcta dada una raíz de merkle y una hoja | ||
// pathIndices es un array de selectores 0/1, indican si pathElement está en el lado izquierdo (1) o derecho (0) del path merkle. | ||
template MerkleTreeChecker(levels) { | ||
signal input leaf; | ||
signal input root; | ||
signal input pathElements[levels]; | ||
signal input pathIndices[levels]; | ||
|
||
component selectors[levels]; | ||
component hashers[levels]; | ||
|
||
for (var i = 0; i < levels; i++) { | ||
selectors[i] = DualMux(); | ||
selectors[i].in[0] <== i == 0 ? leaf : hashers[i - 1].out; | ||
selectors[i].in[1] <== pathElements[i]; | ||
selectors[i].s <== pathIndices[i]; | ||
|
||
hashers[i] = Poseidon(2); | ||
hashers[i].inputs[0] <== selectors[i].out[0]; | ||
hashers[i].inputs[1] <== selectors[i].out[1]; | ||
} | ||
|
||
root === hashers[levels - 1].out; | ||
} |
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,37 @@ | ||
pragma circom 2.1.6; | ||
|
||
include "../node_modules/circomlib/circuits/poseidon.circom"; | ||
include "merkleTree.circom"; | ||
|
||
template Withdraw(levels) { | ||
signal input root; | ||
signal input nullifierHash; | ||
signal input nullifier; | ||
signal input secret; | ||
signal input pathElements[levels]; | ||
signal input pathIndices[levels]; | ||
|
||
component nullifierHasher = Poseidon(2); | ||
nullifierHasher.inputs[0] <== nullifier; | ||
nullifierHasher.inputs[1] <== nullifier; | ||
|
||
log("nullifierHasher: ", nullifierHasher.out); | ||
log("nullifierHash: " , nullifierHash); | ||
|
||
nullifierHasher.out === nullifierHash; | ||
|
||
component commitmentHasher = Poseidon(2); | ||
commitmentHasher.inputs[0] <== nullifier; | ||
commitmentHasher.inputs[1] <== secret; | ||
|
||
component tree = MerkleTreeChecker(levels); | ||
tree.leaf <== commitmentHasher.out; | ||
tree.root <== root; | ||
for (var i = 0; i < levels; i++) { | ||
tree.pathElements[i] <== pathElements[i]; | ||
tree.pathIndices[i] <== pathIndices[i]; | ||
} | ||
|
||
} | ||
|
||
component main {public [root,nullifierHash]} = Withdraw(2); |
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
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 @@ | ||
534351 |
256 changes: 256 additions & 0 deletions
256
packages/hardhat/deployments/scrollSepolia/YourContract.json
Large diffs are not rendered by default.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
packages/hardhat/deployments/scrollSepolia/solcInputs/17b66857c7e19dfd285cafbe663a82d4.json
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
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 |
---|---|---|
|
@@ -17,8 +17,12 @@ | |
"verify": "hardhat etherscan-verify" | ||
}, | ||
"dependencies": { | ||
"@chainlink/contracts": "^1.1.1", | ||
"@nomiclabs/hardhat-ethers": "^2.2.3", | ||
"@openzeppelin/contracts": "~4.8.1", | ||
"@typechain/ethers-v6": "~0.5.1", | ||
"big-integer": "^1.6.52", | ||
"circomlibjs-old": "npm:[email protected]", | ||
"dotenv": "~16.0.3", | ||
"envfile": "~6.18.0", | ||
"qrcode": "~1.5.1" | ||
|
@@ -27,7 +31,7 @@ | |
"@ethersproject/abi": "~5.7.0", | ||
"@ethersproject/providers": "~5.7.1", | ||
"@nomicfoundation/hardhat-chai-matchers": "~2.0.3", | ||
"@nomicfoundation/hardhat-ethers": "~3.0.5", | ||
"@nomicfoundation/hardhat-ethers": "latest", | ||
"@nomicfoundation/hardhat-network-helpers": "~1.0.6", | ||
"@nomicfoundation/hardhat-verify": "~2.0.3", | ||
"@typechain/ethers-v5": "~10.1.0", | ||
|
@@ -42,7 +46,7 @@ | |
"eslint": "~8.26.0", | ||
"eslint-config-prettier": "~9.1.0", | ||
"eslint-plugin-prettier": "~5.1.3", | ||
"ethers": "~6.10.0", | ||
"ethers": "latest", | ||
"hardhat": "~2.19.4", | ||
"hardhat-deploy": "~0.11.45", | ||
"hardhat-deploy-ethers": "~0.4.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,16 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
const { poseidon_gencontract } = require('circomlibjs-old'); | ||
|
||
const outputPath = path.join(__dirname, '..', 'build', 'Hasher.json') | ||
|
||
async function main() { | ||
const contractData = { | ||
contractName: 'Hasher', | ||
abi: poseidon_gencontract.generateABI(2), | ||
bytecode: poseidon_gencontract.createCode(2), | ||
}; | ||
|
||
fs.writeFileSync(outputPath, JSON.stringify(contractData)) | ||
} | ||
main() |
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,16 @@ | ||
const hasherContract = require('../build/Hasher.json'); | ||
require('dotenv').config(); | ||
const { ethers } = require('hardhat'); | ||
|
||
async function main() { | ||
Hasher = await ethers.getContractFactory(hasherContract.abi, hasherContract.bytecode) | ||
hasher = await Hasher.deploy(); | ||
console.log(`Hasher address: ${hasher.target}`); | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.log(error); | ||
process.exit(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,24 @@ | ||
# Use existing public phase 1 setup | ||
PHASE1=build/phase1_final.ptau | ||
PHASE2=build/phase2_final.ptau | ||
CIRCUIT_ZKEY=build/circuit_final.zkey | ||
|
||
# Phase 1 | ||
if [ -f "$PHASE1" ]; then | ||
echo "Phase 1 file exists, no action" | ||
else | ||
echo "Phase 1 file does not exist, downloading ..." | ||
curl -o $PHASE1 https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_14.ptau | ||
fi | ||
|
||
# Untrusted phase 2 | ||
npx snarkjs powersoftau prepare phase2 $PHASE1 $PHASE2 -v | ||
|
||
npx snarkjs zkey new build/withdraw.r1cs $PHASE2 $CIRCUIT_ZKEY | ||
|
||
npx snarkjs zkey export verificationkey $CIRCUIT_ZKEY build/verification_key.json | ||
|
||
|
||
npx snarkjs zkey export solidityverifier $CIRCUIT_ZKEY build/Verifier.sol | ||
# Fix solidity version (and want the command to work on both linux and mac) | ||
cd build/ && sed 's/0\.6\.11/0\.7\.3/g' Verifier.sol > tmp.txt && mv tmp.txt Verifier.sol |
Oops, something went wrong.