Merge pull request #19 from smartkek/fusking-truffle

Fusking truffle
This commit is contained in:
Drygin Alexander 2019-07-05 12:19:34 +03:00 committed by GitHub
commit b4a28675d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 226 additions and 243 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
build/ build/
node_modules/ node_modules/
bundle/
target/ target/
.idea/ .idea/

View File

@ -1,8 +1,8 @@
{ {
"proof": { "proof": {
"a": ["0x12d0dbcfc1da3ea29bc017288fceea3929401f4f12dbd0bba73781420d31aa2d", "0x2811c1eaa63f4a804951bd7f994cbb6bea9df64591793b8392400e8756d1bca7"], "a": ["0x24d858a8ffc1766e7cccf95643f1339cb10978a5b06a6f8abad82782a3ab3efd", "0x2d0b5206a856f75a93284728f7cfa61e998868b632b11886a439add8e6150f3e"],
"b": [["0x04c33f68e1bd55be0928b086c647debcdf7aa0e3c3efc6a8efbc2596a77a0e67", "0x17e7392e0e3ec2b5701e675e6e0569330d03ffffe476fc8d63cfeaa0ba1c8a97"], ["0x2fc402693a54cd1b176abeed209674f2f12ced1496c6ce27ba8cf16903daa4cc", "0x2c47efba3f4f260da643bb6427d08b551bb3446537d6ac4857d611be2355a446"]], "b": [["0x13e6a883986efe7bb0c6e99b00c157d31ea8479283ac6c4934e42368da31e6d8", "0x0718d8dfecf7726df8a27092bac85d58767230b33a66dd8c69ca54f576361fc1"], ["0x160f03315ee7766d576122244d12bcabd24ee3c7d33e1cb05d838337a0fd0dfb", "0x2ea4c7c18ed1b8f3544a4fb3c4d95efa5543182406fef71bfda8760e407a05c7"]],
"c": ["0x04d40f14694092d0f70890a20492b2b68e7eaabdcee744e519678d687c9c3ed0", "0x28de140e393154b0e70b3ef12806af963a4a33b45c24e7864391093b6028fa2b"] "c": ["0x1111708b97dac3f087a3d8e13cfd513d7a82c619d39e9148080b600b7dae210e", "0x2a6e76f3003e65afefae71d3fe18ba26a3940e81463bf94615478cdf5daa2249"]
}, },
"inputs": ["0x00000000000000000000000000000000c6481e22c5ff4164af680b8cfaa5e8ed", "0x000000000000000000000000000000003120eeff89c4f307c4a6faaae059ce10", "0x000000000000000000000000000000005b6d7d198c48c17c9540d29275a04662", "0x00000000000000000000000000000000f7a9aa434629a33c84eec3e16e196f27", "0x0000000000000000000000000000000000000000000000000000000000000001"] "inputs": ["0x00000000000000000000000000000000c6481e22c5ff4164af680b8cfaa5e8ed", "0x000000000000000000000000000000003120eeff89c4f307c4a6faaae059ce10", "0x000000000000000000000000000000005b6d7d198c48c17c9540d29275a04662", "0x00000000000000000000000000000000f7a9aa434629a33c84eec3e16e196f27", "0x0000000000000000000000000000000000000000000000000000000000000001"]
} }

Binary file not shown.

View File

@ -1,11 +1,11 @@
vk.alpha = 0x2c2cb1812fb05d4f31791c66ff995d756b73162f3bb016a5c114befe5cd7903e, 0x0abc1f8a5d49cb2dbda15b5a8b7cd81bec0a581e7c2e16f79446af2d2f5340c0 vk.alpha = 0x2e0a814dd75e4118233ddf6a916a813c40bae07d976fdcd01dbfa22bea641a96, 0x1779e77cff5e54cf2cdc237e51cd6d95ef2c37ab6a7d5f9ce0a242188e1a1fe3
vk.beta = [0x071644533641f7e3acb8606328c591853b2bc27253f29bc11d008a67996fc07f, 0x26ca2720c073a085d8452aef541aac280879971c09b199a6e0f21bf36745e1d8], [0x0b17104896ed701b6d52279992c1f20d558bc0de8284087645633bf3ca1a0c98, 0x2c10eb5b6c0ca42ede8cdcf60642c6dca040abe9abb8294948f4aa0be59a0d42] vk.beta = [0x021548b93199574bdef2be8cb1908a1079b1664d8a041d2e297c3aa6c554855c, 0x190b2d5d03854400e2c2a702f502813677a1d4be920d79648f810e320a30f2c5], [0x0bc956fa715451d64e20b260759c2ae74a82b68f1eef86504051cd3ae547f282, 0x011192ee83c0347e363b7c5fffe156fbadd91591b35dc8fe912d2b498c3a9301]
vk.gamma = [0x0afbadec2ecafdd62278c7021095660f5786f445c040e628e4ed1a410454b582, 0x038aa6f04ee254a97e2b75ea1f30e36785b6cde4dfd3a2371e058ce089b9ad51], [0x077720bb216fb0051c5e153c1bd9aa36a678173b9c13e8d3a83cb5a75ca36948, 0x1f9b58e9abde296abc3c3bab8fb0be2a4f497d8e5d9d463997d316e9cc558a7d] vk.gamma = [0x1c4c46720835faf06e35cd85f05c589a1a98f58112ecf7aacf0deac60681f5a4, 0x1b438f01daf6402ff298981b74f80a5e79c39cce21c67770f74b89e65eb3b9ca], [0x101b8c9c29aa1ac1a709878f6eb4d4a74f4ed1368a18f29c2762b76b8c389f4d, 0x009538b3640e10082d0bf4b18b997fef6af2e7cceb942ebb26bd263e8805fedd]
vk.delta = [0x16526b9b519fa544d3f9ce35a5f4afa7aac0aa4dd54421c4864b3fe8d2415f41, 0x24e24f35699cca59416a7f43c0e93e148b2353440978994df8f81603a46f8839], [0x299f9f09280310aedf63055c5ce76feb16557ed7ff11ba35adad718102b5651a, 0x0c4a2fc4db77ef6c19511b2ffb369981cebbffcb5337a671e1ad678b460ac5e9] vk.delta = [0x25161a4cc549ffabd2c4508038c12d49447c15e9c565b025183ff6114ffcc58b, 0x110f2b773f6d9632162bc2c629467a58e7539ed0f0dc64ff4fd8f63baf4b5a32], [0x0eb80be9e5a3f3f4cb0e39edc1db88dbf8de59b0c800b72dcc34d9c0fae14d55, 0x0839d69bfc27640a59af741138d4f34500d925eb1a4e9fd57fcda269a7411c33]
vk.gammaABC.len() = 6 vk.gammaABC.len() = 6
vk.gammaABC[0] = 0x2f910078bf5092a7ea9d3ce750b7b5399b101509adb8017a6e12fa1a4c638d5b, 0x0b76454d4300571c8d86714b4e5ef095688b51080e674425e8e5edb201f64128 vk.gammaABC[0] = 0x2bb604557c5f1096973ab8afe980ea3ae23bd7457f3f11f67fb395f2d1f3b568, 0x0f12fdb646ea572637ea6e1bbf04158bcabe6947cf614c67efb3f0278279f866
vk.gammaABC[1] = 0x2922a307d415f70c8df6f14b664c46df12a89cd3a89cf7960663907bf9483b68, 0x1bc30a719ddc0099f557cca61a0687766e6275fc98b185baa77735b93bf2a0ef vk.gammaABC[1] = 0x228bbefb9d7457c97766bcae9412c6ddd1de8e3dbcf1606ca6b8f027836affee, 0x01bf2712a663f5a72a469ea83a4c3d453c6023a0cd5d5f86330157f1505d62b3
vk.gammaABC[2] = 0x0201dc8c8faa3dc5b8eec85f029d2482bf11a6b46d5f8e4d9f17d41ac3e4c9c1, 0x0a1d62c1142c92dff75b53d5a572fd7a013708118acf10f718c61fb6226160f5 vk.gammaABC[2] = 0x23af3409b4b3fb3f194dc683be70c5e442de55544edeace8f891a891a4701ca3, 0x1d13edb38da07247e70158557cfa93097d90d92b9a2c99f190c1413f3fdf8828
vk.gammaABC[3] = 0x02276f5896610ec573cd6cdc6e47c69e756362d2b1b1c51c5ab90ac838d1a898, 0x13fa6cc7987f4f3118f6ee3ab85dcd708df17050636d487914077348e0af05b1 vk.gammaABC[3] = 0x00572fbfedfe16fd1dcae266bf009907451cd8db485325ad322fb658cb0c30ff, 0x25415b150b181b2cbecc6f84382b0bd8fd49f2cf498da1c775ad624e5e7b7eaf
vk.gammaABC[4] = 0x0778ae3718fd7f48564bc33b60ec4f39a238e97cb4cc0bbd4ff37119942ff7d4, 0x0282e96481744ee21524d802b3e524bf0596bb37bb63e5ed37c77fc1a5c8e89d vk.gammaABC[4] = 0x1a294f13fbf284a6e11c2f54ed2946fc5fd732dafbf49ac01ce741f224b57c29, 0x182d4a788849c87d27548cbe3a511a0237cb0d4595425eee878d78c4eb4e5529
vk.gammaABC[5] = 0x1ce40e230695bdab7d2ff7ebcf6e6fedb68d1a320238fc98845b151ae4ee3b54, 0x0feac76664d37b57a4ea5a774252bb82355294e55635a8aeb7a1327405d27128 vk.gammaABC[5] = 0x10ec12d1090de44b1aecb41030d123df2d61318c1928d6de10f916c9bfc2f681, 0x0621a1ea9bbbfa893358dfaa206ba1cb8af2ecca483c3c36f2a0c302da401c8f

