Skip to content
Open
Show file tree
Hide file tree
Changes from 115 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
801cfbd
adds quarc to command line options
Oct 1, 2022
d3c1ae1
feat: adds main structure
Oct 1, 2022
d869b06
feat: adds write function (template), fixes format
Oct 1, 2022
cdad252
refact: changes qubit struct for an enum
Oct 1, 2022
b6bb624
feat: easy operators done
Oct 1, 2022
e880aa1
feat: more workflow
Oct 1, 2022
6a4dc06
feat: bitvector not gate implemented
Oct 1, 2022
84842d4
feat: quarc does unrolling
Oct 1, 2022
11d25b2
fix: process next node correctly
Oct 1, 2022
3a81ae2
removes unused variables
Oct 3, 2022
b700b68
add dynamic quantum memory option to cmd
Oct 3, 2022
8843ba0
feat: new unitaries
Oct 3, 2022
553db8c
add barriers in bad and next before recursion starts
Oct 3, 2022
f1fb22b
adds reminder of swaps
Oct 3, 2022
85edb77
refact: changes data type of circuit stack
Oct 3, 2022
17ef2ff
refact: remove qubit struct
Oct 3, 2022
23f70d1
feat: uncompute
Oct 4, 2022
1389ddd
refact: solves merge conflict
Oct 4, 2022
dbc82dc
feat: Node::And
Oct 7, 2022
315aeb1
fix: makes better use of qunatum dynamic memory in Node::And
Oct 7, 2022
a3dee13
refact: dynamic memory is a pool
Oct 7, 2022
3680c1a
feat: Node::Eq
Oct 7, 2022
7caf4b2
refact: clippy suggestions
Oct 7, 2022
c0d439e
refact: single match for read and write
Oct 7, 2022
1a14808
feat: Node::Ite
Oct 7, 2022
4e5607c
feat: Node::Add
Oct 8, 2022
bc257b0
feat: Node::Sub
Oct 8, 2022
097c2ed
feat: Node::Ult
Oct 8, 2022
1f9e58f
feat: Node::Mul
Oct 8, 2022
1b6ce4d
feat: Div and Rem
Oct 8, 2022
3137e1d
refact: clippy + fmt
Oct 8, 2022
cd4cfcb
feat: builds oracle output
Oct 9, 2022
1de1a48
refact: clippy + fmt
Oct 9, 2022
064d61d
fix: bug in and
Oct 9, 2022
d8d507e
refact: adds some checks
Oct 9, 2022
4ae93e1
test quarc
Oct 11, 2022
a1f9b7f
refact: fmt
Oct 11, 2022
c4b2d06
debug: wrote tests
Oct 13, 2022
5e553b7
adds test files
Oct 13, 2022
5d86118
feat: input checker for quarc
Oct 15, 2022
d3f43dc
feat: print stats when building q. circuit
Oct 16, 2022
862ff47
refact: clippy suggestions
Oct 16, 2022
d17768e
fix: bug in init
Oct 22, 2022
9e5e30d
refactor: cargo fmt
Oct 23, 2022
ef1571d
refactor: update test files for quarc
Oct 23, 2022
5e0f96d
fix: bugs and tests
Oct 23, 2022
3798797
fix: adjusts call to evaluate input
Oct 23, 2022
582237e
refactor: update div, mul and rem debug files
Oct 23, 2022
f104dbe
refactor: removes test file
Oct 23, 2022
7a941e7
debug: round1 tests succeed
Oct 23, 2022
1b715a3
refactor: clippy
Oct 25, 2022
bddce39
refactor: clippy suggestions
Oct 25, 2022
dfa7ef9
debug: corrected logic
Oct 25, 2022
5a33782
refactor: replace assert!(false)
Oct 25, 2022
e8ea02a
refactor: clean up code
Oct 26, 2022
c4ba769
refactor: changes folder name test files and adds new test files
Oct 29, 2022
5dbe4c6
refactor: removes old files
Oct 29, 2022
3554e03
update files
Nov 2, 2022
d522e82
debug: setup of experiments (this will fail, need to figure out const…
Nov 2, 2022
b852553
refactor: some files deleted
Nov 2, 2022
224e682
refactor: update cargo file
Nov 2, 2022
65e7a6c
fix bug in get last state
Nov 9, 2022
2731e37
debug
Nov 13, 2022
4818a9b
qubot in main workflow
Nov 13, 2022
b4aafc0
feat: optimized ancilla usage in multiply
Nov 13, 2022
e24ff67
refactor: cargo fmt
Nov 13, 2022
0cc97d3
refact: remove printlns
Nov 13, 2022
2ba01ea
refact: more efficieny in btor2 and operator
Nov 13, 2022
bc22a0e
feat: optimize eq
Nov 19, 2022
45fb70f
Merge branch 'feat-quarc' of https://github.com/cksystemsgroup/unicor…
Nov 19, 2022
5b3e549
paper checkpoint
Jan 5, 2023
b0bddaa
paper checkpoint
Jan 5, 2023
a67024e
refact: change imports (api prep)
Jan 10, 2023
58eaee7
refact: move z3solver_impl to its own file
Jan 10, 2023
371d284
debug: opt any
Jan 10, 2023
261af9f
refactor: add feature z3 flag
Jan 10, 2023
c77b35c
make quarc::get_constant public
Jan 11, 2023
fb87a27
refactor: moves boolecotr_impl to its own file
Jan 21, 2023
f9c97a9
fix: import boolector_impl in main
Jan 21, 2023
2bef8cf
refact: moves input evaluator tool for quarc outside class
Jan 21, 2023
3e60794
refactor, import evaluate_input
Jan 21, 2023
08819aa
feat: adds get_qubit_dependency
Jan 21, 2023
498e160
refact: change get_qubit_dep return type
Jan 21, 2023
3f29d99
feat: get_dep_data
Jan 21, 2023
487777e
refact: type in function name
Jan 21, 2023
2f37795
feat: new functions added for quarc api
Jan 21, 2023
5a6a822
refact: quarc api functions
Jan 21, 2023
3d85d7b
unicorn api
Jan 22, 2023
2266d7a
refact: README
Jan 22, 2023
2fbdfb5
refact: readme
Jan 22, 2023
da4d1f1
refact: readme
Jan 22, 2023
cf5080e
adds example to readme file
Jan 22, 2023
d8ae2f7
feat: example with qir
Jan 22, 2023
16f70d1
refact: remove print
Jan 22, 2023
1747d49
refactor: changes a file name
Jan 23, 2023
3303ac2
chore: solves merge conflicts
Jan 23, 2023
b6f7fd3
refactor: removes copied directory
Jan 23, 2023
f49006e
chore: remove file
Jan 23, 2023
d159044
Merge branch 'main' into opt-quarc-paper
smml1996 Jan 23, 2023
a58ae7f
fix: imports
Jan 23, 2023
31c2e5c
fix imports
Jan 23, 2023
2c813c7
refactor: cargo fmt
Jan 23, 2023
6ecf256
fix imports
Jan 24, 2023
81ecd54
refactor: cargo fmt
Jan 24, 2023
106f8b5
refactor: removes boolector_impl from sat_solver.rs and fix imports
Jan 24, 2023
f2f5550
Merge branch 'main' into opt-quarc-paper
smml1996 Jan 24, 2023
95b3ae9
refactor: fix smt solvers after merge with main
Jan 24, 2023
3c9c9a4
refactor: cargo fmt
Jan 24, 2023
6bc2c3e
fix: imports sat solver
Jan 24, 2023
f20468a
fix: conditional import sat solvers and return type in main
Jan 24, 2023
335c044
refactor: clippy suggestions
Jan 24, 2023
f1aa952
removes panic in has_depth_in_name
Jan 25, 2023
874dd6a
fix: removes uncomputation in OR of bad states
Jan 26, 2023
2b3d1be
fix: define ccx gates
Jan 26, 2023
d9d8780
Update README.md
smml1996 Feb 1, 2023
8abdc65
refactor: removes println
smml1996 Feb 12, 2023
7476b2d
refactor: sets smt solver feature flag in mod.rs
smml1996 Feb 12, 2023
d3031c6
Merge branch 'main' into opt-quarc-paper
smml1996 Feb 17, 2023
4c1544a
fix: merge main. moves smt files correctly
smml1996 Feb 17, 2023
ea1d3c5
refactor change Node::Div for Node::Divu
smml1996 Feb 17, 2023
a140095
Merge branch 'main' into opt-quarc-paper
smml1996 Feb 21, 2023
a6f38bc
debug: fix imports
smml1996 Mar 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,59 @@ selfie -c <SOURCE_CODE_FILE> -o <BINARY_FILE>

To display the available subcommands that Unicorn has you can type `./target/debug/unicorn --help`, or to display subcommand options `./target/debug/unicorn <SUBCOMMAND> --help`.

Currently, there are 3 main commands:
### 1. Generate a BTOR2 file from a binary
We give a short tutorial for 3 commands in the following sections:

<ol>
<li><a href="#beator">beator</a> to generate BTOR2 files.</li>
<li><a href="#quarc">quarc</a> to generate quantum circuits.</li>
<li><a href="#qubot">qubot</a> to generate QUBO/ISING models.</li>
</ol>

<h4 id="beator">1. Generate a BTOR2 file from a binary</h3>

```sh
./target/debug/unicorn beator <BINARY_FILE> --unroll <NUM_STATE_TRANSITIONS> --solver boolector --out <BTOR2_FILE>
```
The above command generates a BTOR2 file, while the unroll option specifies how many state transitions Unicorn should represent in the BTOR2 file. In this example, Unicorn optimizes the number of variables using Boolector.

There are more options. For example, you can add `--bitblast` to the command, and the BTOR2 file will represent a logic (combinatorial) circuit.

<h4 id="quarc"> 2. Quantum Circuits with QUARC </h4>
QUARC builds quantum circuits, more concretely it builds oracles for Grover's algorithm. You can build and test a quantum circuit:

```sh
target/debug/unicorn quarc <INPUT_FILE> --unroll <NUM_STATE_TRANSITIONS> --solver <SMT_SOLVER> --inputs <TEST_THESE_INPUTS>
```

Which for example can be

```sh
target/debug/unicorn quarc examples/selfie/d.m --unroll 84 --inputs 42-49-0
```

The above command will unroll the finite state machine of the program `d.m` 84 times, and it will execute inputs 42, 49 and 0 in the oracle. The output is the following:

```
******* QUANTUM CIRCUIT STATS ********
Qubits required: 384
Total gates: 2968
Single-qubit gates: 343
MCX gates: 2625
Max. controls in MCX: 18
**************************************
[42] evaluates to true

[49] evaluates to true

[0] evaluates to false
```
Meaning that inputs `42` and `49` makes the oracle evaluate to `true`, while input `0` makes de oracle evaluate to `false`.

A Python binding is coming soon!

<h4 id="qubot"> 3. QUBOT </h4>
Similarly, QUBOT can also build and test its models.

### 2. Generate and/or test a QUBO of the binary
```sh
./target/debug/unicorn qubot <BINARY_FILE> --unroll <NUM_STATE_TRANSITIONS> --solver <SMT_SOLVER> --out <QUBO_FILE> --inputs 42,32;34
```
Expand Down
10 changes: 10 additions & 0 deletions examples/quarc/add.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 sort bitvec 8
2 input 1
3 input 1
4 state 1
9 constd 1 0
10 init 1 4 9
5 add 1 2 3
6 next 1 4 5
7 eq 1 4 4
8 bad 7
9 changes: 9 additions & 0 deletions examples/quarc/add2.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1 sort bitvec 8
2 input 1
4 state 1
9 constd 1 10
10 init 1 4 9
5 add 1 4 2
6 next 1 4 5
7 eq 1 4 4
8 bad 7
10 changes: 10 additions & 0 deletions examples/quarc/and.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 sort bitvec 8
2 input 1
3 input 1
4 state 1
9 constd 1 0
10 init 1 4 9
5 and 1 2 3
6 next 1 4 5
7 eq 1 4 4
8 bad 7
9 changes: 9 additions & 0 deletions examples/quarc/and2.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1 sort bitvec 8
2 input 1
4 state 1
9 constd 1 241
10 init 1 4 9
5 and 1 4 2
6 next 1 4 5
7 eq 1 4 4
8 bad 7
10 changes: 10 additions & 0 deletions examples/quarc/div.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 sort bitvec 8
2 input 1
3 input 1
4 state 1
9 constd 1 0
10 init 1 4 9
5 udiv 1 2 3
6 next 1 4 5
7 eq 1 4 4
8 bad 7
9 changes: 9 additions & 0 deletions examples/quarc/div2.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1 sort bitvec 8
2 input 1
4 state 1
9 constd 1 50
10 init 1 4 9
5 udiv 1 2 4
6 next 1 4 5
7 eq 1 4 4
8 bad 7
5 changes: 5 additions & 0 deletions examples/quarc/eq.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 sort bitvec 1
2 input 1
3 input 1
4 eq 1 2 3
5 bad 4
5 changes: 5 additions & 0 deletions examples/quarc/eq8.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 sort bitvec 8
2 input 1
3 input 1
4 eq 1 2 3
5 bad 4
7 changes: 7 additions & 0 deletions examples/quarc/eq82.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1 sort bitvec 8
2 input 1
3 state 1
9 constd 1 0
10 init 1 3 9
4 eq 1 2 3
5 bad 4
11 changes: 11 additions & 0 deletions examples/quarc/ite.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1 sort bitvec 1
2 sort bitvec 8
3 input 1
4 input 2
5 input 2
6 ite 1 3 4 5
10 state 2
11 constd 1 241
12 init 1 10 11
7 next 1 10 6
9 bad 3
10 changes: 10 additions & 0 deletions examples/quarc/ite2.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 sort bitvec 1
2 sort bitvec 8
3 input 1
4 state 2
11 constd 2 0
12 init 2 4 11
5 input 2
6 ite 1 3 5 4
7 next 1 4 6
9 bad 3
10 changes: 10 additions & 0 deletions examples/quarc/mul.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 sort bitvec 8
2 input 1
3 input 1
4 state 1
9 constd 1 0
10 init 1 4 9
5 mul 1 2 3
6 next 1 4 5
7 eq 1 4 4
8 bad 7
9 changes: 9 additions & 0 deletions examples/quarc/mul2.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1 sort bitvec 8
2 input 1
4 state 1
9 constd 1 3
10 init 1 4 9
5 mul 1 2 4
6 next 1 4 5
7 eq 1 4 4
8 bad 7
6 changes: 6 additions & 0 deletions examples/quarc/not.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1 sort bitvec 8
3 input 1
4 not 1 3
5 next 1 3 4
7 eq 1 3 3
8 bad 7
10 changes: 10 additions & 0 deletions examples/quarc/rem.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 sort bitvec 8
2 input 1
3 input 1
4 state 1
9 constd 1 0
10 init 1 4 9
5 urem 1 2 3
6 next 1 4 5
7 eq 1 4 4
8 bad 7
10 changes: 10 additions & 0 deletions examples/quarc/sub.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 sort bitvec 8
2 input 1
3 input 1
4 state 1
9 constd 1 0
10 init 1 4 9
5 sub 1 2 3
6 next 1 4 5
7 eq 1 4 4
8 bad 7
7 changes: 7 additions & 0 deletions examples/quarc/sub2.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1 sort bitvec 8
2 input 1
4 state 1
9 constd 1 255
10 init 1 4 9
5 sub 1 4 2
6 next 1 4 5
5 changes: 5 additions & 0 deletions examples/quarc/ult.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 sort bitvec 8
2 input 1
3 input 1
4 ult 1 2 3
5 bad 4
7 changes: 7 additions & 0 deletions examples/quarc/ult2.btor2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1 sort bitvec 8
2 input 1
3 state 1
9 constd 1 213
10 init 1 3 9
4 ult 1 2 3
5 bad 4
10 changes: 10 additions & 0 deletions examples/selfie/d.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
uint64_t* x;
uint64_t main() { uint64_t a;
x = malloc(1); // rounded up to 8
// touch to trigger page fault here
*x = 0;
// read 1 byte from console into x
read(0, x, 1);
a = *x;
a = *(x + a); // segfault if input != 0
}
Binary file added examples/selfie/d.m
Binary file not shown.
25 changes: 25 additions & 0 deletions examples/selfie/division-by-zero-3-35.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
uint64_t main() {
uint64_t a;
uint64_t* x;

x = malloc(8);

*x = 0; // touch memory

read(0, x, 1);

*x = *x - 48;

// division by zero if the input is '0' (== 48 == b00110000)
a = 41 + (1 / *x);

// division by zero if the input is '2' (== 50 == b00110010)
if (*x == 2)
a = 41 + (1 / 0);

if (a == 42)
// non-zero exit code if the input is '1' (== 49 == b00110001)
return 1;
else
return 0;
}
Binary file added examples/selfie/division-by-zero-3-35.m
Binary file not shown.
59 changes: 59 additions & 0 deletions examples/selfie/memory-access-fail-1-35.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
uint64_t main() {
uint64_t* x;
uint64_t* v;

x = malloc(8);

*x = 0; // touch memory

// access code segment by reaching over data segment with _bump variable, no --check-block-access required

v = x + -(4096 / 8) + -1;

*v = *v;
open(v, 32768, 0);
read(0, v, 1);
write(1, v, 1);

// access memory right above 4GB, avoiding big integer in data segment, no --check-block-access required

v = x + ((uint64_t*) (4 * 1024 * 1024 * 1024) - x);

*v = *v;
open(v, 32768, 0);
read(0, v, 1);
write(1, v, 1);

// access word-unaligned address, no --check-block-access required

v = (uint64_t*) ((uint64_t) x + 1);

*v = *v;
open(v, 32768, 0);
read(0, v, 1);
write(1, v, 1);

// access memory right above memory block but well below 4GB, requires --check-block-access

v = x + 1;

*v = *v;
open(v, 32768, 0);
read(0, v, 1);
write(1, v, 1);

// unsafe access right above memory block even without pointer arithmetic
read(0, x, 9);
write(1, x, 9);

// access memory right below memory block but still above code segment, due to _bump variable, requires --check-block-access

v = x + -1;

*v = *v;
open(v, 32768, 0);
read(0, v, 1);
write(1, v, 1);

return 0;
}
Binary file added examples/selfie/memory-access-fail-1-35.m
Binary file not shown.
27 changes: 27 additions & 0 deletions examples/selfie/nested-if-else-1-35.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
uint64_t main() {
uint64_t a;
uint64_t* x;

a = 40;
x = malloc(8);

*x = 0; // touch memory

read(0, x, 1);

if (*x > 48) {
*x = *x - 47;

if (*x == 2)
a = a + *x;
else
a = a + (*x * 0);
} else
a = a + (*x * 0);

if (a == 42)
// non-zero exit code if the input is '1' (== 49 == b00110001)
return 1;
else
return 0;
}
Binary file added examples/selfie/nested-if-else-1-35.m
Binary file not shown.
28 changes: 28 additions & 0 deletions examples/selfie/nested-if-else-reverse-1-35.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
uint64_t main() {
uint64_t a;
uint64_t* x;

a = 40;
x = malloc(8);

*x = 0; // touch memory

read(0, x, 1);

if (*x <= 48)
a = a + (*x * 0);
else {
*x = *x - 47;

if (*x != 2)
a = a + (*x * 0);
else
a = a + *x;
}

if (a == 42)
// non-zero exit code if the input is '1' (== 49 == b00110001)
return 1;
else
return 0;
}
Binary file added examples/selfie/nested-if-else-reverse-1-35.m
Binary file not shown.
Loading