This repository was archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathOpSelectLte.sol
More file actions
62 lines (57 loc) · 2.12 KB
/
OpSelectLte.sol
File metadata and controls
62 lines (57 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: CAL
pragma solidity ^0.8.15;
import "../../../tier/libraries/TierwiseCombine.sol";
import "../../run/LibStackPointer.sol";
import "../../run/LibInterpreterState.sol";
import "../../deploy/LibIntegrityCheck.sol";
import "../../../math/Binary.sol";
/// @title OpSelectLte
/// @notice Exposes `TierwiseCombine.selectLte` as an opcode.
library OpSelectLte {
using LibStackPointer for StackPointer;
using LibStackPointer for uint256[];
using LibIntegrityCheck for IntegrityCheckState;
function integrity(
IntegrityCheckState memory integrityCheckState_,
Operand operand_,
StackPointer stackTop_
) internal pure returns (StackPointer) {
unchecked {
if (Operand.unwrap(operand_) == 0) {
revert OperandUnderflow(1, 0);
}
return
integrityCheckState_.push(
integrityCheckState_.pop(
stackTop_,
Operand.unwrap(operand_)
)
);
}
}
// Stacks the result of a `selectLte` combinator.
// All `selectLte` share the same stack and argument handling.
// Takes the `logic_` and `mode_` from the `operand_` high bits.
// `logic_` is the highest bit.
// `mode_` is the 2 highest bits after `logic_`.
// The other bits specify how many values to take from the stack
// as reports to compare against each other and the block number.
function run(
InterpreterState memory,
Operand operand_,
StackPointer stackTop_
) internal pure returns (StackPointer) {
unchecked {
uint256 inputs_ = Operand.unwrap(operand_) & MASK_8BIT;
uint256 mode_ = (Operand.unwrap(operand_) >> 8) & MASK_2BIT;
uint256 logic_ = Operand.unwrap(operand_) >> 10;
(uint256 time_, uint256[] memory reports_) = stackTop_.list(
inputs_
);
return
reports_.asStackPointer().push(
TierwiseCombine.selectLte(logic_, mode_, time_, reports_)
);
}
}
}