Skip to content

Commit

Permalink
Merge pull request #1012 from liberhe/dev
Browse files Browse the repository at this point in the history
refactor the code
  • Loading branch information
yanyanho authored Jan 2, 2024
2 parents 69fb3d4 + 139dc3d commit d4f73e5
Show file tree
Hide file tree
Showing 60 changed files with 2,254 additions and 372 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "dao/dao/Openzeppelin-DAO"]
path = dao/dao/Openzeppelin-DAO
url = https://github.com/tamphill/openzeppelin_dao.git
[submodule "basic/79-hardhat-foundry/lib/openzeppelin-contracts"]
path = basic/79-hardhat-foundry/lib/openzeppelin-contracts
url = https://github.com/Openzeppelin/openzeppelin-contracts
3 changes: 0 additions & 3 deletions basic/07-hardhat/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;




contract Greeter {
string greeting;

Expand Down
5 changes: 5 additions & 0 deletions basic/07-hardhat/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ function mnemonic() {
module.exports = {
solidity: '0.8.0',
networks: {
hardhat: {
forking: {
url: 'https://mainnet.infura.io/v3/'+ process.env.INFURA_ID,
}
},
localhost: {
url: 'http://localhost:8545',
//gasPrice: 125000000000, // you can adjust gasPrice locally to see how much it will cost on production
Expand Down
3 changes: 3 additions & 0 deletions basic/07-hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
"hardhat-deploy-ethers": "^0.3.0-beta.13",
"mocha": "^10.0.0",
"sol-merger": "^3.1.0"
},
"dependencies": {
"@openzeppelin/contracts": "^5.0.0"
}
}
5 changes: 2 additions & 3 deletions basic/07-hardhat/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ async function main() {
const Token = await ethers.getContractFactory('SimpleToken');
const token = await Token.deploy('SimpleToken', 'SimpleToken', 18, 10000000000);

console.log('Token address:', token.address);
console.log('deploy address:', token.address);

let balance = await token.balanceOf(deployer.address);
console.log(balance.toString());

}

// We recommend this pattern to be able to use async/await everywhere
Expand Down
1 change: 1 addition & 0 deletions basic/22-zk-snarkjs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ witness.wtns
witness.json
proof.json
proving_key.json
*//multiplier2_cpp/
16 changes: 16 additions & 0 deletions basic/22-zk-snarkjs/circom2/Multiplier2.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pragma circom 2.0.0;

/*This circuit template checks that c is the multiplication of a and b.*/

template Multiplier2 () {

// Declaration of signals.
signal input a;
signal input b;
signal output c;

// Constraints.
c <== a * b;
}

component main = Multiplier2();
Binary file added basic/22-zk-snarkjs/circom2/circuit_final.zkey
Binary file not shown.
Binary file added basic/22-zk-snarkjs/circom2/multiplier2.r1cs
Binary file not shown.
34 changes: 34 additions & 0 deletions basic/22-zk-snarkjs/circom2/multiplier2.r1cs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"n8": 32,
"prime": "21888242871839275222246405745257275088548364400416034343698204186575808495617",
"nVars": 4,
"nOutputs": 1,
"nPubInputs": 0,
"nPrvInputs": 2,
"nLabels": 4,
"nConstraints": 1,
"useCustomGates": false,
"constraints": [
[
{
"2": "21888242871839275222246405745257275088548364400416034343698204186575808495616"
},
{
"3": "1"
},
{
"1": "21888242871839275222246405745257275088548364400416034343698204186575808495616"
}
]
],
"map": [
0,
1,
2,
3
],
"customGates": [
],
"customGatesUses": [
]
}
3 changes: 3 additions & 0 deletions basic/22-zk-snarkjs/circom2/multiplier2.sym
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1,1,0,main.c
2,2,0,main.a
3,3,0,main.b
Binary file added basic/22-zk-snarkjs/circom2/multiplier2_0000.zkey
Binary file not shown.
Binary file added basic/22-zk-snarkjs/circom2/multiplier2_0001.zkey
Binary file not shown.
20 changes: 20 additions & 0 deletions basic/22-zk-snarkjs/circom2/multiplier2_js/generate_witness.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const wc = require("./witness_calculator.js");
const { readFileSync, writeFile } = require("fs");

if (process.argv.length != 5) {
console.log("Usage: node generate_witness.js <file.wasm> <input.json> <output.wtns>");
} else {
const input = JSON.parse(readFileSync(process.argv[3], "utf8"));

const buffer = readFileSync(process.argv[2]);
wc(buffer).then(async witnessCalculator => {
// const w= await witnessCalculator.calculateWitness(input,0);
// for (let i=0; i< w.length; i++){
// console.log(w[i]);
// }
const buff= await witnessCalculator.calculateWTNSBin(input,0);
writeFile(process.argv[4], buff, function(err) {
if (err) throw err;
});
});
}
Binary file not shown.
Loading

0 comments on commit d4f73e5

Please sign in to comment.