Skip to content

Commit

Permalink
fix(ssa): Accurate constant type for slice dummy data in flattening (#…
Browse files Browse the repository at this point in the history
…4661)

# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

We were not accurately constructing the type for slice dummy data. We
were always making slice dummy data a `Field` but this could lead to
errors when eventually merging this value with a different numeric type.

## Additional Context



## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [ ] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
vezenovm committed Mar 27, 2024
1 parent d202a08 commit b87654e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ impl<'a> ValueMerger<'a> {
/// such as with dynamic indexing of non-homogenous slices.
fn make_slice_dummy_data(&mut self, typ: &Type) -> ValueId {
match typ {
Type::Numeric(_) => {
Type::Numeric(numeric_type) => {
let zero = FieldElement::zero();
self.dfg.make_constant(zero, Type::field())
self.dfg.make_constant(zero, Type::Numeric(*numeric_type))
}
Type::Array(element_types, len) => {
let mut array = im::Vector::new();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "regression_sha256_slice"
type = "bin"
authors = [""]
compiler_version = ">=0.26.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = ["5", "10"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use dep::std;

fn main(x: [u8; 2]) {
let mut y = x.as_slice();
let digest1 = std::hash::sha256_slice(y);
let mut v = y;
if x[0] != 0 {
v = y.push_back(x[0]);
}
let digest2 = std::hash::sha256_slice(v);
assert(digest1 != digest2);
}

0 comments on commit b87654e

Please sign in to comment.