Browse Source

Add cargo archive, examples.

Thomas Kerber 1 year ago
parent
commit
9796f9b508

BIN
cargo.tar.xz View File


+ 0
- 17
contract-rewrite/multitest.sol View File

@@ -1,17 +0,0 @@
1
-pragma solidity ^0.4.0;
2
-
3
-contract Simple {
4
-    address private verifier;
5
-
6
-    function Simple(address _verifier) {
7
-        verifier = _verifier;
8
-    }
9
-
10
-    function add(int32 a, int32 b) public verifiable(verifier) returns (int32) {
11
-        return a + b;
12
-    }
13
-
14
-    function multi(int32 a, int32 b, int32 c) public verifying returns (int32) {
15
-        return add(add(a, b), c);
16
-    }
17
-}

+ 0
- 38
contract-rewrite/simple-novc.sol View File

@@ -1,38 +0,0 @@
1
-pragma solidity ^0.4.0;
2
-
3
-contract Simple {
4
-    address private verifier;
5
-
6
-    event Event(int32 a);
7
-    event Event2(int32 a, int32 b);
8
-
9
-    function Simple(address _verifier) {
10
-        verifier = _verifier;
11
-    }
12
-
13
-    function simple(int32[4] arr, bool swap) private returns (int32[2] ret) {
14
-        int32 j = 0;
15
-        for(uint32 i = 0; i < 30; i++) {
16
-            j++;
17
-        }
18
-        if(swap) {
19
-            ret[0] = arr[0] + arr[1];
20
-            ret[1] = arr[2] + arr[3];
21
-        } else {
22
-            ret[0] = arr[0] + arr[3];
23
-            ret[1] = arr[2] + arr[1];
24
-        }
25
-        return ret;
26
-    }
27
-
28
-    function intermediate(int32 a, int32 b) private verifying returns (int32[2]) {
29
-        Event(a);
30
-        return simple([int32(1), 2, 3, 4], true);
31
-    }
32
-
33
-    function entry(int32 a, int32 b) public verifying returns (int32[2]) {
34
-        int32[2] memory r = intermediate(a, b);
35
-        Event2(a + b, r[0]);
36
-        return r;
37
-    }
38
-}

+ 0
- 35
contract-rewrite/simple.sol View File

@@ -1,35 +0,0 @@
1
-pragma solidity ^0.4.0;
2
-
3
-contract Simple {
4
-    address private verifier;
5
-
6
-    event Event(int32 a);
7
-    event Event2(int32 a, int32 b);
8
-
9
-    function Simple(address _verifier) {
10
-        verifier = _verifier;
11
-    }
12
-
13
-    function simple(int32 a, int32 b) public verifiable(verifier) returns (int32) {
14
-       int32 j = 0;
15
-       for(uint32 i = 0; i < 30; i++) {
16
-           j = j + a + b;
17
-       }
18
-       return j;
19
-    }
20
-
21
-    function intermediate(int32 a, int32 b) private verifying returns (int32) {
22
-        Event(a);
23
-        int32 j = 0;
24
-        for(uint32 i = 0; i < 30; i++) {
25
-            j += simple(j, b);
26
-        }
27
-        return simple(a, b);
28
-    }
29
-
30
-    function entry(int32 a, int32 b) public verifying returns (int32) {
31
-        int32 r = intermediate(a, b);
32
-        Event2(a + b, r);
33
-        return r;
34
-    }
35
-}

+ 0
- 17
contract-rewrite/sum.sol View File

@@ -1,17 +0,0 @@
1
-pragma solidity ^0.4.0;
2
-
3
-contract Sum {
4
-    address private verifier;
5
-
6
-    function Sum(address _verifier) {
7
-        verifier = _verifier;
8
-    }
9
-
10
-    function simple(int32[32] a) public verifiable(verifier) returns (int32) {
11
-       int32 s = 0;
12
-       for(uint32 i = 0; i < 32; i++) {
13
-           s = s + a[i];
14
-       }
15
-       return s;
16
-    }
17
-}

+ 18
- 0
examples/accumulate.sol View File

@@ -0,0 +1,18 @@
1
+pragma solidity ^0.4.0;
2
+
3
+contract Accumulate {
4
+    address private verifier;
5
+    int32 public accumulator;
6
+
7
+    function Accumulate(address _verifier) {
8
+        verifier = _verifier;
9
+    }
10
+
11
+    function add(int32 a, int32 b) verifiable(verifier) returns (int32) {
12
+        return a + b;
13
+    }
14
+
15
+    function increment(int32 n) verifying {
16
+        accumulator = add(accumulator, n);
17
+    }
18
+}

+ 35
- 0
examples/matrix_mul.sol View File

@@ -0,0 +1,35 @@
1
+pragma solidity ^0.4.0;
2
+
3
+contract MatrixMultiplication {
4
+    address private verifier;
5
+    int32[9] state;
6
+
7
+    function getState(uint idx) public constant returns (int32) {
8
+        return state[idx];
9
+    }
10
+
11
+    function MatrixMultiplication(address _verifier) {
12
+        verifier = _verifier;
13
+        for(uint8 i = 0; i < 9; i++) {
14
+            state[i] = i;
15
+        }
16
+    }
17
+
18
+    function multiply(int32[9] a, int32[9] b) verifiable(verifier) returns (int32[9] c) {
19
+        // Row index
20
+        for(uint32 i = 0; i < 3; i++) {
21
+            // Column index
22
+            for(uint32 j = 0; j < 3; j++) {
23
+                c[3*i + j] = 0;
24
+                for(uint32 k = 0; k < 3; k++) {
25
+                    c[3*i + j] = c[3*i + j] + a[3*i + k] * b[3*k + j];
26
+                }
27
+            }
28
+        }
29
+        return c;
30
+    }
31
+
32
+    function square() verifying {
33
+        state = multiply(state, state);
34
+    }
35
+}

+ 21
- 0
examples/vector_add.sol View File

@@ -0,0 +1,21 @@
1
+pragma solidity ^0.4.0;
2
+
3
+contract VectorAdd {
4
+    address private verifier;
5
+    int32[16] state;
6
+
7
+    function VectorAdd(address _verifier) {
8
+        verifier = _verifier;
9
+    }
10
+
11
+    function vector_add(int32[16] a, int32[16] b) verifiable(verifier) returns (int32[16] c) {
12
+        for(uint32 i = 0; i < 16; i++) {
13
+            c[i] = a[i] + b[i];
14
+        }
15
+        return c;
16
+    }
17
+
18
+    function increment(int32[16] diff) verifying {
19
+        state = vector_add(state, diff);
20
+    }
21
+}

Loading…
Cancel
Save