-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
added multiple new detectors
- detector_emptyf - detector_magicv - detector_susinst - detector_divrd - detector_downcast
Showing
34 changed files
with
519 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "vanguard" | ||
version = "0.0.4" | ||
version = "0.0.5" | ||
authors = [ | ||
{ name="Yanju Chen", email="[email protected]" }, | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.env | ||
*.avm | ||
*.prover | ||
*.verifier | ||
outputs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# emptyf0.aleo | ||
|
||
## Build Guide | ||
|
||
To compile this Aleo program, run: | ||
```bash | ||
snarkvm build | ||
``` | ||
|
||
To execute this Aleo program, run: | ||
```bash | ||
snarkvm run hello | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
program emptyf0.aleo; | ||
|
||
|
||
|
||
function vanguard_helper: | ||
cast true into r0 as [boolean; 1u32]; | ||
output r0 as [boolean; 1u32].private; | ||
|
||
|
||
function ex0: | ||
|
||
|
||
function ex1: | ||
async ex1 into r0; | ||
output 9u8 as u8.private; | ||
output r0 as emptyf0.aleo/ex1.future; | ||
|
||
finalize ex1: | ||
assert.eq true true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"program": "emptyf0.aleo", | ||
"version": "0.0.0", | ||
"description": "", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"program": "emptyf0.aleo", | ||
"version": "0.0.0", | ||
"description": "", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// The 'emptyf0' program. | ||
program emptyf0.aleo { | ||
// by default, arguments without visibility are private | ||
// but in finalize, they have to be public | ||
transition vanguard_helper() -> [bool; 2] { | ||
return [ | ||
label_ex0, label_ex1, | ||
]; | ||
} | ||
|
||
const label_ex0: bool = true; | ||
transition ex0() { | ||
} | ||
|
||
const label_ex1: bool = true; | ||
transition ex1() -> u8 { | ||
return 9u8 then finalize(); | ||
} | ||
finalize ex1() { | ||
assert(true); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.env | ||
*.avm | ||
*.prover | ||
*.verifier | ||
outputs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# magicv0.aleo | ||
|
||
## Build Guide | ||
|
||
To compile this Aleo program, run: | ||
```bash | ||
snarkvm build | ||
``` | ||
|
||
To execute this Aleo program, run: | ||
```bash | ||
snarkvm run hello | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
program magicv0.aleo; | ||
|
||
|
||
|
||
function vanguard_helper: | ||
cast true true into r0 as [boolean; 2u32]; | ||
output r0 as [boolean; 2u32].private; | ||
|
||
|
||
function ex0: | ||
output aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc as address.private; | ||
|
||
|
||
function ex1: | ||
output 123u8 as u8.private; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"program": "magicv0.aleo", | ||
"version": "0.0.0", | ||
"description": "", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"program": "magicv0.aleo", | ||
"version": "0.0.0", | ||
"description": "", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// The 'magicv0' program. | ||
program magicv0.aleo { | ||
// by default, arguments without visibility are private | ||
// but in finalize, they have to be public | ||
transition vanguard_helper() -> [bool; 2] { | ||
return [ | ||
label_ex0, label_ex1, | ||
]; | ||
} | ||
|
||
const label_ex0: bool = true; | ||
transition ex0() -> address { | ||
let a: address = aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc; | ||
return a; | ||
} | ||
|
||
const label_ex1: bool = true; | ||
transition ex1() -> u8 { | ||
let a: u8 = 123u8; | ||
return a; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.env | ||
*.avm | ||
*.prover | ||
*.verifier | ||
outputs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# susinst0.aleo | ||
|
||
## Build Guide | ||
|
||
To compile this Aleo program, run: | ||
```bash | ||
snarkvm build | ||
``` | ||
|
||
To execute this Aleo program, run: | ||
```bash | ||
snarkvm run hello | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
program susinst0.aleo; | ||
|
||
|
||
|
||
function vanguard_helper: | ||
cast true true true into r0 as [boolean; 3u32]; | ||
output r0 as [boolean; 3u32].private; | ||
|
||
|
||
function ex0: | ||
assert.eq true true; | ||
|
||
|
||
function ex1: | ||
add 123u8 0u8 into r0; | ||
output r0 as u8.private; | ||
|
||
|
||
function ex2: | ||
mul 123u8 1u8 into r0; | ||
output r0 as u8.private; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"program": "susinst0.aleo", | ||
"version": "0.0.0", | ||
"description": "", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"program": "susinst0.aleo", | ||
"version": "0.0.0", | ||
"description": "", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// The 'susinst0' program. | ||
program susinst0.aleo { | ||
// by default, arguments without visibility are private | ||
// but in finalize, they have to be public | ||
transition vanguard_helper() -> [bool; 3] { | ||
return [ | ||
label_ex0, label_ex1, label_ex2 | ||
]; | ||
} | ||
|
||
const label_ex0: bool = true; | ||
transition ex0() { | ||
assert(true); | ||
} | ||
|
||
const label_ex1: bool = true; | ||
transition ex1() -> u8 { | ||
let a: u8 = 123u8 + 0u8; | ||
return a; | ||
} | ||
|
||
const label_ex2: bool = true; | ||
transition ex2() -> u8 { | ||
let a: u8 = 123u8 * 1u8; | ||
return a; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
from .divz import detector_divz | ||
from .infoleak import detector_infoleak | ||
from .rtcnst import detector_rtcnst | ||
from .unused import detector_unused | ||
from .unused import detector_unused | ||
from .emptyf import detector_emptyf | ||
from .magicv import detector_magicv | ||
from .susinst import detector_susinst | ||
from .divrd import detector_divrd | ||
from .downcast import detector_downcast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from ..grammar import * | ||
from ..graphs import get_dfg_edges | ||
|
||
def detector_divrd(env: AleoEnvironment, pid: str, fid: str, readable=False): | ||
# initialize | ||
prog: AleoProgram = env.programs[pid] | ||
func: AleoFunction = prog.functions[fid] | ||
|
||
dinsts = [] | ||
|
||
# check for statement level redundancy | ||
all_insts = func.instructions + ([] if func.finalize is None else func.finalize.instructions) | ||
for inst in all_insts: | ||
match inst: | ||
case AleoBinary() if inst.op in {AleoBinaryOp.DIV, AleoBinaryOp.DIVW}: | ||
if isinstance(inst.operands[0], AleoLiteral) and isinstance(inst.operands[1], AleoLiteral): | ||
# pattern 1: literal division | ||
a = inst.operands[0].value | ||
b = inst.operands[1].value | ||
if a % b != 0: | ||
dinsts.append(f"{inst}" if readable else inst) | ||
else: | ||
# FIXME: need to infer value, for now, just ignore | ||
# dinsts.append(f"{inst}" if readable else inst) | ||
pass | ||
|
||
case _: | ||
# not interested | ||
pass | ||
|
||
# pattern 2: division before multiplication | ||
# FIXME: values are not tracked across transition/finalize, neither in external calls | ||
# FIXME: data structures are not considered | ||
div_dests = [] # tracking division destinations | ||
div_lines = [] | ||
for inst in func.instructions: | ||
match inst: | ||
case AleoBinary() if inst.op in {AleoBinaryOp.DIV, AleoBinaryOp.DIVW}: | ||
div_dests.append(f"{inst.regacc}") | ||
div_lines.append(inst) | ||
case AleoBinary() if inst.op in {AleoBinaryOp.MUL, AleoBinaryOp.MULW}: | ||
ind = None | ||
if f"{inst.operands[0]}" in div_dests: | ||
ind = div_dests.index(f"{inst.operands[0]}") | ||
elif f"{inst.operands[1]}" in div_dests: | ||
ind = div_dests.index(f"{inst.operands[1]}") | ||
else: | ||
# do nothing | ||
pass | ||
if ind is not None: | ||
dinsts.append( | ||
(f"{div_lines[ind]}", f"{inst}") if readable else\ | ||
(div_lines[ind], inst) | ||
) | ||
|
||
case _: | ||
# not interested | ||
pass | ||
|
||
return (len(dinsts)>0, dinsts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from ..grammar import * | ||
from ..graphs import get_dfg_edges | ||
|
||
def detector_downcast(env: AleoEnvironment, pid: str, fid: str, readable=False): | ||
# initialize | ||
prog: AleoProgram = env.programs[pid] | ||
func: AleoFunction = prog.functions[fid] | ||
|
||
dinsts = [] | ||
|
||
# check for statement level redundancy | ||
all_insts = func.instructions + ([] if func.finalize is None else func.finalize.instructions) | ||
for inst in all_insts: | ||
match inst: | ||
case AleoCast() if len(inst.operands) == 1: | ||
dinsts.append(f"{inst}" if readable else inst) | ||
|
||
case _: | ||
# not interested | ||
pass | ||
|
||
return (len(dinsts)>0, dinsts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from ..grammar import * | ||
from ..graphs import get_dfg_edges | ||
|
||
def detector_emptyf(env: AleoEnvironment, pid: str, fid: str, readable=False): | ||
# initialize | ||
prog: AleoProgram = env.programs[pid] | ||
func: AleoFunction = prog.functions[fid] | ||
|
||
efs = [] | ||
|
||
# check for function level redundancy | ||
if len(func.instructions) == 0: | ||
efs.append(f"transition {func.id}") | ||
|
||
if func.finalize is not None: | ||
if len(func.finalize.instructions) == 0: | ||
efs.append(f"finalize {func.finalize.id}") | ||
|
||
# check for statement level redundancy | ||
all_insts = func.instructions + ([] if func.finalize is None else func.finalize.instructions) | ||
for inst in all_insts: | ||
match inst: | ||
case AleoAssert(): | ||
g = True | ||
for p in inst.operands: | ||
if not isinstance(p, AleoLiteral): | ||
g = False | ||
break | ||
if g: | ||
efs.append(f"{inst}" if readable else inst) | ||
|
||
case _: | ||
# not interested | ||
pass | ||
|
||
return (len(efs)>0, efs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from ..grammar import * | ||
from ..graphs import get_dfg_edges | ||
|
||
def detector_magicv(env: AleoEnvironment, pid: str, fid: str, readable=False): | ||
# initialize | ||
prog: AleoProgram = env.programs[pid] | ||
func: AleoFunction = prog.functions[fid] | ||
|
||
mvs = [] | ||
|
||
def mm(node): | ||
match node: | ||
case AleoAddressLiteral(): | ||
mvs.append(f"{node}" if readable else node) | ||
case AleoUnsignedLiteral() | AleoSignedLiteral(): | ||
if node.value >= 2 or node.value <= -2: | ||
mvs.append(f"{node}" if readable else node) | ||
case _: | ||
# not interested | ||
pass | ||
|
||
# check for magic values | ||
AleoNode.visit(func, fn_pre=mm) | ||
|
||
return (len(mvs)>0, mvs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from ..grammar import * | ||
from ..graphs import get_dfg_edges | ||
|
||
def detector_susinst(env: AleoEnvironment, pid: str, fid: str, readable=False): | ||
# initialize | ||
prog: AleoProgram = env.programs[pid] | ||
func: AleoFunction = prog.functions[fid] | ||
|
||
sinsts = [] | ||
|
||
# check for statement level redundancy | ||
all_insts = func.instructions + ([] if func.finalize is None else func.finalize.instructions) | ||
for inst in all_insts: | ||
match inst: | ||
case AleoAssert(): | ||
if f"{inst.operands[0]}" == f"{inst.operands[1]}": | ||
sinsts.append(f"{inst}" if readable else inst) | ||
|
||
case AleoBinary(): | ||
match inst.op: | ||
case AleoBinaryOp.ADD | AleoBinaryOp.ADDW: | ||
for p in inst.operands: | ||
if isinstance(p, AleoLiteral) and p.value == 0: | ||
sinsts.append(f"{inst}" if readable else inst) | ||
case AleoBinaryOp.SUB | AleoBinaryOp.SUBW: | ||
if isinstance(inst.operands[1], AleoLiteral) and inst.operands[1].value == 0: | ||
sinsts.append(f"{inst}" if readable else inst) | ||
case AleoBinaryOp.MUL | AleoBinaryOp.MULW: | ||
for p in inst.operands: | ||
if isinstance(p, AleoLiteral) and p.value == 1: | ||
sinsts.append(f"{inst}" if readable else inst) | ||
case _: | ||
# not interested | ||
pass | ||
|
||
case _: | ||
# not interested | ||
pass | ||
|
||
return (len(sinsts)>0, sinsts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters