From cd75e1cdd2e537d579f85ed26f705d70bea96d48 Mon Sep 17 00:00:00 2001 From: Andrey Nefedov Date: Fri, 20 Dec 2024 11:27:17 +0000 Subject: [PATCH] blueprint: use wrapping operations --- .../include/nil/blueprint/zkevm/operations/add_sub.hpp | 2 +- .../include/nil/blueprint/zkevm/operations/mul.hpp | 2 +- .../include/nil/blueprint/zkevm/zkevm_machine_interface.hpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm/operations/add_sub.hpp b/crypto3/libs/blueprint/include/nil/blueprint/zkevm/operations/add_sub.hpp index efdb03c358..285ee7e927 100644 --- a/crypto3/libs/blueprint/include/nil/blueprint/zkevm/operations/add_sub.hpp +++ b/crypto3/libs/blueprint/include/nil/blueprint/zkevm/operations/add_sub.hpp @@ -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); diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm/operations/mul.hpp b/crypto3/libs/blueprint/include/nil/blueprint/zkevm/operations/mul.hpp index d5d2354ada..e8ef028751 100644 --- a/crypto3/libs/blueprint/include/nil/blueprint/zkevm/operations/mul.hpp +++ b/crypto3/libs/blueprint/include/nil/blueprint/zkevm/operations/mul.hpp @@ -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 a_chunks = zkevm_word_to_field_element(a); const std::vector b_chunks = zkevm_word_to_field_element(b); const std::vector r_chunks = zkevm_word_to_field_element(result); diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm/zkevm_machine_interface.hpp b/crypto3/libs/blueprint/include/nil/blueprint/zkevm/zkevm_machine_interface.hpp index 2f4bec007f..c07dc94853 100644 --- a/crypto3/libs/blueprint/include/nil/blueprint/zkevm/zkevm_machine_interface.hpp +++ b/crypto3/libs/blueprint/include/nil/blueprint/zkevm/zkevm_machine_interface.hpp @@ -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; }