Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(breaking change): change embedded curve scalar mul to use two limbs to properly encode the scalar field #2105

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ void handle_blackbox_func_call(Circuit::Opcode::BlackBoxFuncCall const& arg, aci
});
} else if constexpr (std::is_same_v<T, Circuit::BlackBoxFuncCall::FixedBaseScalarMul>) {
af.fixed_base_scalar_mul_constraints.push_back(FixedBaseScalarMul{
.scalar = arg.input.witness.value,
.low = arg.low.witness.value,
.high = arg.high.witness.value,
.pub_key_x = arg.outputs[0].value,
.pub_key_y = arg.outputs[1].value,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ namespace acir_format {
void create_fixed_base_constraint(Builder& builder, const FixedBaseScalarMul& input)
{

field_ct scalar_as_field = field_ct::from_witness_index(&builder, input.scalar);
auto public_key = group_ct::fixed_base_scalar_mul_g1<254>(scalar_as_field);
field_ct low_as_field = field_ct::from_witness_index(&builder, input.low);
field_ct high_as_field = field_ct::from_witness_index(&builder, input.high);
(void)high_as_field;
auto public_key = group_ct::fixed_base_scalar_mul_g1<254>(low_as_field);

builder.assert_equal(public_key.x.witness_index, input.pub_key_x);
builder.assert_equal(public_key.y.witness_index, input.pub_key_y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
namespace acir_format {

struct FixedBaseScalarMul {
uint32_t scalar;
uint32_t low;
uint32_t high;
uint32_t pub_key_x;
uint32_t pub_key_y;

// for serialization, update with any new fields
MSGPACK_FIELDS(scalar, pub_key_x, pub_key_y);
MSGPACK_FIELDS(low, high, pub_key_x, pub_key_y);
friend bool operator==(FixedBaseScalarMul const& lhs, FixedBaseScalarMul const& rhs) = default;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ struct BlackBoxFuncCall {
};

struct FixedBaseScalarMul {
Circuit::FunctionInput input;
Circuit::FunctionInput low;
Circuit::FunctionInput high;
std::array<Circuit::Witness, 2> outputs;

friend bool operator==(const FixedBaseScalarMul&, const FixedBaseScalarMul&);
Expand Down Expand Up @@ -467,7 +468,8 @@ struct BlackBoxOp {
};

struct FixedBaseScalarMul {
Circuit::RegisterIndex input;
Circuit::RegisterIndex low;
Circuit::RegisterIndex high;
Circuit::HeapArray result;

friend bool operator==(const FixedBaseScalarMul&, const FixedBaseScalarMul&);
Expand Down Expand Up @@ -2379,7 +2381,10 @@ namespace Circuit {

inline bool operator==(const BlackBoxFuncCall::FixedBaseScalarMul& lhs, const BlackBoxFuncCall::FixedBaseScalarMul& rhs)
{
if (!(lhs.input == rhs.input)) {
if (!(lhs.low == rhs.low)) {
return false;
}
if (!(lhs.high == rhs.high)) {
return false;
}
if (!(lhs.outputs == rhs.outputs)) {
Expand Down Expand Up @@ -2413,7 +2418,8 @@ template <typename Serializer>
void serde::Serializable<Circuit::BlackBoxFuncCall::FixedBaseScalarMul>::serialize(
const Circuit::BlackBoxFuncCall::FixedBaseScalarMul& obj, Serializer& serializer)
{
serde::Serializable<decltype(obj.input)>::serialize(obj.input, serializer);
serde::Serializable<decltype(obj.low)>::serialize(obj.low, serializer);
serde::Serializable<decltype(obj.high)>::serialize(obj.high, serializer);
serde::Serializable<decltype(obj.outputs)>::serialize(obj.outputs, serializer);
}

Expand All @@ -2423,7 +2429,8 @@ Circuit::BlackBoxFuncCall::FixedBaseScalarMul serde::Deserializable<
Circuit::BlackBoxFuncCall::FixedBaseScalarMul>::deserialize(Deserializer& deserializer)
{
Circuit::BlackBoxFuncCall::FixedBaseScalarMul obj;
obj.input = serde::Deserializable<decltype(obj.input)>::deserialize(deserializer);
obj.low = serde::Deserializable<decltype(obj.low)>::deserialize(deserializer);
obj.high = serde::Deserializable<decltype(obj.high)>::deserialize(deserializer);
obj.outputs = serde::Deserializable<decltype(obj.outputs)>::deserialize(deserializer);
return obj;
}
Expand Down Expand Up @@ -3134,7 +3141,10 @@ namespace Circuit {

inline bool operator==(const BlackBoxOp::FixedBaseScalarMul& lhs, const BlackBoxOp::FixedBaseScalarMul& rhs)
{
if (!(lhs.input == rhs.input)) {
if (!(lhs.low == rhs.low)) {
return false;
}
if (!(lhs.high == rhs.high)) {
return false;
}
if (!(lhs.result == rhs.result)) {
Expand Down Expand Up @@ -3167,7 +3177,8 @@ template <typename Serializer>
void serde::Serializable<Circuit::BlackBoxOp::FixedBaseScalarMul>::serialize(
const Circuit::BlackBoxOp::FixedBaseScalarMul& obj, Serializer& serializer)
{
serde::Serializable<decltype(obj.input)>::serialize(obj.input, serializer);
serde::Serializable<decltype(obj.low)>::serialize(obj.low, serializer);
serde::Serializable<decltype(obj.high)>::serialize(obj.high, serializer);
serde::Serializable<decltype(obj.result)>::serialize(obj.result, serializer);
}

Expand All @@ -3177,7 +3188,8 @@ Circuit::BlackBoxOp::FixedBaseScalarMul serde::Deserializable<Circuit::BlackBoxO
Deserializer& deserializer)
{
Circuit::BlackBoxOp::FixedBaseScalarMul obj;
obj.input = serde::Deserializable<decltype(obj.input)>::deserialize(deserializer);
obj.low = serde::Deserializable<decltype(obj.low)>::deserialize(deserializer);
obj.high = serde::Deserializable<decltype(obj.high)>::deserialize(deserializer);
obj.result = serde::Deserializable<decltype(obj.result)>::deserialize(deserializer);
return obj;
}
Expand Down