Skip to content

Commit b330910

Browse files
authored
Merge pull request #64 from bendyarm/flagged-operations
Flagged operations
2 parents a5a8d8b + 1705d0b commit b330910

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

arc-0004/README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
arc: 4
3+
title: Flagged Operations
4+
authors: bendyarm, d0cd, acoglio
5+
discussion: https://github.com/AleoHQ/ARCs/discussions/63
6+
topic: # Choose: Protocol, Network, or Application
7+
status: Draft
8+
created: # Date
9+
---
10+
11+
## Abstract
12+
13+
Some Aleo instructions can halt when passed certain arguments.
14+
This halting behavior makes those instructions unusable
15+
by a program that wants to try something else if a halt is detected.
16+
17+
For example, if a Leo program contains a conditional not in a
18+
finalize, both branches of the conditional are executed in the
19+
circuit, so if a branch not taken executes an instruction that halts,
20+
the whole program will incorrectly halt. Replacing the halting
21+
instruction by one that returns an error flag will allow such a
22+
program to compile correctly.
23+
24+
This ARC proposes to add new opcodes for flagged operations
25+
corresponding to the Aleo Instructions that can halt.
26+
27+
## Specification
28+
29+
Each flagged operation is identical to the current halting instruction
30+
except it doesn't halt and it returns another return value that is a
31+
boolean.
32+
33+
The flagged operations are different from wrapped (e.g. `abs.w`) or
34+
lossy (e.g. `cast.lossy`) operations. It is important that the flagged
35+
operation have the same semantics as the current halting instruction
36+
except for the halting behavior and extra return value, for ease of
37+
use by compilers.
38+
39+
| Current Halting Opcode | New Flagged Opcode |
40+
|:-------------------:|:-----------------------:|
41+
| abs | abs.flagged |
42+
| add | add.flagged |
43+
| cast | cast.flagged |
44+
| commit.bhp256 | commit.bhp256.flagged |
45+
| commit.bhp512 | commit.bhp512.flagged |
46+
| commit.bhp768 | commit.bhp768.flagged |
47+
| commit.bhp768 | commit.bhp1024.flagged |
48+
| commit.ped64 | commit.ped64.flagged |
49+
| commit.ped128 | commit.ped128.flagged |
50+
| div | div.flagged |
51+
| hash.bhp256 | hash.bhp256.flagged |
52+
| hash.bhp512 | hash.bhp512.flagged |
53+
| hash.bhp768 | hash.bhp768.flagged |
54+
| hash.bhp1024 | hash.bhp1024.flagged |
55+
| hash.ped64 | hash.ped64.flagged |
56+
| hash.ped128 | hash.ped128.flagged |
57+
| inv | inv.flagged |
58+
| mod | mod.flagged |
59+
| mul | mul.flagged |
60+
| neg | neg.flagged |
61+
| pow | pow.flagged |
62+
| rem | rem.flagged |
63+
| shl | shl.flagged |
64+
| shr | shr.flagged |
65+
| sqrt | sqrt.flagged |
66+
| sub | sub.flagged |
67+
68+
### Test Cases
69+
70+
This section should introduce any and all critical test cases that need to be considered for the specification.
71+
72+
The following note applies to all tests of Aleo Instructions. For all tests, both literal constant arguments
73+
and variable arguments should be tested. If there are two arguments, we need to test all four
74+
combinations. This is because the Aleo Instructions compiler generates more optimized code for literal
75+
constant arguments, and the circuits can differ substantially.
76+
77+
One or more arguments that causes halting for a current halting opcode should be used as an input
78+
for the equivalent new flagged opcode to make sure it doesn't halt.
79+
80+
An assortment of arguments that do not cause halting for a current halting opcode should be
81+
used as input to both halting and flagged operations to make sure they return the same value
82+
(other than the halting flag, of course).
83+
84+
## Dependencies
85+
86+
The main change is to the snarkVM repository.
87+
88+
The Aleo Explorer will need to be updated to output the new operations when displaying an aleo program.
89+
90+
The "sdk" repository may need to be changed to show syntax highlighting on the new opcodes.
91+
92+
After this change, the Leo compiler can more easily be fixed to prevent the [conditional halting bug.](<https://github.com/AleoHQ/leo/issues/27482>)
93+
94+
### Backwards Compatibility
95+
96+
This change is strictly additive.
97+
98+
## Security & Compliance
99+
100+
This change does not affect security or regulatory issues.
101+
102+
## References
103+
104+
Leo bug:
105+
https://github.com/AleoHQ/leo/issues/27482

0 commit comments

Comments
 (0)