Open pventuzelo opened 1 year ago
@Pratyush @vicsn i think it might be time for us to debug this (along with AleoHQ/snarkVM#986) after multi-executions are feature complete. this issue seems to reappear from time to time (I ran into a similar issue with a community dev in Tokyo).
Just FYI got a good lead on this - following up in two weeks from now due to some team member's holidays who I asked for input.
TL;DR: the error is valid but we should decide how to handle build-time and runtime errors for all operators. In order to inform a refactor and update our developer docs, I could investigate for all Aleo/Leo operators what their behavior is at build and runtime on bad constant or dynamic inputs. Alternatively I can just replace the panicking assert(...)
with a panicking halt(...)
.
–
The assert which fails, checks whether the Magnitude we shift by is not too big. This is done by checking that enough trailing bits of the rhs
we shift right by are zero.
As Alessandro noticed, the logic follows Rust's shr_checked
specification, which we use directly when the operands are Constant. The only problem is that we panic instead of gracefully stopping. Noting that:
halt()
, which is easy to implement.bail!()
when the user tries to use the wrong operand types for a particular operator. However, our failure is caused by the value of the operand. Even the smallest type (U8) can hold a value (255) which we should never shift by. Pranav mentioned "I don’t think there is an easy way to modify the circuits APIs to better handle errors."It looks like other operators are not consistent in dealing with bad input, which I think is worth streamlining so nothing panics:
assert.eq 1i16 2i16
panics on build, if an operand is dynamic, we cleanly fail ⚠️at runtimeadd 30000i16 30000i16
panics on build, if an operand is dynamic we panic at runtime
Assertion failed
left == right
We (@fuzzinglabs) found an assertion fail panics while fuzzing in
Circuit::enforce()
.This error can be triggered directly with the
aleo build
on the latest release version of the projectYour Environment
Expected Behavior
The program should either gracefully exit or use the function
halt()
that is used in others cases when there's an error. The preferred behavior would be to gracefully exit.Backtrace
Crash File (main.aleo)