Skip to content

Commit

Permalink
update CI and fixed infoleak detector
Browse files Browse the repository at this point in the history
  • Loading branch information
chyanju committed Feb 28, 2024
1 parent 4c87595 commit 884c938
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
7 changes: 6 additions & 1 deletion tests/scripts/test-infoleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
build_path = f"./tests/public/{project_name}/build/"
env = AleoEnvironment(build_path)
main = env.main

fid = "ex0"
res, info = detector_infoleak(env, main.id, fid)
assert res, f"Test failed for {fid}, expected: True, got: {res}"
assert res, f"Test failed for {fid}, expected: True, got: {res}"

fid = "ex1"
res, info = detector_infoleak(env, main.id, fid)
assert not res, f"Test failed for {fid}, expected: False, got: {res}"
2 changes: 1 addition & 1 deletion tests/scripts/test-unused.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

fid = "ex0"
res, info = detector_unused(env, main.id, fid)
assert not res, f"Test failed for {fid}, expected: True, got: {res}"
assert not res, f"Test failed for {fid}, expected: False, got: {res}"

fid = "ex1"
res, info = detector_unused(env, main.id, fid)
Expand Down
37 changes: 21 additions & 16 deletions tests/test4.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"# [debug] deploy: main.aleo\n",
"# [debug] deploy: helpers.aleo\n"
"# [debug] deploy: main.aleo\n"
]
}
],
"source": [
"project_name = \"divz0\"\n",
"# project_name = \"infoleak0\"\n",
"# project_name = \"divz0\"\n",
"project_name = \"infoleak0\"\n",
"# project_name = \"unused0\"\n",
"# project_name = \"rtcnst0\"\n",
"build_path = f\"./tests/public/{project_name}/build/\"\n",
Expand All @@ -63,26 +62,32 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 4,
"id": "0dc6fcff-f8b2-44cb-8919-fda9b23c0b49",
"metadata": {},
"outputs": [
{
"ename": "KeyError",
"evalue": "'ex26'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[9], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m fid \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mex26\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 2\u001b[0m \u001b[43mdetector_divz\u001b[49m\u001b[43m(\u001b[49m\u001b[43menv\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmain\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mid\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfid\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mreadable\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Desktop/UCSB/24winter/vanguard-aleo/vanguard/aleo/detectors/divz.py:158\u001b[0m, in \u001b[0;36mdetector_divz\u001b[0;34m(env, pid, fid, readable)\u001b[0m\n\u001b[1;32m 155\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdetector_divz\u001b[39m(env: AleoEnvironment, pid: \u001b[38;5;28mstr\u001b[39m, fid: \u001b[38;5;28mstr\u001b[39m, readable\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m):\n\u001b[1;32m 156\u001b[0m \u001b[38;5;66;03m# initialize\u001b[39;00m\n\u001b[1;32m 157\u001b[0m prog: AleoProgram \u001b[38;5;241m=\u001b[39m env\u001b[38;5;241m.\u001b[39mprograms[pid]\n\u001b[0;32m--> 158\u001b[0m func: AleoFunction \u001b[38;5;241m=\u001b[39m \u001b[43mprog\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfunctions\u001b[49m\u001b[43m[\u001b[49m\u001b[43mfid\u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 160\u001b[0m \u001b[38;5;66;03m# store problematic instructions\u001b[39;00m\n\u001b[1;32m 161\u001b[0m lines \u001b[38;5;241m=\u001b[39m []\n",
"\u001b[0;31mKeyError\u001b[0m: 'ex26'"
"name": "stdout",
"output_type": "stream",
"text": [
"r0 -> r0\n",
"# [debug] sig_in: r0\n"
]
},
{
"data": {
"text/plain": [
"(True, [('r0', 'r0')])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fid = \"ex26\"\n",
"detector_divz(env, main.id, fid, readable=True)"
"fid = \"ex0\"\n",
"detector_infoleak(env, main.id, fid, readable=True)"
]
},
{
Expand Down
3 changes: 3 additions & 0 deletions vanguard/aleo/detectors/infoleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def detector_infoleak(env: AleoEnvironment, pid: str, fid: str, readable=False):
func: AleoFunction = prog.functions[fid]

edges = get_dfg_edges(env, pid, fid, hash=False)
# special edge a -> a so that direct returning of a variable is accounted
for k,v in func.inputs:
edges.append((k, k))

# DEBUG
for p in edges:
Expand Down

0 comments on commit 884c938

Please sign in to comment.