Merge pull request #1193 from AleoHQ/bug/countdown-loops-off-by-one

fix reverse loop have to add range, which is always 1 for now
This commit is contained in:
Alessandro Coglio 2021-07-27 10:30:18 -07:00 committed by GitHub
commit e1b6361a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 86 additions and 5 deletions

View File

@ -57,7 +57,8 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
(true, true) => Box::new(from..=to), (true, true) => Box::new(from..=to),
(true, false) => Box::new(from..to), (true, false) => Box::new(from..to),
(false, true) => Box::new((to..=from).rev()), (false, true) => Box::new((to..=from).rev()),
(false, false) => Box::new((to..from).rev()), // add the range to the values to get correct bound
(false, false) => Box::new(((to + 1)..(from + 1)).rev()),
}; };
for i in iter { for i in iter {

View File

@ -6,7 +6,7 @@ input_file: inputs/dummy.in
function main(k: bool) -> bool { function main(k: bool) -> bool {
let reverse: u32 = 0; let reverse: u32 = 0;
for i in 10..0 { for i in 9..0 {
reverse += i; reverse += i;
} }

View File

@ -0,0 +1,19 @@
/*
namespace: Compile
expectation: Pass
input_file: inputs/dummy.in
*/
function main(k: bool) -> bool {
let reverse: u32 = 0;
for i in 25..1 {
reverse += i;
}
let reverse_inclusive: u32 = 0;
for a in 25..=1 {
reverse_inclusive += a;
}
return (reverse + 1 == reverse_inclusive) && k;
}

View File

@ -0,0 +1,19 @@
/*
namespace: Compile
expectation: Pass
input_file: inputs/dummy.in
*/
function main(k: bool) -> bool {
let reverse: u32 = 0;
for i in 1..0 {
reverse += i;
}
let reverse_inclusive: u32 = 0;
for a in 1..=0 {
reverse_inclusive += a;
}
return (reverse == 1) && (reverse_inclusive == 1) && k;
}

View File

@ -16,6 +16,6 @@ outputs:
r0: r0:
type: bool type: bool
value: "true" value: "true"
initial_ast: 7ecd56e44c6b1cb4f702a2712a2a7fe3bf564dac26a70e1f14151a688fb24769 initial_ast: 280277fb32e4eece0eab1f72338a9b60b6792d7f11124e8c4a5678ef3fc4a04e
canonicalized_ast: 360ecac21f95b0e1d949d49458f2c4557446d01db08333d6f25621ef47a78a66 canonicalized_ast: 84769d3580d79825fef6fd00dd9ab88dc6eaf16bf2e3f3c46feae654f8f1f746
type_inferenced_ast: 853fdefe080011aaa35363e827a527ab7ce6c7e93cd568c8a150211fa6e402fe type_inferenced_ast: 078070bc5df73c49f8de0ca37ac624c93a67551e0221dc1c65a84588507a2a6f

View File

@ -0,0 +1,21 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: inputs/dummy.in
output:
registers:
r0:
type: bool
value: "true"
initial_ast: 41a0c534538a94dc81b72250c2fc9f4119c6b8d3f3e99e47e239365284bd0084
canonicalized_ast: 6c3f732c92874e90be8cab55ac665c6f6d4292d76fce147ae89ed9dbdfe685ea
type_inferenced_ast: 2258791abdb7bde2e3f28a12ff8b5d593985c42d78e3750d6b5f44d88d0560ed

View File

@ -0,0 +1,21 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: inputs/dummy.in
output:
registers:
r0:
type: bool
value: "true"
initial_ast: 55d64e1ef9318084a66cee912987308a21c5779cdad1f0103d6b3fb195f74d8a
canonicalized_ast: 467824b3c4be8e0d10d6008a036f40bed2659a18ab7eb2ea2a5c7124146d9b06
type_inferenced_ast: b0908f46546647877409194ca817072d02f157b720236c7f58b5d3b0b7cfb81f