Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

Revert extra unwanted commit #1093

Merged
merged 1 commit into from
Apr 10, 2024
Merged
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
90 changes: 0 additions & 90 deletions src/kakarot/instructions/stop_and_math_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,96 +34,6 @@ from kakarot.state import State
from utils.uint256 import uint256_fast_exp, uint256_signextend, uint256_sub, uint256_add
from utils.utils import Helpers

// Adds two integers. Returns the result as a 256-bit integer and the (1-bit) carry.
// Strictly equivalent and faster version of common.uint256.uint256_add using the same whitelisted hint.
func uint256_add{range_check_ptr}(a: Uint256, b: Uint256) -> (res: Uint256, carry: felt) {
alloc_locals;
local carry_low: felt;
local carry_high: felt;
%{
sum_low = ids.a.low + ids.b.low
ids.carry_low = 1 if sum_low >= ids.SHIFT else 0
sum_high = ids.a.high + ids.b.high + ids.carry_low
ids.carry_high = 1 if sum_high >= ids.SHIFT else 0
%}

if (carry_low != 0) {
if (carry_high != 0) {
tempvar range_check_ptr = range_check_ptr + 2;
tempvar res = Uint256(low=a.low + b.low - SHIFT, high=a.high + b.high + 1 - SHIFT);
assert [range_check_ptr - 2] = res.low;
assert [range_check_ptr - 1] = res.high;
return (res, 1);
} else {
tempvar range_check_ptr = range_check_ptr + 2;
tempvar res = Uint256(low=a.low + b.low - SHIFT, high=a.high + b.high + 1);
assert [range_check_ptr - 2] = res.low;
assert [range_check_ptr - 1] = res.high;
return (res, 0);
}
} else {
if (carry_high != 0) {
tempvar range_check_ptr = range_check_ptr + 2;
tempvar res = Uint256(low=a.low + b.low, high=a.high + b.high - SHIFT);
assert [range_check_ptr - 2] = res.low;
assert [range_check_ptr - 1] = res.high;
return (res, 1);
} else {
tempvar range_check_ptr = range_check_ptr + 2;
tempvar res = Uint256(low=a.low + b.low, high=a.high + b.high);
assert [range_check_ptr - 2] = res.low;
assert [range_check_ptr - 1] = res.high;
return (res, 0);
}
}
}

// Subtracts two integers. Returns the result as a 256-bit integer.
// Strictly equivalent and faster version of common.uint256.uint256_sub using uint256_add's whitelisted hint.
func uint256_sub{range_check_ptr}(a: Uint256, b: Uint256) -> (res: Uint256) {
alloc_locals;
// Reference "b" as -b.
local b: Uint256 = Uint256(ALL_ONES - b.low + 1, ALL_ONES - b.high);
// Computes a + (-b)
local carry_low: felt;
local carry_high: felt;
%{
sum_low = ids.a.low + ids.b.low
ids.carry_low = 1 if sum_low >= ids.SHIFT else 0
sum_high = ids.a.high + ids.b.high + ids.carry_low
ids.carry_high = 1 if sum_high >= ids.SHIFT else 0
%}

if (carry_low != 0) {
if (carry_high != 0) {
tempvar range_check_ptr = range_check_ptr + 2;
tempvar res = Uint256(low=a.low + b.low - SHIFT, high=a.high + b.high + 1 - SHIFT);
assert [range_check_ptr - 2] = res.low;
assert [range_check_ptr - 1] = res.high;
return (res,);
} else {
tempvar range_check_ptr = range_check_ptr + 2;
tempvar res = Uint256(low=a.low + b.low - SHIFT, high=a.high + b.high + 1);
assert [range_check_ptr - 2] = res.low;
assert [range_check_ptr - 1] = res.high;
return (res,);
}
} else {
if (carry_high != 0) {
tempvar range_check_ptr = range_check_ptr + 2;
tempvar res = Uint256(low=a.low + b.low, high=a.high + b.high - SHIFT);
assert [range_check_ptr - 2] = res.low;
assert [range_check_ptr - 1] = res.high;
return (res,);
} else {
tempvar range_check_ptr = range_check_ptr + 2;
tempvar res = Uint256(low=a.low + b.low, high=a.high + b.high);
assert [range_check_ptr - 2] = res.low;
assert [range_check_ptr - 1] = res.high;
return (res,);
}
}
}
// @title Stop and Math operations opcodes.
// @notice Math operations gathers Arithmetic and Comparison operations
namespace StopAndMathOperations {
Expand Down
Loading