-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24f82fc
commit a15e3cc
Showing
33 changed files
with
77 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule rain.chainlink
deleted from
c9844b
Submodule rain.math.fixedpoint
deleted from
f0d74e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,79 @@ | ||
// SPDX-License-Identifier: CAL | ||
pragma solidity ^0.8.18; | ||
// // SPDX-License-Identifier: CAL | ||
// pragma solidity ^0.8.18; | ||
|
||
import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; | ||
import {Pointer} from "rain.solmem/lib/LibPointer.sol"; | ||
import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol"; | ||
import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol"; | ||
import {SaturatingMath} from "rain.math.saturating/SaturatingMath.sol"; | ||
// import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; | ||
// import {Pointer} from "rain.solmem/lib/LibPointer.sol"; | ||
// import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol"; | ||
// import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol"; | ||
// import {SaturatingMath} from "rain.math.saturating/SaturatingMath.sol"; | ||
|
||
/// @title LibOpSub | ||
/// @notice Opcode to subtract N integers. | ||
library LibOpSub { | ||
function integrity(IntegrityCheckStateNP memory, Operand operand) internal pure returns (uint256, uint256) { | ||
// There must be at least two inputs. | ||
uint256 inputs = (Operand.unwrap(operand) >> 0x10) & 0x0F; | ||
inputs = inputs > 1 ? inputs : 2; | ||
return (inputs, 1); | ||
} | ||
// /// @title LibOpSub | ||
// /// @notice Opcode to subtract N integers. | ||
// library LibOpSub { | ||
// function integrity(IntegrityCheckStateNP memory, Operand operand) internal pure returns (uint256, uint256) { | ||
// // There must be at least two inputs. | ||
// uint256 inputs = (Operand.unwrap(operand) >> 0x10) & 0x0F; | ||
// inputs = inputs > 1 ? inputs : 2; | ||
// return (inputs, 1); | ||
// } | ||
|
||
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | ||
return a - b; | ||
} | ||
// function sub(uint256 a, uint256 b) internal pure returns (uint256) { | ||
// return a - b; | ||
// } | ||
|
||
/// sub | ||
/// Subtraction with implied overflow checks from the Solidity 0.8.x compiler. | ||
function run(InterpreterStateNP memory, Operand operand, Pointer stackTop) internal pure returns (Pointer) { | ||
uint256 a; | ||
uint256 b; | ||
uint256 saturate; | ||
assembly ("memory-safe") { | ||
a := mload(stackTop) | ||
b := mload(add(stackTop, 0x20)) | ||
stackTop := add(stackTop, 0x40) | ||
saturate := and(operand, 1) | ||
} | ||
function (uint256, uint256) internal pure returns (uint256) f = | ||
saturate > 0 ? SaturatingMath.saturatingSub : sub; | ||
a = f(a, b); | ||
// /// sub | ||
// /// Subtraction with implied overflow checks from the Solidity 0.8.x compiler. | ||
// function run(InterpreterStateNP memory, Operand operand, Pointer stackTop) internal pure returns (Pointer) { | ||
// uint256 a; | ||
// uint256 b; | ||
// uint256 saturate; | ||
// assembly ("memory-safe") { | ||
// a := mload(stackTop) | ||
// b := mload(add(stackTop, 0x20)) | ||
// stackTop := add(stackTop, 0x40) | ||
// saturate := and(operand, 1) | ||
// } | ||
// function (uint256, uint256) internal pure returns (uint256) f = | ||
// saturate > 0 ? SaturatingMath.saturatingSub : sub; | ||
// a = f(a, b); | ||
|
||
{ | ||
uint256 inputs = (Operand.unwrap(operand) >> 0x10) & 0x0F; | ||
uint256 i = 2; | ||
while (i < inputs) { | ||
assembly ("memory-safe") { | ||
b := mload(stackTop) | ||
stackTop := add(stackTop, 0x20) | ||
} | ||
a = f(a, b); | ||
unchecked { | ||
i++; | ||
} | ||
} | ||
} | ||
// { | ||
// uint256 inputs = (Operand.unwrap(operand) >> 0x10) & 0x0F; | ||
// uint256 i = 2; | ||
// while (i < inputs) { | ||
// assembly ("memory-safe") { | ||
// b := mload(stackTop) | ||
// stackTop := add(stackTop, 0x20) | ||
// } | ||
// a = f(a, b); | ||
// unchecked { | ||
// i++; | ||
// } | ||
// } | ||
// } | ||
|
||
assembly ("memory-safe") { | ||
stackTop := sub(stackTop, 0x20) | ||
mstore(stackTop, a) | ||
} | ||
return stackTop; | ||
} | ||
// assembly ("memory-safe") { | ||
// stackTop := sub(stackTop, 0x20) | ||
// mstore(stackTop, a) | ||
// } | ||
// return stackTop; | ||
// } | ||
|
||
/// Gas intensive reference implementation of subtraction for testing. | ||
function referenceFn(InterpreterStateNP memory, Operand, uint256[] memory inputs) | ||
internal | ||
pure | ||
returns (uint256[] memory outputs) | ||
{ | ||
// Unchecked so that when we assert that an overflow error is thrown, we | ||
// see the revert from the real function and not the reference function. | ||
unchecked { | ||
uint256 acc = inputs[0]; | ||
for (uint256 i = 1; i < inputs.length; i++) { | ||
acc -= inputs[i]; | ||
} | ||
outputs = new uint256[](1); | ||
outputs[0] = acc; | ||
} | ||
} | ||
} | ||
// /// Gas intensive reference implementation of subtraction for testing. | ||
// function referenceFn(InterpreterStateNP memory, Operand, uint256[] memory inputs) | ||
// internal | ||
// pure | ||
// returns (uint256[] memory outputs) | ||
// { | ||
// // Unchecked so that when we assert that an overflow error is thrown, we | ||
// // see the revert from the real function and not the reference function. | ||
// unchecked { | ||
// uint256 acc = inputs[0]; | ||
// for (uint256 i = 1; i < inputs.length; i++) { | ||
// acc -= inputs[i]; | ||
// } | ||
// outputs = new uint256[](1); | ||
// outputs[0] = acc; | ||
// } | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.