|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +// This is licensed under the Cryptographic Open Software License 1.0 |
| 3 | +pragma solidity ^0.8.28; |
| 4 | + |
| 5 | +import "../base/Constants.sol"; |
| 6 | +import "../base/Errors.sol"; |
| 7 | +import {VerificationBuilder} from "../builder/VerificationBuilder.pre.sol"; |
| 8 | + |
| 9 | +/// @title SubtractExpr |
| 10 | +/// @dev Library for handling subtracting two proof expressions |
| 11 | +library SubtractExpr { |
| 12 | + /// @notice Evaluates an subtract expression by subtracting one sub-expression from the other |
| 13 | + /// @custom:as-yul-wrapper |
| 14 | + /// #### Wrapped Yul Function |
| 15 | + /// ##### Signature |
| 16 | + /// ```yul |
| 17 | + /// subtract_expr_evaluate(expr_ptr, builder_ptr, chi_eval) -> expr_ptr_out, eval |
| 18 | + /// ``` |
| 19 | + /// ##### Parameters |
| 20 | + /// * `expr_ptr` - calldata pointer to the expression data |
| 21 | + /// * `builder_ptr` - memory pointer to the verification builder |
| 22 | + /// * `chi_eval` - the chi value for evaluation |
| 23 | + /// ##### Return Values |
| 24 | + /// * `expr_ptr_out` - pointer to the remaining expression after consuming both sub-expressions |
| 25 | + /// * `eval` - the evaluation result from the builder's final round MLE |
| 26 | + /// @notice Evaluates two sub-expressions and subtract one from the other |
| 27 | + /// ##### Proof Plan Encoding |
| 28 | + /// The subtract expression is encoded as follows: |
| 29 | + /// 1. The left hand side expression |
| 30 | + /// 2. The right hand side expression |
| 31 | + /// @param __expr The subtract expression data |
| 32 | + /// @param __builder The verification builder |
| 33 | + /// @param __chiEval The chi value for evaluation |
| 34 | + /// @return __exprOut The remaining expression after processing |
| 35 | + /// @return __builderOut The verification builder result |
| 36 | + /// @return __eval The evaluated result |
| 37 | + function __subtractExprEvaluate( // solhint-disable-line gas-calldata-parameters |
| 38 | + bytes calldata __expr, VerificationBuilder.Builder memory __builder, uint256 __chiEval) |
| 39 | + external |
| 40 | + pure |
| 41 | + returns (bytes calldata __exprOut, VerificationBuilder.Builder memory __builderOut, uint256 __eval) |
| 42 | + { |
| 43 | + assembly { |
| 44 | + // IMPORT-YUL ../base/Errors.sol |
| 45 | + function err(code) { |
| 46 | + revert(0, 0) |
| 47 | + } |
| 48 | + // IMPORT-YUL ../base/Queue.pre.sol |
| 49 | + function dequeue(queue_ptr) -> value { |
| 50 | + revert(0, 0) |
| 51 | + } |
| 52 | + // IMPORT-YUL ../base/SwitchUtil.pre.sol |
| 53 | + function case_const(lhs, rhs) { |
| 54 | + revert(0, 0) |
| 55 | + } |
| 56 | + // IMPORT-YUL ../builder/VerificationBuilder.pre.sol |
| 57 | + function builder_get_column_evaluation(builder_ptr, column_num) -> eval { |
| 58 | + revert(0, 0) |
| 59 | + } |
| 60 | + // IMPORT-YUL ../base/Array.pre.sol |
| 61 | + function get_array_element(arr_ptr, index) -> value { |
| 62 | + revert(0, 0) |
| 63 | + } |
| 64 | + // IMPORT-YUL ColumnExpr.pre.sol |
| 65 | + function column_expr_evaluate(expr_ptr, builder_ptr) -> expr_ptr_out, eval { |
| 66 | + revert(0, 0) |
| 67 | + } |
| 68 | + // IMPORT-YUL LiteralExpr.pre.sol |
| 69 | + function literal_expr_evaluate(expr_ptr, chi_eval) -> expr_ptr_out, eval { |
| 70 | + revert(0, 0) |
| 71 | + } |
| 72 | + // IMPORT-YUL EqualsExpr.pre.sol |
| 73 | + function equals_expr_evaluate(expr_ptr, builder_ptr, chi_eval) -> expr_ptr_out, eval { |
| 74 | + revert(0, 0) |
| 75 | + } |
| 76 | + // IMPORT-YUL AddExpr.pre.sol |
| 77 | + function add_expr_evaluate(expr_ptr, builder_ptr, chi_eval) -> expr_ptr_out, eval { |
| 78 | + revert(0, 0) |
| 79 | + } |
| 80 | + // IMPORT-YUL ../builder/VerificationBuilder.pre.sol |
| 81 | + function builder_consume_final_round_mle(builder_ptr) -> value { |
| 82 | + revert(0, 0) |
| 83 | + } |
| 84 | + // IMPORT-YUL ../builder/VerificationBuilder.pre.sol |
| 85 | + function builder_produce_identity_constraint(builder_ptr, evaluation, degree) { |
| 86 | + revert(0, 0) |
| 87 | + } |
| 88 | + // IMPORT-YUL ProofExpr.pre.sol |
| 89 | + function proof_expr_evaluate(expr_ptr, builder_ptr, chi_eval) -> expr_ptr_out, eval { |
| 90 | + revert(0, 0) |
| 91 | + } |
| 92 | + |
| 93 | + function subtract_expr_evaluate(expr_ptr, builder_ptr, chi_eval) -> expr_ptr_out, result_eval { |
| 94 | + let lhs_eval |
| 95 | + expr_ptr, lhs_eval := proof_expr_evaluate(expr_ptr, builder_ptr, chi_eval) |
| 96 | + |
| 97 | + let rhs_eval |
| 98 | + expr_ptr, rhs_eval := proof_expr_evaluate(expr_ptr, builder_ptr, chi_eval) |
| 99 | + |
| 100 | + result_eval := addmod(lhs_eval, mulmod(MODULUS_MINUS_ONE, rhs_eval, MODULUS), MODULUS) |
| 101 | + expr_ptr_out := expr_ptr |
| 102 | + } |
| 103 | + |
| 104 | + let __exprOutOffset |
| 105 | + __exprOutOffset, __eval := subtract_expr_evaluate(__expr.offset, __builder, __chiEval) |
| 106 | + __exprOut.offset := __exprOutOffset |
| 107 | + // slither-disable-next-line write-after-write |
| 108 | + __exprOut.length := sub(__expr.length, sub(__exprOutOffset, __expr.offset)) |
| 109 | + } |
| 110 | + __builderOut = __builder; |
| 111 | + } |
| 112 | +} |
0 commit comments