Skip to content

Commit

Permalink
Comments added during presentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Oct 2, 2023
1 parent 658094e commit 3d68467
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class BabyVMTraceBuilder : public ExecutionTraceBuilderBase<arithmetization::Bab
std::vector<Row> rows;
// WORKTODO: instead store columns as vectors? This is what we do with circuit builders.


// EXERCISE NOTE: In practice, some operations will span multiple execution trace rows.
void add_accumulate(const FF& to_add)
{
vm_operations.emplace_back(VMOperation{
Expand Down Expand Up @@ -52,6 +54,7 @@ class BabyVMTraceBuilder : public ExecutionTraceBuilderBase<arithmetization::Bab
});
}

// EXERCISE NOTE: add error case and error handling?
void build_execution_trace()
{
FF previous_accumulator = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TEST(BabyVMTraceBuilderTests, Basic)
trace.mul_accumulate(b);
trace.mul_accumulate(x);
trace.add_accumulate(a);
trace.eq_and_reset(expected);
trace.eq_and_reset(1);

bool result = trace.check_gates();
EXPECT_EQ(result, expected_result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ template <typename FF_> class BabyVMRelationImpl {

/**
* @brief Expression for the BabyVMMultiplication gate.
* @details The relation is defined as, for some challenge c,
* @details The relation is defined as, for some challenge c (the scaling factor),
*
* c^0 + (1 - q_mul) * q_mul
* c^1 + (1 - q_add) * q_add
* c^2 + (1 - q_add) * (1 - q_mul) * (accumulator - scalar)
* c^3 + (1 - q_mul) * q_add * (accumulator - (previous_accumulator + scalar))
* c^4 + (1 - q_add) * q_mul * (accumulator - (previous_accumulator * scalar))
* c^0 * (1 - q_mul) * q_mul
* + c^1 * (1 - q_add) * q_add
* + c^2 * (1 - q_add) * (1 - q_mul) * (accumulator - scalar)
* + c^3 * (1 - q_mul) * q_add * (accumulator - (previous_accumulator + scalar))
* + c^4 * (1 - q_add) * q_mul * (accumulator - (previous_accumulator * scalar))
*
* @param accumulator the term being calculated by a sequence of calls to this function
* @param new_term the term added to the accumulator in this iteration of the function
Expand Down Expand Up @@ -80,6 +80,7 @@ template <typename FF_> class BabyVMRelationImpl {
auto tmp = (FF(1) - q_add);
tmp *= (FF(1) - q_mul);
tmp *= (accumulator - scalar);
tmp *= scaling_factor;
std::get<2>(accumulators) += tmp;
}();

Expand All @@ -88,6 +89,7 @@ template <typename FF_> class BabyVMRelationImpl {
auto tmp = (FF(1) - q_mul);
tmp *= q_add;
tmp *= (accumulator - (previous_accumulator + scalar));
tmp *= scaling_factor;
std::get<3>(accumulators) += tmp;
}();

Expand All @@ -96,6 +98,7 @@ template <typename FF_> class BabyVMRelationImpl {
auto tmp = (FF(1) - q_add);
tmp *= q_mul;
tmp *= (accumulator - (previous_accumulator * scalar));
tmp *= scaling_factor;
std::get<4>(accumulators) += tmp;
}();
};
Expand Down

0 comments on commit 3d68467

Please sign in to comment.