From c4da270b1d76a19d862116fc9abc068ab3bc901f Mon Sep 17 00:00:00 2001 From: Evgeny Marchenko Date: Sun, 23 Jun 2019 14:59:32 +0300 Subject: [PATCH 1/3] test --- truffle/contracts/VerifierProxy.sol | 9 ++++---- truffle/test/test.js | 35 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 truffle/test/test.js diff --git a/truffle/contracts/VerifierProxy.sol b/truffle/contracts/VerifierProxy.sol index 1de53ff..8b368f7 100644 --- a/truffle/contracts/VerifierProxy.sol +++ b/truffle/contracts/VerifierProxy.sol @@ -15,9 +15,10 @@ contract VerifierProxy is IVerifier { // Truffle gives `UnimplementedFeatureError: Encoding struct from calldata is not yet supported.` // that's why function is public and uses memory location modifier function isValid(Data memory data, Proof memory proof) public returns (bool) { - bytes memory payload = abi.encodeWithSelector(verifier.verifyTx.selector, proof, data); - (bool success, bytes memory r) = address(verifier).call(payload); - require(success); - return abi.decode(r, (bool)); + // bytes memory payload = abi.encodeWithSelector(verifier.verifyTx.selector, proof, data); + // (bool success, bytes memory r) = address(verifier).call(payload); + // require(success); + // return abi.decode(r, (bool)); + return verifier.verifyTx(proof.a, proof.b, proof.c, data.input); } } \ No newline at end of file diff --git a/truffle/test/test.js b/truffle/test/test.js new file mode 100644 index 0000000..cc093d3 --- /dev/null +++ b/truffle/test/test.js @@ -0,0 +1,35 @@ +const Lazy = artifacts.require('./Lazy.sol'); +const Verifier = artifacts.require('./Verifier.sol'); + + +contract("Testing Lazy", accounts => { + + it("should deploy with 2 tasks", async () => { + let instance = await Lazy.deployed(); + let tasksNum = await instance.tasksNum.call(); + assert.equal(tasksNum.valueOf(), 2); + }); + it("should verify correct proof", async () => { + let instance = await Lazy.deployed(); + console.log("let's try to verify"); + let tasksNum = await instance.challenge.call(1); + console.log("should be ok"); + }); + +}); + + +contract("Testing Verifier", accounts => { +const a = ["0x12d0dbcfc1da3ea29bc017288fceea3929401f4f12dbd0bba73781420d31aa2d","0x2811c1eaa63f4a804951bd7f994cbb6bea9df64591793b8392400e8756d1bca7"]; +const b = [["0x04c33f68e1bd55be0928b086c647debcdf7aa0e3c3efc6a8efbc2596a77a0e67","0x17e7392e0e3ec2b5701e675e6e0569330d03ffffe476fc8d63cfeaa0ba1c8a97"],["0x2fc402693a54cd1b176abeed209674f2f12ced1496c6ce27ba8cf16903daa4cc","0x2c47efba3f4f260da643bb6427d08b551bb3446537d6ac4857d611be2355a446"]]; +const c = ["0x04d40f14694092d0f70890a20492b2b68e7eaabdcee744e519678d687c9c3ed0","0x28de140e393154b0e70b3ef12806af963a4a33b45c24e7864391093b6028fa2b"]; +const input = ["0x00000000000000000000000000000000c6481e22c5ff4164af680b8cfaa5e8ed","0x000000000000000000000000000000003120eeff89c4f307c4a6faaae059ce10","0x000000000000000000000000000000005b6d7d198c48c17c9540d29275a04662","0x00000000000000000000000000000000f7a9aa434629a33c84eec3e16e196f27","0x0000000000000000000000000000000000000000000000000000000000000001"] + + it("should process proofs", async () => { + let instance = await Verifier.deployed(); + let result = await instance.verifyTx.call(a,b,c,input); + console.log("verfifier thinks that result is " + result) + // assert.equal(result.valueOf(), false); + }); + +}); \ No newline at end of file From e3c694f7765c776120903978635970fc2ccb60c0 Mon Sep 17 00:00:00 2001 From: Evgeny Marchenko Date: Sun, 23 Jun 2019 16:15:25 +0300 Subject: [PATCH 2/3] fix assert bug --- truffle/contracts/VerifierProxy.sol | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/truffle/contracts/VerifierProxy.sol b/truffle/contracts/VerifierProxy.sol index 8b368f7..c051676 100644 --- a/truffle/contracts/VerifierProxy.sol +++ b/truffle/contracts/VerifierProxy.sol @@ -15,10 +15,9 @@ contract VerifierProxy is IVerifier { // Truffle gives `UnimplementedFeatureError: Encoding struct from calldata is not yet supported.` // that's why function is public and uses memory location modifier function isValid(Data memory data, Proof memory proof) public returns (bool) { - // bytes memory payload = abi.encodeWithSelector(verifier.verifyTx.selector, proof, data); - // (bool success, bytes memory r) = address(verifier).call(payload); - // require(success); - // return abi.decode(r, (bool)); - return verifier.verifyTx(proof.a, proof.b, proof.c, data.input); + bytes memory payload = abi.encodeWithSelector(verifier.verifyTx.selector, proof.a, proof.b, proof.c, data.input); + (bool success, bytes memory r) = address(verifier).call(payload); + return success && abi.decode(r, (bool)); + // return verifier.verifyTx(proof.a, proof.b, proof.c, data.input); } } \ No newline at end of file From 97c5d00f8222b0595b583f2df766d164c6b1e319 Mon Sep 17 00:00:00 2001 From: Evgeny Marchenko Date: Sun, 23 Jun 2019 16:20:20 +0300 Subject: [PATCH 3/3] more tests --- truffle/test/test.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/truffle/test/test.js b/truffle/test/test.js index cc093d3..266eda7 100644 --- a/truffle/test/test.js +++ b/truffle/test/test.js @@ -9,11 +9,14 @@ contract("Testing Lazy", accounts => { let tasksNum = await instance.tasksNum.call(); assert.equal(tasksNum.valueOf(), 2); }); - it("should verify correct proof", async () => { + + it("should detect incorrect proof", async () => { let instance = await Lazy.deployed(); - console.log("let's try to verify"); - let tasksNum = await instance.challenge.call(1); - console.log("should be ok"); + let task = await instance.tasks(0); + assert.equal(task.status, 0); + await instance.challenge(0); + task = await instance.tasks(0); + assert.equal(task.status, 2); }); });