Skip to content

Commit

Permalink
Pass the uint context to the return value of uint::at (#1593)
Browse files Browse the repository at this point in the history
* Construct return value from current context in uint::at

Fixes https://github.com/AztecProtocol/aztec2-internal/issues/1433

* Add uint test which asserts context inheritance
  • Loading branch information
guidovranken authored Oct 10, 2022
1 parent aedde40 commit d93f118
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
22 changes: 21 additions & 1 deletion src/aztec/stdlib/primitives/bit_array/bit_array.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,24 @@ TEST(stdlib_bit_array, test_byte_array_conversion)

EXPECT_EQ(result, expected);
}
} // namespace test_stdlib_bit_array

TEST(stdlib_bit_array, test_uint32_vector_constructor)
{
waffle::StandardComposer composer = waffle::StandardComposer();

uint32_t a_expected = engine.get_random_uint32();
uint32_t b_expected = engine.get_random_uint32();

uint32 a = witness_t(&composer, a_expected);
uint32 b = witness_t(&composer, b_expected);

std::vector<uint32> inputs = { a, b };
bit_array test_bit_array = bit_array(inputs);

std::vector<uint32> result = test_bit_array.to_uint32_vector();

bit_array test_bit_array_2 = bit_array(result);

static_cast<byte_array>(test_bit_array_2).get_value();
}
} // namespace test_stdlib_bit_array
6 changes: 3 additions & 3 deletions src/aztec/stdlib/primitives/uint/uint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ template <typename Composer, typename Native> bool_t<Composer> uint<Composer, Na
* lo_bit + 2 high bit of (A_pivot - 4 A_{pivot - 1}) = A_pivot - 4 A_{pivot - 1} == 0
*/
context->create_big_add_gate_with_bit_extraction(gate);
bool_t<Composer> result;
bool_t<Composer> result(context);
result.witness_index = gate.a;
result.witness_bool = (lo_bit == 1) ? true : false;
return result;
Expand All @@ -364,7 +364,7 @@ template <typename Composer, typename Native> bool_t<Composer> uint<Composer, Na
* bit extraction gate is trusted to correctly extract 6 * (high bit c - 4d).
*/
context->create_big_add_gate_with_bit_extraction(gate);
bool_t<Composer> result;
bool_t<Composer> result(context);
result.witness_index = gate.b;
result.witness_bool = (hi_bit == 1) ? true : false;
return result;
Expand All @@ -376,4 +376,4 @@ INSTANTIATE_STDLIB_TYPE_VA(uint, uint32_t);
INSTANTIATE_STDLIB_TYPE_VA(uint, uint64_t);

} // namespace stdlib
} // namespace plonk
} // namespace plonk
1 change: 1 addition & 0 deletions src/aztec/stdlib/primitives/uint/uint.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,7 @@ TEST(stdlib_uint, test_at)
bool_ct result = c.at(i);
bool expected = (((c_val >> i) & 1UL) == 1UL) ? true : false;
EXPECT_EQ(result.get_value(), expected);
EXPECT_EQ(result.get_context(), c.get_context());
}
};

Expand Down

0 comments on commit d93f118

Please sign in to comment.