Browse Source

Add cargo archive, examples.

master
Thomas Kerber 2 years ago
parent
commit
9796f9b508

BIN
cargo.tar.xz View File


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

@@ -1,17 +0,0 @@
pragma solidity ^0.4.0;

contract Simple {
address private verifier;

function Simple(address _verifier) {
verifier = _verifier;
}

function add(int32 a, int32 b) public verifiable(verifier) returns (int32) {
return a + b;
}

function multi(int32 a, int32 b, int32 c) public verifying returns (int32) {
return add(add(a, b), c);
}
}

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

@@ -1,38 +0,0 @@
pragma solidity ^0.4.0;

contract Simple {
address private verifier;

event Event(int32 a);
event Event2(int32 a, int32 b);

function Simple(address _verifier) {
verifier = _verifier;
}

function simple(int32[4] arr, bool swap) private returns (int32[2] ret) {
int32 j = 0;
for(uint32 i = 0; i < 30; i++) {
j++;
}
if(swap) {
ret[0] = arr[0] + arr[1];
ret[1] = arr[2] + arr[3];
} else {
ret[0] = arr[0] + arr[3];
ret[1] = arr[2] + arr[1];
}
return ret;
}

function intermediate(int32 a, int32 b) private verifying returns (int32[2]) {
Event(a);
return simple([int32(1), 2, 3, 4], true);
}

function entry(int32 a, int32 b) public verifying returns (int32[2]) {
int32[2] memory r = intermediate(a, b);
Event2(a + b, r[0]);
return r;
}
}

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

@@ -1,35 +0,0 @@
pragma solidity ^0.4.0;

contract Simple {
address private verifier;

event Event(int32 a);
event Event2(int32 a, int32 b);

function Simple(address _verifier) {
verifier = _verifier;
}

function simple(int32 a, int32 b) public verifiable(verifier) returns (int32) {
int32 j = 0;
for(uint32 i = 0; i < 30; i++) {
j = j + a + b;
}
return j;
}

function intermediate(int32 a, int32 b) private verifying returns (int32) {
Event(a);
int32 j = 0;
for(uint32 i = 0; i < 30; i++) {
j += simple(j, b);
}
return simple(a, b);
}

function entry(int32 a, int32 b) public verifying returns (int32) {
int32 r = intermediate(a, b);
Event2(a + b, r);
return r;
}
}

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

@@ -1,17 +0,0 @@
pragma solidity ^0.4.0;

contract Sum {
address private verifier;

function Sum(address _verifier) {
verifier = _verifier;
}

function simple(int32[32] a) public verifiable(verifier) returns (int32) {
int32 s = 0;
for(uint32 i = 0; i < 32; i++) {
s = s + a[i];
}
return s;
}
}

+ 18
- 0
examples/accumulate.sol View File

@@ -0,0 +1,18 @@
pragma solidity ^0.4.0;

contract Accumulate {
address private verifier;
int32 public accumulator;

function Accumulate(address _verifier) {
verifier = _verifier;
}

function add(int32 a, int32 b) verifiable(verifier) returns (int32) {
return a + b;
}

function increment(int32 n) verifying {
accumulator = add(accumulator, n);
}
}

+ 35
- 0
examples/matrix_mul.sol View File

@@ -0,0 +1,35 @@
pragma solidity ^0.4.0;

contract MatrixMultiplication {
address private verifier;
int32[9] state;

function getState(uint idx) public constant returns (int32) {
return state[idx];
}

function MatrixMultiplication(address _verifier) {
verifier = _verifier;
for(uint8 i = 0; i < 9; i++) {
state[i] = i;
}
}

function multiply(int32[9] a, int32[9] b) verifiable(verifier) returns (int32[9] c) {
// Row index
for(uint32 i = 0; i < 3; i++) {
// Column index
for(uint32 j = 0; j < 3; j++) {
c[3*i + j] = 0;
for(uint32 k = 0; k < 3; k++) {
c[3*i + j] = c[3*i + j] + a[3*i + k] * b[3*k + j];
}
}
}
return c;
}

function square() verifying {
state = multiply(state, state);
}
}

+ 21
- 0
examples/vector_add.sol View File

@@ -0,0 +1,21 @@
pragma solidity ^0.4.0;

contract VectorAdd {
address private verifier;
int32[16] state;

function VectorAdd(address _verifier) {
verifier = _verifier;
}

function vector_add(int32[16] a, int32[16] b) verifiable(verifier) returns (int32[16] c) {
for(uint32 i = 0; i < 16; i++) {
c[i] = a[i] + b[i];
}
return c;
}

function increment(int32[16] diff) verifying {
state = vector_add(state, diff);
}
}

Loading…
Cancel
Save