Skip to content

Commit

Permalink
blueprint: use wrapping operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ioxid committed Dec 20, 2024
1 parent d12f72b commit cd75e1c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace nil {
using word_type = typename zkevm_stack::word_type;
word_type a = machine.stack_top();
word_type b = machine.stack_top(1);
word_type result = is_add ? a + b : a - b;
word_type result = is_add ? add_wrapping(a, b) : subtract_wrapping(a, b);
// TODO: after memory logic would become more complicated here
if (!is_add) {
std::swap(result, a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace nil {
using word_type = typename zkevm_stack::word_type;
word_type a = machine.stack_top();
word_type b = machine.stack_top(1);
word_type result = a * b;
word_type result = multiply_wrapping(a, b);
const std::vector<value_type> a_chunks = zkevm_word_to_field_element<BlueprintFieldType>(a);
const std::vector<value_type> b_chunks = zkevm_word_to_field_element<BlueprintFieldType>(b);
const std::vector<value_type> r_chunks = zkevm_word_to_field_element<BlueprintFieldType>(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,21 @@ namespace nil {
case zkevm_opcode::ADD:{
word_type a = stack_pop();
word_type b = stack_pop();
stack.push(a+b);
stack.push(add_wrapping(a, b));
pc++; gas -= 3;
break;
}
case zkevm_opcode::SUB:{
word_type a = stack_pop();
word_type b = stack_pop();
stack.push(a-b);
stack.push(subtract_wrapping(a, b));
pc++; gas -= 3;
break;
}
case zkevm_opcode::MUL:{
word_type a = stack_pop();
word_type b = stack_pop();
stack.push(a*b);
stack.push(multiply_wrapping(a, b));
pc++; gas -= 5;
break;
}
Expand Down

0 comments on commit cd75e1c

Please sign in to comment.