1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

update contracts to 0.5, add solcjs test on verifier in integration

This commit is contained in:
schaeff 2019-02-28 13:25:51 +01:00
parent 3c918d6408
commit c5c9ed0662
7 changed files with 66 additions and 42 deletions

View file

@ -11,6 +11,9 @@ ENV ZOKRATES_HOME=/home/zokrates/ZoKrates/stdlib/
COPY ./scripts/install_libsnark_prerequisites.sh /tmp/
RUN /tmp/install_libsnark_prerequisites.sh
COPY ./scripts/install_solc_prerequisites_deb.sh /tmp/
RUN /tmp/install_solc_prerequisites_deb.sh
USER zokrates
WORKDIR /home/zokrates

View file

@ -0,0 +1,7 @@
#!/bin/bash
apt-get update -y
apt-get install -y curl gnupg sudo build-essential
curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt-get install -y nodejs
npm i -g solc

View file

@ -195,6 +195,22 @@ mod integration {
.succeeds()
.unwrap();
let mut verifier_file = File::open(&verification_contract_path).unwrap();
let mut verifier_string = String::new();
verifier_file.read_to_string(&mut verifier_string).unwrap();
let solc_json_input = format!(
r#"{{"language": "Solidity", "sources": {{ "this": {{ "content": {:?} }} }} }}"#,
verifier_string
);
assert_cli::Assert::command(&["solcjs", "--standard-json"])
.stdin(&solc_json_input)
.succeeds()
.stdout()
.doesnt_contain(r#""severity":"error""#)
.unwrap();
// GENERATE-PROOF
assert_cli::Assert::command(&[
"../target/release/zokrates",

View file

@ -37,5 +37,4 @@ assert_cli = "0.5"
[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }
cmake = "0.1.31"
parity-wasm = "0.35.3"
git2 = "0.8.0"

View file

@ -206,7 +206,7 @@ contract Verifier {
Pairing.G2Point B;
Pairing.G1Point C;
}
function verifyingKey() pure internal returns (VerifyingKey vk) {
function verifyingKey() pure internal returns (VerifyingKey memory vk) {
vk.H = Pairing.G2Point(<%vk_h%>);
vk.Galpha = Pairing.G1Point(<%vk_g_alpha%>);
vk.Hbeta = Pairing.G2Point(<%vk_h_beta%>);
@ -215,7 +215,7 @@ contract Verifier {
vk.query = new Pairing.G1Point[](<%vk_query_length%>);
<%vk_query_pts%>
}
function verify(uint[] input, Proof proof) internal returns (uint) {
function verify(uint[] memory input, Proof memory proof) internal returns (uint) {
VerifyingKey memory vk = verifyingKey();
require(input.length + 1 == vk.query.length);
// Compute the linear combination vk_x
@ -237,10 +237,10 @@ contract Verifier {
}
event Verified(string s);
function verifyTx(
uint[2] a,
uint[2][2] b,
uint[2] c,
uint[<%vk_input_length%>] input
uint[2] memory a,
uint[2][2] memory b,
uint[2] memory c,
uint[<%vk_input_length%>] memory input
) public returns (bool r) {
Proof memory proof;
proof.A = Pairing.G1Point(a[0], a[1]);

View file

@ -210,7 +210,7 @@ const CONTRACT_TEMPLATE: &str = r#"contract Verifier {
Pairing.G1Point K;
Pairing.G1Point H;
}
function verifyingKey() pure internal returns (VerifyingKey vk) {
function verifyingKey() pure internal returns (VerifyingKey memory vk) {
vk.A = Pairing.G2Point(<%vk_a%>);
vk.B = Pairing.G1Point(<%vk_b%>);
vk.C = Pairing.G2Point(<%vk_c%>);
@ -221,7 +221,7 @@ const CONTRACT_TEMPLATE: &str = r#"contract Verifier {
vk.IC = new Pairing.G1Point[](<%vk_ic_length%>);
<%vk_ic_pts%>
}
function verify(uint[] input, Proof proof) internal returns (uint) {
function verify(uint[] memory input, Proof memory proof) internal returns (uint) {
VerifyingKey memory vk = verifyingKey();
require(input.length + 1 == vk.IC.length);
// Compute the linear combination vk_x
@ -246,15 +246,15 @@ const CONTRACT_TEMPLATE: &str = r#"contract Verifier {
}
event Verified(string s);
function verifyTx(
uint[2] a,
uint[2] a_p,
uint[2][2] b,
uint[2] b_p,
uint[2] c,
uint[2] c_p,
uint[2] h,
uint[2] k,
uint[<%vk_input_length%>] input
uint[2] memory a,
uint[2] memory a_p,
uint[2][2] memory b,
uint[2] memory b_p,
uint[2] memory c,
uint[2] memory c_p,
uint[2] memory h,
uint[2] memory k,
uint[<%vk_input_length%>] memory input
) public returns (bool r) {
Proof memory proof;
proof.A = Pairing.G1Point(a[0], a[1]);

View file

@ -182,8 +182,6 @@ pub fn prepare_generate_proof<T: Field>(
pub const SOLIDITY_G2_ADDITION_LIB: &str = r#"// This file is LGPL3 Licensed
pragma solidity ^0.4.19;
/**
* @title Elliptic curve operations on twist points for alt_bn128
* @author Mustafa Al-Bassam (mus@musalbas.com)
@ -440,7 +438,7 @@ library BN256G2 {
uint256 pt1zx, uint256 pt1zy,
uint256 pt2xx, uint256 pt2xy,
uint256 pt2yx, uint256 pt2yy,
uint256 pt2zx, uint256 pt2zy) internal pure returns (uint256[6] pt3) {
uint256 pt2zx, uint256 pt2zy) internal pure returns (uint256[6] memory pt3) {
if (pt1zx == 0 && pt1zy == 0) {
(
pt3[PTXX], pt3[PTXY],
@ -451,7 +449,7 @@ library BN256G2 {
pt2yx, pt2yy,
pt2zx, pt2zy
);
return;
return pt3;
} else if (pt2zx == 0 && pt2zy == 0) {
(
pt3[PTXX], pt3[PTXY],
@ -462,7 +460,7 @@ library BN256G2 {
pt1yx, pt1yy,
pt1zx, pt1zy
);
return;
return pt3;
}
(pt2yx, pt2yy) = _FQ2Mul(pt2yx, pt2yy, pt1zx, pt1zy); // U1 = y2 * z1
@ -477,7 +475,7 @@ library BN256G2 {
pt3[PTYX], pt3[PTYY],
pt3[PTZX], pt3[PTZY]
) = _ECTwistDoubleJacobian(pt1xx, pt1xy, pt1yx, pt1yy, pt1zx, pt1zy);
return;
return pt3;
}
(
pt3[PTXX], pt3[PTXY],
@ -488,7 +486,7 @@ library BN256G2 {
1, 0,
0, 0
);
return;
return pt3;
}
(pt2zx, pt2zy) = _FQ2Mul(pt1zx, pt1zy, pt2zx, pt2zy); // W = z1 * z2
@ -546,7 +544,7 @@ library BN256G2 {
uint256 pt1xx, uint256 pt1xy,
uint256 pt1yx, uint256 pt1yy,
uint256 pt1zx, uint256 pt1zy
) internal pure returns(uint256[6] pt2) {
) internal pure returns(uint256[6] memory pt2) {
while (d != 0) {
if ((d & 1) != 0) {
pt2 = _ECTwistAddJacobian(
@ -572,6 +570,7 @@ library BN256G2 {
}
}
"#;
pub const SOLIDITY_PAIRING_LIB : &str = r#"// This file is MIT Licensed.
@ -581,7 +580,7 @@ pub const SOLIDITY_PAIRING_LIB : &str = r#"// This file is MIT Licensed.
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
pragma solidity ^0.4.14;
pragma solidity ^0.5.0;
library Pairing {
struct G1Point {
uint X;
@ -593,11 +592,11 @@ library Pairing {
uint[2] Y;
}
/// @return the generator of G1
function P1() pure internal returns (G1Point) {
function P1() pure internal returns (G1Point memory) {
return G1Point(1, 2);
}
/// @return the generator of G2
function P2() pure internal returns (G2Point) {
function P2() pure internal returns (G2Point memory) {
return G2Point(
[11559732032986387107991004021392285783925812861821192530917403151452391805634,
10857046999023057135944570762232829481370756359578518086990519993285655852781],
@ -606,7 +605,7 @@ library Pairing {
);
}
/// @return the negation of p, i.e. p.addition(p.negate()) should be zero.
function negate(G1Point p) pure internal returns (G1Point) {
function negate(G1Point memory p) pure internal returns (G1Point memory) {
// The prime q in the base field F_q for G1
uint q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
if (p.X == 0 && p.Y == 0)
@ -614,7 +613,7 @@ library Pairing {
return G1Point(p.X, q - (p.Y % q));
}
/// @return the sum of two points of G1
function addition(G1Point p1, G1Point p2) internal returns (G1Point r) {
function addition(G1Point memory p1, G1Point memory p2) internal returns (G1Point memory r) {
uint[4] memory input;
input[0] = p1.X;
input[1] = p1.Y;
@ -629,12 +628,12 @@ library Pairing {
require(success);
}
/// @return the sum of two points of G2
function addition(G2Point p1, G2Point p2) internal pure returns (G2Point r) {
function addition(G2Point memory p1, G2Point memory p2) internal pure returns (G2Point memory r) {
(r.X[1], r.X[0], r.Y[1], r.Y[0]) = BN256G2.ECTwistAdd(p1.X[1],p1.X[0],p1.Y[1],p1.Y[0],p2.X[1],p2.X[0],p2.Y[1],p2.Y[0]);
}
/// @return the product of a point on G1 and a scalar, i.e.
/// p == p.scalar_mul(1) and p.addition(p) == p.scalar_mul(2) for all points p.
function scalar_mul(G1Point p, uint s) internal returns (G1Point r) {
function scalar_mul(G1Point memory p, uint s) internal returns (G1Point memory r) {
uint[3] memory input;
input[0] = p.X;
input[1] = p.Y;
@ -651,7 +650,7 @@ library Pairing {
/// e(p1[0], p2[0]) * .... * e(p1[n], p2[n]) == 1
/// For example pairing([P1(), P1().negate()], [P2(), P2()]) should
/// return true.
function pairing(G1Point[] p1, G2Point[] p2) internal returns (bool) {
function pairing(G1Point[] memory p1, G2Point[] memory p2) internal returns (bool) {
require(p1.length == p2.length);
uint elements = p1.length;
uint inputSize = elements * 6;
@ -676,7 +675,7 @@ library Pairing {
return out[0] != 0;
}
/// Convenience method for a pairing check for two pairs.
function pairingProd2(G1Point a1, G2Point a2, G1Point b1, G2Point b2) internal returns (bool) {
function pairingProd2(G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2) internal returns (bool) {
G1Point[] memory p1 = new G1Point[](2);
G2Point[] memory p2 = new G2Point[](2);
p1[0] = a1;
@ -687,9 +686,9 @@ library Pairing {
}
/// Convenience method for a pairing check for three pairs.
function pairingProd3(
G1Point a1, G2Point a2,
G1Point b1, G2Point b2,
G1Point c1, G2Point c2
G1Point memory a1, G2Point memory a2,
G1Point memory b1, G2Point memory b2,
G1Point memory c1, G2Point memory c2
) internal returns (bool) {
G1Point[] memory p1 = new G1Point[](3);
G2Point[] memory p2 = new G2Point[](3);
@ -703,10 +702,10 @@ library Pairing {
}
/// Convenience method for a pairing check for four pairs.
function pairingProd4(
G1Point a1, G2Point a2,
G1Point b1, G2Point b2,
G1Point c1, G2Point c2,
G1Point d1, G2Point d2
G1Point memory a1, G2Point memory a2,
G1Point memory b1, G2Point memory b2,
G1Point memory c1, G2Point memory c2,
G1Point memory d1, G2Point memory d2
) internal returns (bool) {
G1Point[] memory p1 = new G1Point[](4);
G2Point[] memory p2 = new G2Point[](4);