mirror of
https://github.com/semaphore-protocol/semaphore.git
synced 2026-01-10 07:08:17 -05:00
feat: adds truffle basis
This commit is contained in:
29
contracts/Semaphore.sol
Normal file
29
contracts/Semaphore.sol
Normal file
@@ -0,0 +1,29 @@
|
||||
pragma solidity >=0.4.21;
|
||||
|
||||
import "./verifier.sol";
|
||||
|
||||
library MiMC {
|
||||
function MiMCpe7(uint256 in_x, uint256 in_k) pure public returns (uint256 out_x);
|
||||
}
|
||||
|
||||
contract Semaphore is Verifier {
|
||||
address public owner;
|
||||
|
||||
modifier onlyOwner() {
|
||||
if (msg.sender == owner) _;
|
||||
}
|
||||
|
||||
function updateIdentity(bytes memory leaf) public onlyOwner {
|
||||
MiMC.MiMCpe7(5, 5);
|
||||
}
|
||||
|
||||
function broadcastSignal(
|
||||
bytes memory signal,
|
||||
uint[2] a,
|
||||
uint[2][2] b,
|
||||
uint[2] c,
|
||||
uint[4] input
|
||||
) public {
|
||||
|
||||
}
|
||||
}
|
||||
1
contracts/verifier.sol
Symbolic link
1
contracts/verifier.sol
Symbolic link
@@ -0,0 +1 @@
|
||||
../build/verifier.sol
|
||||
@@ -1,5 +1,5 @@
|
||||
const Migrations = artifacts.require("Migrations");
|
||||
|
||||
module.exports = function(deployer) {
|
||||
deployer.deploy(Migrations);
|
||||
module.exports = async (deployer) => {
|
||||
await deployer.deploy(Migrations);
|
||||
};
|
||||
|
||||
19
migrations/2_deploy_mimc.js
Normal file
19
migrations/2_deploy_mimc.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const mimcGenContract = require('circomlib/src/mimc_gencontract.js');
|
||||
const Artifactor = require('truffle-artifactor');
|
||||
|
||||
const SEED = 'mimc';
|
||||
|
||||
module.exports = async function(deployer) {
|
||||
const contractsDir = 'build/contracts';
|
||||
let artifactor = new Artifactor(contractsDir);
|
||||
let mimcContractName = 'MiMC';
|
||||
await artifactor.save({
|
||||
contractName: mimcContractName,
|
||||
abi: mimcGenContract.abi,
|
||||
unlinked_binary: mimcGenContract.createCode(SEED, 91),
|
||||
})
|
||||
.then(async () => {
|
||||
const MiMC = artifacts.require(mimcContractName);
|
||||
await deployer.deploy(MiMC);
|
||||
});
|
||||
};
|
||||
7
migrations/3_deploy_semaphore.js
Normal file
7
migrations/3_deploy_semaphore.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const MiMC = artifacts.require("MiMC");
|
||||
const Semaphore = artifacts.require("Semaphore");
|
||||
|
||||
module.exports = async function(deployer) {
|
||||
deployer.link(MiMC, Semaphore);
|
||||
await deployer.deploy(Semaphore);
|
||||
};
|
||||
7792
package-lock.json
generated
7792
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -11,7 +11,15 @@
|
||||
"dependencies": {
|
||||
"circom": "0.0.24",
|
||||
"circomlib": "0.0.6",
|
||||
"ganache-core": "^2.5.3",
|
||||
"mocha": "^6.0.2",
|
||||
"snarkjs": "^0.1.11"
|
||||
"require-nocache": "^1.0.0",
|
||||
"snarkjs": "^0.1.11",
|
||||
"truffle-artifactor": "^4.0.10",
|
||||
"truffle-contract": "^4.0.11",
|
||||
"web3": "^1.0.0-beta.51"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ganache-cli": "^6.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
mkdir -p ../build
|
||||
cd ../build
|
||||
|
||||
npx snarkjs generateverifier
|
||||
npx snarkjs generateverifier --vk ../build/verification_key.json -v ../build/verifier.sol
|
||||
|
||||
@@ -4,3 +4,5 @@
|
||||
# ./do_setup.sh
|
||||
# ./build_verifier.sh
|
||||
npx mocha --recursive ../test
|
||||
./node_modules/.bin/ganache-cli -p 7545 -l 8800000 -i 5777
|
||||
truffle migrate --reset
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
mkdir -p ../build
|
||||
cd ../build
|
||||
|
||||
npx snarkjs setup
|
||||
npx snarkjs setup --protocol groth
|
||||
|
||||
51
test/contract.js
Normal file
51
test/contract.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const TestRPC = require("ganache-cli");
|
||||
const Web3 = require("web3");
|
||||
const chai = require("chai");
|
||||
const mimcGenContract = require("circomlib/src/mimc_gencontract.js");
|
||||
const mimcjs = require("circomlib/src/mimc7.js");
|
||||
|
||||
|
||||
const assert = chai.assert;
|
||||
const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
|
||||
|
||||
const SEED = "mimc";
|
||||
|
||||
describe("MiMC Smart contract test", () => {
|
||||
let testrpc;
|
||||
let web3;
|
||||
let mimc;
|
||||
let accounts;
|
||||
|
||||
before(async () => {
|
||||
testrpc = TestRPC.server({
|
||||
ws: true,
|
||||
gasLimit: 5800000,
|
||||
total_accounts: 10,
|
||||
});
|
||||
|
||||
testrpc.listen(8546, "127.0.0.1");
|
||||
|
||||
web3 = new Web3("ws://127.0.0.1:8546");
|
||||
accounts = await web3.eth.getAccounts();
|
||||
});
|
||||
|
||||
after(async () => testrpc.close());
|
||||
|
||||
it("Should deploy the contract", async () => {
|
||||
const C = new web3.eth.Contract(mimcGenContract.abi);
|
||||
|
||||
mimc = await C.deploy({
|
||||
data: mimcGenContract.createCode(SEED, 91)
|
||||
}).send({
|
||||
gas: 1500000,
|
||||
from: accounts[0]
|
||||
});
|
||||
});
|
||||
|
||||
it("Shold calculate the mimic correctly", async () => {
|
||||
const res = await mimc.methods.MiMCpe7(1,2).call();
|
||||
const res2 = await mimcjs.hash(1,2,91);
|
||||
|
||||
assert.equal(res.toString(), res2.toString());
|
||||
});
|
||||
});
|
||||
@@ -85,7 +85,7 @@ module.exports = {
|
||||
// Configure your compilers
|
||||
compilers: {
|
||||
solc: {
|
||||
// version: "0.5.1", // Fetch exact version from solc-bin (default: truffle's version)
|
||||
version: "0.4.25", // Fetch exact version from solc-bin (default: truffle's version)
|
||||
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
|
||||
// settings: { // See the solidity docs for advice about optimization and evmVersion
|
||||
// optimizer: {
|
||||
|
||||
Reference in New Issue
Block a user