Skip to content

Commit bf459fd

Browse files
authored
fix(ssa): Validate signed mul overflow (#8798)
1 parent 9b4d7ba commit bf459fd

5 files changed

Lines changed: 257 additions & 51 deletions

File tree

compiler/noirc_evaluator/src/ssa/opt/checked_to_unchecked.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ mod tests {
324324
b0(v0: u1, v1: i32):
325325
v2 = cast v0 as i32
326326
v3 = mul v2, v1
327+
v4 = cast v3 as u64
328+
v6 = truncate v4 to 32 bits, max_bit_size: 64
327329
return v2
328330
}
329331
";

compiler/noirc_evaluator/src/ssa/opt/loop_invariant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ mod test {
10931093
v9 = unchecked_add v2, i32 1
10941094
jmp b1(v9)
10951095
b6():
1096-
v10 = mul v0, v1
1096+
v10 = unchecked_mul v0, v1
10971097
constrain v10 == i32 6
10981098
v12 = unchecked_add v3, i32 1
10991099
jmp b4(v12)
@@ -1110,7 +1110,7 @@ mod test {
11101110
let expected = "
11111111
brillig(inline) fn main f0 {
11121112
b0(v0: i32, v1: i32):
1113-
v4 = mul v0, v1
1113+
v4 = unchecked_mul v0, v1
11141114
constrain v4 == i32 6
11151115
jmp b1(i32 0)
11161116
b1(v2: i32):

compiler/noirc_evaluator/src/ssa/opt/unrolling.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,9 +1490,9 @@ mod tests {
14901490
v11 = array_get v0, index v10 -> u64
14911491
v12 = add v11, u64 1
14921492
v13 = array_set v9, index v10, value v12
1493-
v15 = add v1, {idx_type} 1
1493+
v15 = unchecked_add v1, {idx_type} 1
14941494
store v13 at v4
1495-
v16 = add v1, {idx_type} 1 // duplicate
1495+
v16 = unchecked_add v1, {idx_type} 1 // duplicate
14961496
jmp b1(v16)
14971497
b2():
14981498
v8 = load v4 -> [u64; 6]

compiler/noirc_evaluator/src/ssa/parser/into_ssa.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::ssa::{
1616
value::ValueId,
1717
},
1818
opt::pure::FunctionPurities,
19-
validation::validate_function,
2019
};
2120

2221
use super::{
@@ -558,10 +557,6 @@ impl Translator {
558557
// before each print.
559558
ssa.normalize_ids();
560559

561-
for function in ssa.functions.values() {
562-
validate_function(function);
563-
}
564-
565560
ssa
566561
}
567562

0 commit comments

Comments
 (0)