View File

@ -552,17 +552,17 @@ contract Verifier {
Pairing.G1Point C; Pairing.G1Point C;
} }
function verifyingKey() pure internal returns (VerifyingKey memory vk) { function verifyingKey() pure internal returns (VerifyingKey memory vk) {
vk.a = Pairing.G1Point(uint256(0x2c2cb1812fb05d4f31791c66ff995d756b73162f3bb016a5c114befe5cd7903e), uint256(0x0abc1f8a5d49cb2dbda15b5a8b7cd81bec0a581e7c2e16f79446af2d2f5340c0)); vk.a = Pairing.G1Point(uint256(0x2e0a814dd75e4118233ddf6a916a813c40bae07d976fdcd01dbfa22bea641a96), uint256(0x1779e77cff5e54cf2cdc237e51cd6d95ef2c37ab6a7d5f9ce0a242188e1a1fe3));
vk.b = Pairing.G2Point([uint256(0x071644533641f7e3acb8606328c591853b2bc27253f29bc11d008a67996fc07f), uint256(0x26ca2720c073a085d8452aef541aac280879971c09b199a6e0f21bf36745e1d8)], [uint256(0x0b17104896ed701b6d52279992c1f20d558bc0de8284087645633bf3ca1a0c98), uint256(0x2c10eb5b6c0ca42ede8cdcf60642c6dca040abe9abb8294948f4aa0be59a0d42)]); vk.b = Pairing.G2Point([uint256(0x021548b93199574bdef2be8cb1908a1079b1664d8a041d2e297c3aa6c554855c), uint256(0x190b2d5d03854400e2c2a702f502813677a1d4be920d79648f810e320a30f2c5)], [uint256(0x0bc956fa715451d64e20b260759c2ae74a82b68f1eef86504051cd3ae547f282), uint256(0x011192ee83c0347e363b7c5fffe156fbadd91591b35dc8fe912d2b498c3a9301)]);
vk.gamma = Pairing.G2Point([uint256(0x0afbadec2ecafdd62278c7021095660f5786f445c040e628e4ed1a410454b582), uint256(0x038aa6f04ee254a97e2b75ea1f30e36785b6cde4dfd3a2371e058ce089b9ad51)], [uint256(0x077720bb216fb0051c5e153c1bd9aa36a678173b9c13e8d3a83cb5a75ca36948), uint256(0x1f9b58e9abde296abc3c3bab8fb0be2a4f497d8e5d9d463997d316e9cc558a7d)]); vk.gamma = Pairing.G2Point([uint256(0x1c4c46720835faf06e35cd85f05c589a1a98f58112ecf7aacf0deac60681f5a4), uint256(0x1b438f01daf6402ff298981b74f80a5e79c39cce21c67770f74b89e65eb3b9ca)], [uint256(0x101b8c9c29aa1ac1a709878f6eb4d4a74f4ed1368a18f29c2762b76b8c389f4d), uint256(0x009538b3640e10082d0bf4b18b997fef6af2e7cceb942ebb26bd263e8805fedd)]);
vk.delta = Pairing.G2Point([uint256(0x16526b9b519fa544d3f9ce35a5f4afa7aac0aa4dd54421c4864b3fe8d2415f41), uint256(0x24e24f35699cca59416a7f43c0e93e148b2353440978994df8f81603a46f8839)], [uint256(0x299f9f09280310aedf63055c5ce76feb16557ed7ff11ba35adad718102b5651a), uint256(0x0c4a2fc4db77ef6c19511b2ffb369981cebbffcb5337a671e1ad678b460ac5e9)]); vk.delta = Pairing.G2Point([uint256(0x25161a4cc549ffabd2c4508038c12d49447c15e9c565b025183ff6114ffcc58b), uint256(0x110f2b773f6d9632162bc2c629467a58e7539ed0f0dc64ff4fd8f63baf4b5a32)], [uint256(0x0eb80be9e5a3f3f4cb0e39edc1db88dbf8de59b0c800b72dcc34d9c0fae14d55), uint256(0x0839d69bfc27640a59af741138d4f34500d925eb1a4e9fd57fcda269a7411c33)]);
vk.gammaABC = new Pairing.G1Point[](6); vk.gammaABC = new Pairing.G1Point[](6);
vk.gammaABC[0] = Pairing.G1Point(uint256(0x2f910078bf5092a7ea9d3ce750b7b5399b101509adb8017a6e12fa1a4c638d5b), uint256(0x0b76454d4300571c8d86714b4e5ef095688b51080e674425e8e5edb201f64128)); vk.gammaABC[0] = Pairing.G1Point(uint256(0x2bb604557c5f1096973ab8afe980ea3ae23bd7457f3f11f67fb395f2d1f3b568), uint256(0x0f12fdb646ea572637ea6e1bbf04158bcabe6947cf614c67efb3f0278279f866));
vk.gammaABC[1] = Pairing.G1Point(uint256(0x2922a307d415f70c8df6f14b664c46df12a89cd3a89cf7960663907bf9483b68), uint256(0x1bc30a719ddc0099f557cca61a0687766e6275fc98b185baa77735b93bf2a0ef)); vk.gammaABC[1] = Pairing.G1Point(uint256(0x228bbefb9d7457c97766bcae9412c6ddd1de8e3dbcf1606ca6b8f027836affee), uint256(0x01bf2712a663f5a72a469ea83a4c3d453c6023a0cd5d5f86330157f1505d62b3));
vk.gammaABC[2] = Pairing.G1Point(uint256(0x0201dc8c8faa3dc5b8eec85f029d2482bf11a6b46d5f8e4d9f17d41ac3e4c9c1), uint256(0x0a1d62c1142c92dff75b53d5a572fd7a013708118acf10f718c61fb6226160f5)); vk.gammaABC[2] = Pairing.G1Point(uint256(0x23af3409b4b3fb3f194dc683be70c5e442de55544edeace8f891a891a4701ca3), uint256(0x1d13edb38da07247e70158557cfa93097d90d92b9a2c99f190c1413f3fdf8828));
vk.gammaABC[3] = Pairing.G1Point(uint256(0x02276f5896610ec573cd6cdc6e47c69e756362d2b1b1c51c5ab90ac838d1a898), uint256(0x13fa6cc7987f4f3118f6ee3ab85dcd708df17050636d487914077348e0af05b1)); vk.gammaABC[3] = Pairing.G1Point(uint256(0x00572fbfedfe16fd1dcae266bf009907451cd8db485325ad322fb658cb0c30ff), uint256(0x25415b150b181b2cbecc6f84382b0bd8fd49f2cf498da1c775ad624e5e7b7eaf));
vk.gammaABC[4] = Pairing.G1Point(uint256(0x0778ae3718fd7f48564bc33b60ec4f39a238e97cb4cc0bbd4ff37119942ff7d4), uint256(0x0282e96481744ee21524d802b3e524bf0596bb37bb63e5ed37c77fc1a5c8e89d)); vk.gammaABC[4] = Pairing.G1Point(uint256(0x1a294f13fbf284a6e11c2f54ed2946fc5fd732dafbf49ac01ce741f224b57c29), uint256(0x182d4a788849c87d27548cbe3a511a0237cb0d4595425eee878d78c4eb4e5529));
vk.gammaABC[5] = Pairing.G1Point(uint256(0x1ce40e230695bdab7d2ff7ebcf6e6fedb68d1a320238fc98845b151ae4ee3b54), uint256(0x0feac76664d37b57a4ea5a774252bb82355294e55635a8aeb7a1327405d27128)); vk.gammaABC[5] = Pairing.G1Point(uint256(0x10ec12d1090de44b1aecb41030d123df2d61318c1928d6de10f916c9bfc2f681), uint256(0x0621a1ea9bbbfa893358dfaa206ba1cb8af2ecca483c3c36f2a0c302da401c8f));
} }
function verify(uint[] memory input, Proof memory proof) internal returns (uint) { function verify(uint[] memory input, Proof memory proof) internal returns (uint) {
VerifyingKey memory vk = verifyingKey(); VerifyingKey memory vk = verifyingKey();

View File

@ -28,6 +28,7 @@
<label id="challenge">Challenge?</label> <label id="challenge">Challenge?</label>
</div> </div>
</div> </div>
<p> </p>
<div class="row 1"> <div class="row 1">
<div class="col-sm-7"> <div class="col-sm-7">
<label id="state-id-0">None</label> <label id="state-id-0">None</label>
@ -37,9 +38,9 @@
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<button type="button" class="btn btn-primary" id="challenge-0">Challenge on Fluence!</button> <button type="button" class="btn btn-primary" id="challenge-0">Challenge on Fluence!</button>
<p><a id = "link-0" target="_blank"></a></p>
</div> </div>
</div> </div>
<p> </p>
<div class="row 2"> <div class="row 2">
<div class="col-sm-7"> <div class="col-sm-7">
<label id="state-id-1">None</label> <label id="state-id-1">None</label>
@ -49,9 +50,9 @@
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<button type="button" class="btn btn-primary" id="challenge-1">Challenge on Fluence!</button> <button type="button" class="btn btn-primary" id="challenge-1">Challenge on Fluence!</button>
<p><a id = "link-1" target="_blank"></a></p>
</div> </div>
</div> </div>
<p> </p>
<div class="row 3"> <div class="row 3">
<div class="col-sm-7"> <div class="col-sm-7">
<label id="state-id-2">None</label> <label id="state-id-2">None</label>
@ -61,10 +62,9 @@
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<button type="button" class="btn btn-primary" id="challenge-2">Challenge on Fluence!</button> <button type="button" class="btn btn-primary" id="challenge-2">Challenge on Fluence!</button>
<p><a id = "link-2" target="_blank"></a></p>
</div> </div>
</div> </div>
<p> </p>
<div class="row 4"> <div class="row 4">
<div class="col-sm-7"> <div class="col-sm-7">
<label id="state-id-3">None</label> <label id="state-id-3">None</label>
@ -74,9 +74,9 @@
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<button type="button" class="btn btn-primary" id="challenge-3">Challenge on Fluence!</button> <button type="button" class="btn btn-primary" id="challenge-3">Challenge on Fluence!</button>
<p><a id = "link-3" target="_blank"></a></p>
</div> </div>
</div> </div>
<p> </p>
<div class="row 5"> <div class="row 5">
<div class="col-sm-7"> <div class="col-sm-7">
<label id="state-id-4">None</label> <label id="state-id-4">None</label>
@ -86,7 +86,6 @@
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<button type="button" class="btn btn-primary" id="challenge-4">Challenge on Fluence!</button> <button type="button" class="btn btn-primary" id="challenge-4">Challenge on Fluence!</button>
<p><a id = "link-4" target="_blank"></a></p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -8,22 +8,22 @@ window.getResultAsString = function (result) {
var contractInstance; var contractInstance;
$(document).ready(function() { $(document).ready(async function() {
let contractAddress = "0xeFF91455de6D4CF57C141bD8bF819E5f873c1A01"; let contractAddress = "0xeFF91455de6D4CF57C141bD8bF819E5f873c1A01";
// set ethUrl to `undefined` to use MetaMask instead of Ethereum node // set ethUrl to `undefined` to use MetaMask instead of Ethereum node
let ethUrl = "http://rinkeby.fluence.one:8545/"; let ethUrl = "http://rinkeby.fluence.one:8545/";
// application to interact with that stored in Fluence contract // application to interact with that stored in Fluence contract
let appId = "264"; let appId = "269";
// create a session between client and backend application, and then join the game // create a session between client and backend application, and then join the game
fluence.connect(contractAddress, appId, ethUrl).then((s) => { await fluence.connect(contractAddress, appId, ethUrl).then((s) => {
console.log("Session created"); console.log("Session created");
window.session = s; window.session = s;
}); });
var lazyAddress = '0x1cca1f0be338c747b11a16aba8d0905251628bdf'; var lazyAddress = '0x4812b51D4420Da87C3cD78a77048328cd6914f27';
let ControllerAbi = [ let ControllerAbi = [
{ {
"constant": true, "constant": true,
@ -430,8 +430,8 @@ $('button').click(function () {
function challengeEthereum(id, data) { function challengeEthereum(id, data) {
console.log('Challenging task N ' + data + ' on Ethereum!'); console.log('Challenging task N ' + data + ' on Ethereum!');
contractInstance.challenge.sendTransaction(data, function (err, txHash) { contractInstance.challenge.sendTransaction(data, function (err, txHash) {
$('#challenge-' + id).remove(); if (!err) {
$('#link-' + id).text('See tx on Etherscan!').attr("href", "https://rinkeby.etherscan.io/tx/" + txHash); $('#challenge-' + id).text('See tx on Etherscan!').attr("onclick", "window.open('https://rinkeby.etherscan.io/tx/" + txHash + "')");
}
}); });
} }

View File

@ -1,5 +1,5 @@
{ {
"name": "frontend-challenger", "name": "lazy-snark-frontend",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"private": true, "private": true,

View File

@ -1,4 +1,4 @@
pragma solidity ^0.5.4; pragma solidity 0.5.10;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./Structs.sol"; import "./Structs.sol";

View File

@ -1,4 +1,4 @@
pragma solidity ^0.5.4; pragma solidity 0.5.10;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./IVerifier.sol"; import "./IVerifier.sol";
@ -72,9 +72,7 @@ contract Lazy is Structs {
msg.sender.transfer(stake); msg.sender.transfer(stake);
} }
function taskDataById(uint id) external view returns( function taskDataById(uint id) external view returns(uint[13] memory data) {
uint[13] memory data
) {
Task memory task = tasks[id]; Task memory task = tasks[id];
data[0] = task.data.input[0]; data[0] = task.data.input[0];

View File

@ -1,4 +1,4 @@
pragma solidity ^0.5.4; pragma solidity 0.5.10;
interface Structs { interface Structs {
struct Data { struct Data {

View File

@ -41,40 +41,40 @@ library BN256G2 {
pt1yx == 0 && pt1yy == 0 pt1yx == 0 && pt1yy == 0
) { ) {
if (!( if (!(
pt2xx == 0 && pt2xy == 0 && pt2xx == 0 && pt2xy == 0 &&
pt2yx == 0 && pt2yy == 0 pt2yx == 0 && pt2yy == 0
)) { )) {
assert(_isOnCurve( assert(_isOnCurve(
pt2xx, pt2xy, pt2xx, pt2xy,
pt2yx, pt2yy pt2yx, pt2yy
)); ));
} }
return ( return (
pt2xx, pt2xy, pt2xx, pt2xy,
pt2yx, pt2yy pt2yx, pt2yy
); );
} else if ( } else if (
pt2xx == 0 && pt2xy == 0 && pt2xx == 0 && pt2xy == 0 &&
pt2yx == 0 && pt2yy == 0 pt2yx == 0 && pt2yy == 0
) { ) {
assert(_isOnCurve( assert(_isOnCurve(
pt1xx, pt1xy, pt1xx, pt1xy,
pt1yx, pt1yy pt1yx, pt1yy
)); ));
return ( return (
pt1xx, pt1xy, pt1xx, pt1xy,
pt1yx, pt1yy pt1yx, pt1yy
); );
} }
assert(_isOnCurve( assert(_isOnCurve(
pt1xx, pt1xy, pt1xx, pt1xy,
pt1yx, pt1yy pt1yx, pt1yy
)); ));
assert(_isOnCurve( assert(_isOnCurve(
pt2xx, pt2xy, pt2xx, pt2xy,
pt2yx, pt2yy pt2yx, pt2yy
)); ));
uint256[6] memory pt3 = _ECTwistAddJacobian( uint256[6] memory pt3 = _ECTwistAddJacobian(
pt1xx, pt1xy, pt1xx, pt1xy,
@ -119,9 +119,9 @@ library BN256G2 {
pt1zx = 0; pt1zx = 0;
} else { } else {
assert(_isOnCurve( assert(_isOnCurve(
pt1xx, pt1xy, pt1xx, pt1xy,
pt1yx, pt1yy pt1yx, pt1yy
)); ));
} }
uint256[6] memory pt2 = _ECTwistMulJacobian( uint256[6] memory pt2 = _ECTwistMulJacobian(
@ -155,8 +155,8 @@ library BN256G2 {
uint256 yx, uint256 yy uint256 yx, uint256 yy
) internal pure returns(uint256, uint256) { ) internal pure returns(uint256, uint256) {
return ( return (
submod(mulmod(xx, yx, FIELD_MODULUS), mulmod(xy, yy, FIELD_MODULUS), FIELD_MODULUS), submod(mulmod(xx, yx, FIELD_MODULUS), mulmod(xy, yy, FIELD_MODULUS), FIELD_MODULUS),
addmod(mulmod(xx, yy, FIELD_MODULUS), mulmod(xy, yx, FIELD_MODULUS), FIELD_MODULUS) addmod(mulmod(xx, yy, FIELD_MODULUS), mulmod(xy, yx, FIELD_MODULUS), FIELD_MODULUS)
); );
} }
@ -165,8 +165,8 @@ library BN256G2 {
uint256 c uint256 c
) internal pure returns(uint256, uint256) { ) internal pure returns(uint256, uint256) {
return ( return (
mulmod(xx, c, FIELD_MODULUS), mulmod(xx, c, FIELD_MODULUS),
mulmod(xy, c, FIELD_MODULUS) mulmod(xy, c, FIELD_MODULUS)
); );
} }
@ -175,8 +175,8 @@ library BN256G2 {
uint256 yx, uint256 yy uint256 yx, uint256 yy
) internal pure returns(uint256, uint256) { ) internal pure returns(uint256, uint256) {
return ( return (
addmod(xx, yx, FIELD_MODULUS), addmod(xx, yx, FIELD_MODULUS),
addmod(xy, yy, FIELD_MODULUS) addmod(xy, yy, FIELD_MODULUS)
); );
} }
@ -185,8 +185,8 @@ library BN256G2 {
uint256 yx, uint256 yy uint256 yx, uint256 yy
) internal pure returns(uint256 rx, uint256 ry) { ) internal pure returns(uint256 rx, uint256 ry) {
return ( return (
submod(xx, yx, FIELD_MODULUS), submod(xx, yx, FIELD_MODULUS),
submod(xy, yy, FIELD_MODULUS) submod(xy, yy, FIELD_MODULUS)
); );
} }
@ -201,8 +201,8 @@ library BN256G2 {
function _FQ2Inv(uint256 x, uint256 y) internal pure returns(uint256, uint256) { function _FQ2Inv(uint256 x, uint256 y) internal pure returns(uint256, uint256) {
uint256 inv = _modInv(addmod(mulmod(y, y, FIELD_MODULUS), mulmod(x, x, FIELD_MODULUS), FIELD_MODULUS), FIELD_MODULUS); uint256 inv = _modInv(addmod(mulmod(y, y, FIELD_MODULUS), mulmod(x, x, FIELD_MODULUS), FIELD_MODULUS), FIELD_MODULUS);
return ( return (
mulmod(x, inv, FIELD_MODULUS), mulmod(x, inv, FIELD_MODULUS),
FIELD_MODULUS - mulmod(y, inv, FIELD_MODULUS) FIELD_MODULUS - mulmod(y, inv, FIELD_MODULUS)
); );
} }
@ -257,73 +257,73 @@ library BN256G2 {
uint256 pt2xx, uint256 pt2xy, uint256 pt2xx, uint256 pt2xy,
uint256 pt2yx, uint256 pt2yy, uint256 pt2yx, uint256 pt2yy,
uint256 pt2zx, uint256 pt2zy) internal pure returns (uint256[6] memory pt3) { uint256 pt2zx, uint256 pt2zy) internal pure returns (uint256[6] memory pt3) {
if (pt1zx == 0 && pt1zy == 0) { if (pt1zx == 0 && pt1zy == 0) {
(
pt3[PTXX], pt3[PTXY],
pt3[PTYX], pt3[PTYY],
pt3[PTZX], pt3[PTZY]
) = (
pt2xx, pt2xy,
pt2yx, pt2yy,
pt2zx, pt2zy
);
return pt3;
} else if (pt2zx == 0 && pt2zy == 0) {
(
pt3[PTXX], pt3[PTXY],
pt3[PTYX], pt3[PTYY],
pt3[PTZX], pt3[PTZY]
) = (
pt1xx, pt1xy,
pt1yx, pt1yy,
pt1zx, pt1zy
);
return pt3;
}
(pt2yx, pt2yy) = _FQ2Mul(pt2yx, pt2yy, pt1zx, pt1zy); // U1 = y2 * z1
(pt3[PTYX], pt3[PTYY]) = _FQ2Mul(pt1yx, pt1yy, pt2zx, pt2zy); // U2 = y1 * z2
(pt2xx, pt2xy) = _FQ2Mul(pt2xx, pt2xy, pt1zx, pt1zy); // V1 = x2 * z1
(pt3[PTZX], pt3[PTZY]) = _FQ2Mul(pt1xx, pt1xy, pt2zx, pt2zy); // V2 = x1 * z2
if (pt2xx == pt3[PTZX] && pt2xy == pt3[PTZY]) {
if (pt2yx == pt3[PTYX] && pt2yy == pt3[PTYY]) {
( (
pt3[PTXX], pt3[PTXY], pt3[PTXX], pt3[PTXY],
pt3[PTYX], pt3[PTYY], pt3[PTYX], pt3[PTYY],
pt3[PTZX], pt3[PTZY] pt3[PTZX], pt3[PTZY]
) = ( ) = _ECTwistDoubleJacobian(pt1xx, pt1xy, pt1yx, pt1yy, pt1zx, pt1zy);
pt2xx, pt2xy,
pt2yx, pt2yy,
pt2zx, pt2zy
);
return pt3;
} else if (pt2zx == 0 && pt2zy == 0) {
(
pt3[PTXX], pt3[PTXY],
pt3[PTYX], pt3[PTYY],
pt3[PTZX], pt3[PTZY]
) = (
pt1xx, pt1xy,
pt1yx, pt1yy,
pt1zx, pt1zy
);
return pt3; return pt3;
} }
(
pt3[PTXX], pt3[PTXY],
pt3[PTYX], pt3[PTYY],
pt3[PTZX], pt3[PTZY]
) = (
1, 0,
1, 0,
0, 0
);
return pt3;
}
(pt2yx, pt2yy) = _FQ2Mul(pt2yx, pt2yy, pt1zx, pt1zy); // U1 = y2 * z1 (pt2zx, pt2zy) = _FQ2Mul(pt1zx, pt1zy, pt2zx, pt2zy); // W = z1 * z2
(pt3[PTYX], pt3[PTYY]) = _FQ2Mul(pt1yx, pt1yy, pt2zx, pt2zy); // U2 = y1 * z2 (pt1xx, pt1xy) = _FQ2Sub(pt2yx, pt2yy, pt3[PTYX], pt3[PTYY]); // U = U1 - U2
(pt2xx, pt2xy) = _FQ2Mul(pt2xx, pt2xy, pt1zx, pt1zy); // V1 = x2 * z1 (pt1yx, pt1yy) = _FQ2Sub(pt2xx, pt2xy, pt3[PTZX], pt3[PTZY]); // V = V1 - V2
(pt3[PTZX], pt3[PTZY]) = _FQ2Mul(pt1xx, pt1xy, pt2zx, pt2zy); // V2 = x1 * z2 (pt1zx, pt1zy) = _FQ2Mul(pt1yx, pt1yy, pt1yx, pt1yy); // V_squared = V * V
(pt2yx, pt2yy) = _FQ2Mul(pt1zx, pt1zy, pt3[PTZX], pt3[PTZY]); // V_squared_times_V2 = V_squared * V2
if (pt2xx == pt3[PTZX] && pt2xy == pt3[PTZY]) { (pt1zx, pt1zy) = _FQ2Mul(pt1zx, pt1zy, pt1yx, pt1yy); // V_cubed = V * V_squared
if (pt2yx == pt3[PTYX] && pt2yy == pt3[PTYY]) { (pt3[PTZX], pt3[PTZY]) = _FQ2Mul(pt1zx, pt1zy, pt2zx, pt2zy); // newz = V_cubed * W
( (pt2xx, pt2xy) = _FQ2Mul(pt1xx, pt1xy, pt1xx, pt1xy); // U * U
pt3[PTXX], pt3[PTXY], (pt2xx, pt2xy) = _FQ2Mul(pt2xx, pt2xy, pt2zx, pt2zy); // U * U * W
pt3[PTYX], pt3[PTYY], (pt2xx, pt2xy) = _FQ2Sub(pt2xx, pt2xy, pt1zx, pt1zy); // U * U * W - V_cubed
pt3[PTZX], pt3[PTZY] (pt2zx, pt2zy) = _FQ2Muc(pt2yx, pt2yy, 2); // 2 * V_squared_times_V2
) = _ECTwistDoubleJacobian(pt1xx, pt1xy, pt1yx, pt1yy, pt1zx, pt1zy); (pt2xx, pt2xy) = _FQ2Sub(pt2xx, pt2xy, pt2zx, pt2zy); // A = U * U * W - V_cubed - 2 * V_squared_times_V2
return pt3; (pt3[PTXX], pt3[PTXY]) = _FQ2Mul(pt1yx, pt1yy, pt2xx, pt2xy); // newx = V * A
} (pt1yx, pt1yy) = _FQ2Sub(pt2yx, pt2yy, pt2xx, pt2xy); // V_squared_times_V2 - A
( (pt1yx, pt1yy) = _FQ2Mul(pt1xx, pt1xy, pt1yx, pt1yy); // U * (V_squared_times_V2 - A)
pt3[PTXX], pt3[PTXY], (pt1xx, pt1xy) = _FQ2Mul(pt1zx, pt1zy, pt3[PTYX], pt3[PTYY]); // V_cubed * U2
pt3[PTYX], pt3[PTYY], (pt3[PTYX], pt3[PTYY]) = _FQ2Sub(pt1yx, pt1yy, pt1xx, pt1xy); // newy = U * (V_squared_times_V2 - A) - V_cubed * U2
pt3[PTZX], pt3[PTZY]
) = (
1, 0,
1, 0,
0, 0
);
return pt3;
}
(pt2zx, pt2zy) = _FQ2Mul(pt1zx, pt1zy, pt2zx, pt2zy); // W = z1 * z2
(pt1xx, pt1xy) = _FQ2Sub(pt2yx, pt2yy, pt3[PTYX], pt3[PTYY]); // U = U1 - U2
(pt1yx, pt1yy) = _FQ2Sub(pt2xx, pt2xy, pt3[PTZX], pt3[PTZY]); // V = V1 - V2
(pt1zx, pt1zy) = _FQ2Mul(pt1yx, pt1yy, pt1yx, pt1yy); // V_squared = V * V
(pt2yx, pt2yy) = _FQ2Mul(pt1zx, pt1zy, pt3[PTZX], pt3[PTZY]); // V_squared_times_V2 = V_squared * V2
(pt1zx, pt1zy) = _FQ2Mul(pt1zx, pt1zy, pt1yx, pt1yy); // V_cubed = V * V_squared
(pt3[PTZX], pt3[PTZY]) = _FQ2Mul(pt1zx, pt1zy, pt2zx, pt2zy); // newz = V_cubed * W
(pt2xx, pt2xy) = _FQ2Mul(pt1xx, pt1xy, pt1xx, pt1xy); // U * U
(pt2xx, pt2xy) = _FQ2Mul(pt2xx, pt2xy, pt2zx, pt2zy); // U * U * W
(pt2xx, pt2xy) = _FQ2Sub(pt2xx, pt2xy, pt1zx, pt1zy); // U * U * W - V_cubed
(pt2zx, pt2zy) = _FQ2Muc(pt2yx, pt2yy, 2); // 2 * V_squared_times_V2
(pt2xx, pt2xy) = _FQ2Sub(pt2xx, pt2xy, pt2zx, pt2zy); // A = U * U * W - V_cubed - 2 * V_squared_times_V2
(pt3[PTXX], pt3[PTXY]) = _FQ2Mul(pt1yx, pt1yy, pt2xx, pt2xy); // newx = V * A
(pt1yx, pt1yy) = _FQ2Sub(pt2yx, pt2yy, pt2xx, pt2xy); // V_squared_times_V2 - A
(pt1yx, pt1yy) = _FQ2Mul(pt1xx, pt1xy, pt1yx, pt1yy); // U * (V_squared_times_V2 - A)
(pt1xx, pt1xy) = _FQ2Mul(pt1zx, pt1zy, pt3[PTYX], pt3[PTYY]); // V_cubed * U2
(pt3[PTYX], pt3[PTYY]) = _FQ2Sub(pt1yx, pt1yy, pt1xx, pt1xy); // newy = U * (V_squared_times_V2 - A) - V_cubed * U2
} }
function _ECTwistDoubleJacobian( function _ECTwistDoubleJacobian(
@ -374,9 +374,9 @@ library BN256G2 {
pt1zx, pt1zy); pt1zx, pt1zy);
} }
( (
pt1xx, pt1xy, pt1xx, pt1xy,
pt1yx, pt1yy, pt1yx, pt1yy,
pt1zx, pt1zy pt1zx, pt1zy
) = _ECTwistDoubleJacobian( ) = _ECTwistDoubleJacobian(
pt1xx, pt1xy, pt1xx, pt1xy,
pt1yx, pt1yy, pt1yx, pt1yy,
@ -415,9 +415,9 @@ library Pairing {
function P2() pure internal returns (G2Point memory) { function P2() pure internal returns (G2Point memory) {
return G2Point( return G2Point(
[11559732032986387107991004021392285783925812861821192530917403151452391805634, [11559732032986387107991004021392285783925812861821192530917403151452391805634,
10857046999023057135944570762232829481370756359578518086990519993285655852781], 10857046999023057135944570762232829481370756359578518086990519993285655852781],
[4082367875863433681332203403145435568316851327593401208105741076214120093531, [4082367875863433681332203403145435568316851327593401208105741076214120093531,
8495653923123431417604973247489272438418190587263600148770280649306958101930] 8495653923123431417604973247489272438418190587263600148770280649306958101930]
); );
} }
/// @return the negation of p, i.e. p.addition(p.negate()) should be zero. /// @return the negation of p, i.e. p.addition(p.negate()) should be zero.
@ -438,7 +438,7 @@ library Pairing {
bool success; bool success;
assembly { assembly {
success := call(sub(gas, 2000), 6, 0, input, 0xc0, r, 0x60) success := call(sub(gas, 2000), 6, 0, input, 0xc0, r, 0x60)
// Use "invalid" to make gas estimation work // Use "invalid" to make gas estimation work
switch success case 0 { invalid() } switch success case 0 { invalid() }
} }
require(success); require(success);
@ -457,7 +457,7 @@ library Pairing {
bool success; bool success;
assembly { assembly {
success := call(sub(gas, 2000), 7, 0, input, 0x80, r, 0x60) success := call(sub(gas, 2000), 7, 0, input, 0x80, r, 0x60)
// Use "invalid" to make gas estimation work // Use "invalid" to make gas estimation work
switch success case 0 { invalid() } switch success case 0 { invalid() }
} }
require (success); require (success);
@ -484,7 +484,7 @@ library Pairing {
bool success; bool success;
assembly { assembly {
success := call(sub(gas, 2000), 8, 0, add(input, 0x20), mul(inputSize, 0x20), out, 0x20) success := call(sub(gas, 2000), 8, 0, add(input, 0x20), mul(inputSize, 0x20), out, 0x20)
// Use "invalid" to make gas estimation work // Use "invalid" to make gas estimation work
switch success case 0 { invalid() } switch success case 0 { invalid() }
} }
require(success); require(success);
@ -502,9 +502,9 @@ library Pairing {
} }
/// Convenience method for a pairing check for three pairs. /// Convenience method for a pairing check for three pairs.
function pairingProd3( function pairingProd3(
G1Point memory a1, G2Point memory a2, G1Point memory a1, G2Point memory a2,
G1Point memory b1, G2Point memory b2, G1Point memory b1, G2Point memory b2,
G1Point memory c1, G2Point memory c2 G1Point memory c1, G2Point memory c2
) internal returns (bool) { ) internal returns (bool) {
G1Point[] memory p1 = new G1Point[](3); G1Point[] memory p1 = new G1Point[](3);
G2Point[] memory p2 = new G2Point[](3); G2Point[] memory p2 = new G2Point[](3);
@ -518,10 +518,10 @@ library Pairing {
} }
/// Convenience method for a pairing check for four pairs. /// Convenience method for a pairing check for four pairs.
function pairingProd4( function pairingProd4(
G1Point memory a1, G2Point memory a2, G1Point memory a1, G2Point memory a2,
G1Point memory b1, G2Point memory b2, G1Point memory b1, G2Point memory b2,
G1Point memory c1, G2Point memory c2, G1Point memory c1, G2Point memory c2,
G1Point memory d1, G2Point memory d2 G1Point memory d1, G2Point memory d2
) internal returns (bool) { ) internal returns (bool) {
G1Point[] memory p1 = new G1Point[](4); G1Point[] memory p1 = new G1Point[](4);
G2Point[] memory p2 = new G2Point[](4); G2Point[] memory p2 = new G2Point[](4);
@ -552,17 +552,17 @@ contract Verifier {
Pairing.G1Point C; Pairing.G1Point C;
} }
function verifyingKey() pure internal returns (VerifyingKey memory vk) { function verifyingKey() pure internal returns (VerifyingKey memory vk) {
vk.a = Pairing.G1Point(uint256(0x2c2cb1812fb05d4f31791c66ff995d756b73162f3bb016a5c114befe5cd7903e), uint256(0x0abc1f8a5d49cb2dbda15b5a8b7cd81bec0a581e7c2e16f79446af2d2f5340c0)); vk.a = Pairing.G1Point(uint256(0x2e0a814dd75e4118233ddf6a916a813c40bae07d976fdcd01dbfa22bea641a96), uint256(0x1779e77cff5e54cf2cdc237e51cd6d95ef2c37ab6a7d5f9ce0a242188e1a1fe3));
vk.b = Pairing.G2Point([uint256(0x071644533641f7e3acb8606328c591853b2bc27253f29bc11d008a67996fc07f), uint256(0x26ca2720c073a085d8452aef541aac280879971c09b199a6e0f21bf36745e1d8)], [uint256(0x0b17104896ed701b6d52279992c1f20d558bc0de8284087645633bf3ca1a0c98), uint256(0x2c10eb5b6c0ca42ede8cdcf60642c6dca040abe9abb8294948f4aa0be59a0d42)]); vk.b = Pairing.G2Point([uint256(0x021548b93199574bdef2be8cb1908a1079b1664d8a041d2e297c3aa6c554855c), uint256(0x190b2d5d03854400e2c2a702f502813677a1d4be920d79648f810e320a30f2c5)], [uint256(0x0bc956fa715451d64e20b260759c2ae74a82b68f1eef86504051cd3ae547f282), uint256(0x011192ee83c0347e363b7c5fffe156fbadd91591b35dc8fe912d2b498c3a9301)]);
vk.gamma = Pairing.G2Point([uint256(0x0afbadec2ecafdd62278c7021095660f5786f445c040e628e4ed1a410454b582), uint256(0x038aa6f04ee254a97e2b75ea1f30e36785b6cde4dfd3a2371e058ce089b9ad51)], [uint256(0x077720bb216fb0051c5e153c1bd9aa36a678173b9c13e8d3a83cb5a75ca36948), uint256(0x1f9b58e9abde296abc3c3bab8fb0be2a4f497d8e5d9d463997d316e9cc558a7d)]); vk.gamma = Pairing.G2Point([uint256(0x1c4c46720835faf06e35cd85f05c589a1a98f58112ecf7aacf0deac60681f5a4), uint256(0x1b438f01daf6402ff298981b74f80a5e79c39cce21c67770f74b89e65eb3b9ca)], [uint256(0x101b8c9c29aa1ac1a709878f6eb4d4a74f4ed1368a18f29c2762b76b8c389f4d), uint256(0x009538b3640e10082d0bf4b18b997fef6af2e7cceb942ebb26bd263e8805fedd)]);
vk.delta = Pairing.G2Point([uint256(0x16526b9b519fa544d3f9ce35a5f4afa7aac0aa4dd54421c4864b3fe8d2415f41), uint256(0x24e24f35699cca59416a7f43c0e93e148b2353440978994df8f81603a46f8839)], [uint256(0x299f9f09280310aedf63055c5ce76feb16557ed7ff11ba35adad718102b5651a), uint256(0x0c4a2fc4db77ef6c19511b2ffb369981cebbffcb5337a671e1ad678b460ac5e9)]); vk.delta = Pairing.G2Point([uint256(0x25161a4cc549ffabd2c4508038c12d49447c15e9c565b025183ff6114ffcc58b), uint256(0x110f2b773f6d9632162bc2c629467a58e7539ed0f0dc64ff4fd8f63baf4b5a32)], [uint256(0x0eb80be9e5a3f3f4cb0e39edc1db88dbf8de59b0c800b72dcc34d9c0fae14d55), uint256(0x0839d69bfc27640a59af741138d4f34500d925eb1a4e9fd57fcda269a7411c33)]);
vk.gammaABC = new Pairing.G1Point[](6); vk.gammaABC = new Pairing.G1Point[](6);
vk.gammaABC[0] = Pairing.G1Point(uint256(0x2f910078bf5092a7ea9d3ce750b7b5399b101509adb8017a6e12fa1a4c638d5b), uint256(0x0b76454d4300571c8d86714b4e5ef095688b51080e674425e8e5edb201f64128)); vk.gammaABC[0] = Pairing.G1Point(uint256(0x2bb604557c5f1096973ab8afe980ea3ae23bd7457f3f11f67fb395f2d1f3b568), uint256(0x0f12fdb646ea572637ea6e1bbf04158bcabe6947cf614c67efb3f0278279f866));
vk.gammaABC[1] = Pairing.G1Point(uint256(0x2922a307d415f70c8df6f14b664c46df12a89cd3a89cf7960663907bf9483b68), uint256(0x1bc30a719ddc0099f557cca61a0687766e6275fc98b185baa77735b93bf2a0ef)); vk.gammaABC[1] = Pairing.G1Point(uint256(0x228bbefb9d7457c97766bcae9412c6ddd1de8e3dbcf1606ca6b8f027836affee), uint256(0x01bf2712a663f5a72a469ea83a4c3d453c6023a0cd5d5f86330157f1505d62b3));
vk.gammaABC[2] = Pairing.G1Point(uint256(0x0201dc8c8faa3dc5b8eec85f029d2482bf11a6b46d5f8e4d9f17d41ac3e4c9c1), uint256(0x0a1d62c1142c92dff75b53d5a572fd7a013708118acf10f718c61fb6226160f5)); vk.gammaABC[2] = Pairing.G1Point(uint256(0x23af3409b4b3fb3f194dc683be70c5e442de55544edeace8f891a891a4701ca3), uint256(0x1d13edb38da07247e70158557cfa93097d90d92b9a2c99f190c1413f3fdf8828));
vk.gammaABC[3] = Pairing.G1Point(uint256(0x02276f5896610ec573cd6cdc6e47c69e756362d2b1b1c51c5ab90ac838d1a898), uint256(0x13fa6cc7987f4f3118f6ee3ab85dcd708df17050636d487914077348e0af05b1)); vk.gammaABC[3] = Pairing.G1Point(uint256(0x00572fbfedfe16fd1dcae266bf009907451cd8db485325ad322fb658cb0c30ff), uint256(0x25415b150b181b2cbecc6f84382b0bd8fd49f2cf498da1c775ad624e5e7b7eaf));
vk.gammaABC[4] = Pairing.G1Point(uint256(0x0778ae3718fd7f48564bc33b60ec4f39a238e97cb4cc0bbd4ff37119942ff7d4), uint256(0x0282e96481744ee21524d802b3e524bf0596bb37bb63e5ed37c77fc1a5c8e89d)); vk.gammaABC[4] = Pairing.G1Point(uint256(0x1a294f13fbf284a6e11c2f54ed2946fc5fd732dafbf49ac01ce741f224b57c29), uint256(0x182d4a788849c87d27548cbe3a511a0237cb0d4595425eee878d78c4eb4e5529));
vk.gammaABC[5] = Pairing.G1Point(uint256(0x1ce40e230695bdab7d2ff7ebcf6e6fedb68d1a320238fc98845b151ae4ee3b54), uint256(0x0feac76664d37b57a4ea5a774252bb82355294e55635a8aeb7a1327405d27128)); vk.gammaABC[5] = Pairing.G1Point(uint256(0x10ec12d1090de44b1aecb41030d123df2d61318c1928d6de10f916c9bfc2f681), uint256(0x0621a1ea9bbbfa893358dfaa206ba1cb8af2ecca483c3c36f2a0c302da401c8f));
} }
function verify(uint[] memory input, Proof memory proof) internal returns (uint) { function verify(uint[] memory input, Proof memory proof) internal returns (uint) {
VerifyingKey memory vk = verifyingKey(); VerifyingKey memory vk = verifyingKey();
@ -573,19 +573,19 @@ contract Verifier {
vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.gammaABC[i + 1], input[i])); vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.gammaABC[i + 1], input[i]));
vk_x = Pairing.addition(vk_x, vk.gammaABC[0]); vk_x = Pairing.addition(vk_x, vk.gammaABC[0]);
if(!Pairing.pairingProd4( if(!Pairing.pairingProd4(
proof.A, proof.B, proof.A, proof.B,
Pairing.negate(vk_x), vk.gamma, Pairing.negate(vk_x), vk.gamma,
Pairing.negate(proof.C), vk.delta, Pairing.negate(proof.C), vk.delta,
Pairing.negate(vk.a), vk.b)) return 1; Pairing.negate(vk.a), vk.b)) return 1;
return 0; return 0;
} }
event Verified(string s); event Verified(string s);
function verifyTx( function verifyTx(
uint[2] memory a, uint[2] memory a,
uint[2][2] memory b, uint[2][2] memory b,
uint[2] memory c, uint[2] memory c,
uint[5] memory input uint[5] memory input
) public returns (bool r) { ) public returns (bool r) {
Proof memory proof; Proof memory proof;
proof.A = Pairing.G1Point(a[0], a[1]); proof.A = Pairing.G1Point(a[0], a[1]);
proof.B = Pairing.G2Point([b[0][0], b[0][1]], [b[1][0], b[1][1]]); proof.B = Pairing.G2Point([b[0][0], b[0][1]], [b[1][0], b[1][1]]);
@ -601,4 +601,4 @@ contract Verifier {
return false; return false;
} }
} }
} }

View File

@ -1,4 +1,4 @@
pragma solidity ^0.5.4; pragma solidity 0.5.10;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./IVerifier.sol"; import "./IVerifier.sol";

View File

@ -1,4 +1,4 @@
const Migrations = artifacts.require("Migrations"); const Migrations = artifacts.require("./Migrations.sol");
module.exports = function(deployer) { module.exports = function(deployer) {
deployer.deploy(Migrations); deployer.deploy(Migrations);

View File

@ -1,16 +1,16 @@
var Verifier = artifacts.require('Verifier'); var Verifier = artifacts.require('./Verifier.sol');
var VerifierProxy = artifacts.require('VerifierProxy'); var VerifierProxy = artifacts.require('./VerifierProxy.sol');
var Lazy = artifacts.require('Lazy'); var Lazy = artifacts.require('./Lazy.sol');
const proof1 = [["0x24d858a8ffc1766e7cccf95643f1339cb10978a5b06a6f8abad82782a3ab3efd", "0x2d0b5206a856f75a93284728f7cfa61e998868b632b11886a439add8e6150f3e"],[["0x13e6a883986efe7bb0c6e99b00c157d31ea8479283ac6c4934e42368da31e6d8", "0x0718d8dfecf7726df8a27092bac85d58767230b33a66dd8c69ca54f576361fc1"], ["0x160f03315ee7766d576122244d12bcabd24ee3c7d33e1cb05d838337a0fd0dfb", "0x2ea4c7c18ed1b8f3544a4fb3c4d95efa5543182406fef71bfda8760e407a05c7"]],["0x1111708b97dac3f087a3d8e13cfd513d7a82c619d39e9148080b600b7dae210e", "0x2a6e76f3003e65afefae71d3fe18ba26a3940e81463bf94615478cdf5daa2249"]];
const input1 = [["0x00000000000000000000000000000000c6481e22c5ff4164af680b8cfaa5e8ed", "0x000000000000000000000000000000003120eeff89c4f307c4a6faaae059ce10", "0x000000000000000000000000000000005b6d7d198c48c17c9540d29275a04662", "0x00000000000000000000000000000000f7a9aa434629a33c84eec3e16e196f27", "0x0000000000000000000000000000000000000000000000000000000000000001"]];
const proof1 = [["0x12d0dbcfc1da3ea29bc017288fceea3929401f4f12dbd0bba73781420d31aa2d","0x2811c1eaa63f4a804951bd7f994cbb6bea9df64591793b8392400e8756d1bca7"],[["0x04c33f68e1bd55be0928b086c647debcdf7aa0e3c3efc6a8efbc2596a77a0e67","0x17e7392e0e3ec2b5701e675e6e0569330d03ffffe476fc8d63cfeaa0ba1c8a97"],["0x2fc402693a54cd1b176abeed209674f2f12ced1496c6ce27ba8cf16903daa4cc","0x2c47efba3f4f260da643bb6427d08b551bb3446537d6ac4857d611be2355a446"]],["0x04d40f14694092d0f70890a20492b2b68e7eaabdcee744e519678d687c9c3ed0","0x28de140e393154b0e70b3ef12806af963a4a33b45c24e7864391093b6028fa2b"]]
const input1 = [["0x00000000000000000000000000000000c6481e22c5ff4164af680b8cfaa5e8ed","0x000000000000000000000000000000003120eeff89c4f307c4a6faaae059ce10","0x000000000000000000000000000000005b6d7d198c48c17c9540d29275a04662","0x00000000000000000000000000000000f7a9aa434629a33c84eec3e16e196f27","0x0000000000000000000000000000000000000000000000000000000000000001"]]
module.exports = async function(deployer, network, accounts) { module.exports = async function(deployer, network, accounts) {
deployer.then(async() => { deployer.then(async() => {
await deployer.deploy(Verifier) await deployer.deploy(Verifier);
await deployer.deploy(VerifierProxy, Verifier.address) await deployer.deploy(VerifierProxy, Verifier.address);
var contract = await deployer.deploy(Lazy, VerifierProxy.address) var contract = await deployer.deploy(Lazy, VerifierProxy.address);
await contract.submit([[1,2,3,4,5]],[[1,2],[[3,4],[5,6]],[7,8]]) await contract.submit([[1, 2, 3, 4, 5]], [[1, 2], [[3, 4], [5, 6]], [7, 8]]);
await contract.submit(input1,proof1) await contract.submit(input1, proof1);
});
}) };
}

View File

@ -1,22 +1,22 @@
{ {
"name": "testsuite-contract", "name": "lazy-snark",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "truffle-config.js", "main": "truffle.js",
"directories": { "directories": {
"test": "test" "test": "test"
}, },
"dependencies": { "dependencies": {
"any-promise": "^1.3.0",
"babel-polyfill": "^6.26.0", "babel-polyfill": "^6.26.0",
"babel-register": "^6.26.0", "babel-register": "^6.26.0",
"bindings": "^1.5.0",
"ganache-cli": "^6.4.1", "ganache-cli": "^6.4.1",
"openzeppelin-solidity": "^2.1.3", "truffle": "5.0.25",
"truffle": "5.0.8", "truffle-hdwallet-provider": "^1.0.0-web3one.5"
"truffle-hdwallet-provider": "1.0.5"
}, },
"devDependencies": {},
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "./node_modules/.bin/truffle test"
}, },
"author": "", "author": "",
"license": "ISC" "license": "ISC"

View File

@ -19,20 +19,29 @@ contract("Testing Lazy", accounts => {
assert.equal(task.status, 2); assert.equal(task.status, 2);
}); });
it("should pass correct proof", async () => {
let instance = await Lazy.deployed();
let task = await instance.tasks(1);
assert.equal(task.status, 0);
await instance.challenge(1);
task = await instance.tasks(1);
assert.equal(task.status, 1);
});
}); });
contract("Testing Verifier", accounts => { contract("Testing Verifier", accounts => {
const a = ["0x12d0dbcfc1da3ea29bc017288fceea3929401f4f12dbd0bba73781420d31aa2d","0x2811c1eaa63f4a804951bd7f994cbb6bea9df64591793b8392400e8756d1bca7"]; const a = ["0x12d0dbcfc1da3ea29bc017288fceea3929401f4f12dbd0bba73781420d31aa2d", "0x2811c1eaa63f4a804951bd7f994cbb6bea9df64591793b8392400e8756d1bca7"];
const b = [["0x04c33f68e1bd55be0928b086c647debcdf7aa0e3c3efc6a8efbc2596a77a0e67","0x17e7392e0e3ec2b5701e675e6e0569330d03ffffe476fc8d63cfeaa0ba1c8a97"],["0x2fc402693a54cd1b176abeed209674f2f12ced1496c6ce27ba8cf16903daa4cc","0x2c47efba3f4f260da643bb6427d08b551bb3446537d6ac4857d611be2355a446"]]; const b = [["0x04c33f68e1bd55be0928b086c647debcdf7aa0e3c3efc6a8efbc2596a77a0e67", "0x17e7392e0e3ec2b5701e675e6e0569330d03ffffe476fc8d63cfeaa0ba1c8a97"], ["0x2fc402693a54cd1b176abeed209674f2f12ced1496c6ce27ba8cf16903daa4cc", "0x2c47efba3f4f260da643bb6427d08b551bb3446537d6ac4857d611be2355a446"]];
const c = ["0x04d40f14694092d0f70890a20492b2b68e7eaabdcee744e519678d687c9c3ed0","0x28de140e393154b0e70b3ef12806af963a4a33b45c24e7864391093b6028fa2b"]; const c = ["0x04d40f14694092d0f70890a20492b2b68e7eaabdcee744e519678d687c9c3ed0", "0x28de140e393154b0e70b3ef12806af963a4a33b45c24e7864391093b6028fa2b"];
const input = ["0x00000000000000000000000000000000c6481e22c5ff4164af680b8cfaa5e8ed","0x000000000000000000000000000000003120eeff89c4f307c4a6faaae059ce10","0x000000000000000000000000000000005b6d7d198c48c17c9540d29275a04662","0x00000000000000000000000000000000f7a9aa434629a33c84eec3e16e196f27","0x0000000000000000000000000000000000000000000000000000000000000001"] const input = ["0x00000000000000000000000000000000c6481e22c5ff4164af680b8cfaa5e8ed", "0x000000000000000000000000000000003120eeff89c4f307c4a6faaae059ce10", "0x000000000000000000000000000000005b6d7d198c48c17c9540d29275a04662", "0x00000000000000000000000000000000f7a9aa434629a33c84eec3e16e196f27", "0x0000000000000000000000000000000000000000000000000000000000000001"];
it("should process proofs", async () => { it("should process proofs", async () => {
let instance = await Verifier.deployed(); let instance = await Verifier.deployed();
let result = await instance.verifyTx.call(a,b,c,input); let result = await instance.verifyTx.call(a,b,c,input);
console.log("verfifier thinks that result is " + result) console.log("verfifier thinks that result is " + result)
// assert.equal(result.valueOf(), false);
}); });
}); });

View File

@ -1,59 +1,35 @@
/*require('babel-register'); require('babel-register');
require('babel-polyfill'); require('babel-polyfill');
*/
var HDWalletProvider = require("truffle-hdwallet-provider"); var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonicRopsten = "..."; var mnemonicRinkeby = "oxygen crunch note tent verify chicken gossip shield essence runway clinic fortune";
var infuraLinkRopsten = "..."; var infuraLinkRinkeby = "https://rinkeby.infura.io/v3/198f519e2d9643d689649459edccc350";
var deployerAddressRopsten = "...";
var mnemonicKovan = "...";
var infuraLinkKovan = "...";
var deployerAddressKovan = "...";
var addressIndex = 0; // address index in MetaMask
module.exports = { module.exports = {
networks: { networks: {
development: { rinkeby: {
host: "localhost",
network_id: "*",
port: 8545,
},
coverage: {
host: "localhost",
network_id: "*",
port: 8555, // <-- If you change this, also set the port option in .solcover.js.
gas: 0xfffffffffff, // <-- Use this high gas value
gasPrice: 0x01 // <-- Use this low gas price
},
ropsten: {
provider: function() { provider: function() {
return new HDWalletProvider(mnemonicRopsten, infuraLinkRopsten, addressIndex); return new HDWalletProvider(mnemonicRinkeby, infuraLinkRinkeby, 1)
}, },
network_id: 3, from : "0x6d92a2d06758E014Da0C98d0bBBE9Ed78E964f34".toLowerCase(),
from: deployerAddressRopsten.toLowerCase(), network_id: 4
}, },
kovan: { development: {
provider: function() { host: "127.0.0.1",
return new HDWalletProvider(mnemonicKovan, infuraLinkKovan, addressIndex); port: 8545,
}, network_id: "*"
network_id: 42,
from: deployerAddressKovan.toLowerCase(),
} }
}, },
compilers: { compilers: {
solc: { solc: {
version: "0.5.4", version: "0.5.10",
settings: { settings: {
optimizer: { optimizer: {
enabled: true, enabled: true,
runs: 200 runs: 200
}
} }
}
} }
} }
// See <http://truffleframework.com/docs/advanced/configuration>
// to customize your Truffle configuration!
}; };