Skip to content
Merged
Show file tree
Hide file tree
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
1,617 changes: 812 additions & 805 deletions .gas-snapshot

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/rain.interpreter.interface
4 changes: 2 additions & 2 deletions src/generated/Rainterpreter.pointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
pragma solidity =0.8.25;

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0x058f6e179954062975f1f516e5581e0e4250dc80b12ec528f963b42562314db8);
bytes32 constant BYTECODE_HASH = bytes32(0x12101f163b9f03997261cb8dbba0d24350308e2583d2456ffecf3761813ca62a);

/// @dev The function pointers known to the interpreter for dynamic dispatch.
/// By setting these as a constant they can be inlined into the interpreter
/// and loaded at eval time for very low gas (~100) due to the compiler
/// optimising it to a single `codecopy` to build the in memory bytes array.
bytes constant OPCODE_FUNCTION_POINTERS =
hex"087508a708cb0a570b200b320b440b5d0b810bb50bc60bd70c790c980d560e060e8a0fcc10ff0d5611f812aa134c13c413d513e613e613f71462156d15ec160516191678169116aa16e3170e17271740178917b017c31825187318c1190f195d196b19b919dc1a2a1a5b1a9f1ac41ad21ae01b311b4a1b581ba61bd71c081c561c871cb81d061d331d561da41e9a";
hex"087e08b008d40a600b290b3b0b4d0b660b8a0bbe0bcf0be00c820ca10d5f0e0f0e930fd511080d5f120112b3135513cd13de13ef13ef1400146b157615f5160e16221681169a16b316ec171717301749179217b917cc182e187c18ca19181966197419c219e519f31a411a721ab61adb1ae91af71b481b921ba01bee1c1f1c501c9e1ccf1d001d4e1d7b1d9e1dec1ee2";
6 changes: 3 additions & 3 deletions src/generated/RainterpreterExpressionDeployer.pointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
pragma solidity =0.8.25;

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0x1b5519183df0925de8b552daa52766a1d41087a630c1869dcbd656e9edacefb7);
bytes32 constant BYTECODE_HASH = bytes32(0xdb19c38314dcae4ac9574bf379a865e3a65fcc1e909ce729d5bd9ca320e2b02d);

/// @dev The hash of the meta that describes the contract.
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0x6160988942c60333bd4c6f09f5ed3d93d5552c9052d9d2bcab6dccc418d0b791);
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0xb2500441a27ea683f814327be6e43c90f516b8f033203ad3e0ba2cde847fb0ba);

/// @dev The function pointers for the integrity check fns.
bytes constant INTEGRITY_FUNCTION_POINTERS =
hex"0ef00f6e0fd2114c11561156116011691184122a122a128612fe130b11561160130b115611601156115611561160114c114c114c114c1315133a135411561156131511561156130b116011561156130b130b114c135e135e135e135e135e1160135e11561378114c1160116011601160115611601160135e114c114c135e114c114c137811561160137811601354";
hex"0ef80f760fda1154115e115e11681171118c12321232128e13061313115e11681313115e1168115e115e115e11681154115411541154131d1342135c115e115e131d115e115e13131168115e115e1313131311541366136613661366136611681366115e1168138011541168116811681168115e116811681366115411541366115411541380115e116813801168135c";
8 changes: 4 additions & 4 deletions src/generated/RainterpreterParser.pointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
pragma solidity =0.8.25;

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0x914aa90ef2bb7b6068265b57a391e3d01a0683a84a1b9cdfb5622c0d4952ddaa);
bytes32 constant BYTECODE_HASH = bytes32(0x994bd986f9fbac0f25488fe3a5ea2c7d039d0f9465e2db37c9321a046a74ed8f);

/// @dev The parse meta that is used to lookup word definitions.
/// The structure of the parse meta is:
Expand All @@ -29,7 +29,7 @@ bytes32 constant BYTECODE_HASH = bytes32(0x914aa90ef2bb7b6068265b57a391e3d01a068
/// bit count of the previous bloom filter. If we reach the end of the bloom
/// filters then we have a miss.
bytes constant PARSE_META =
hex"027360018812c0058112300804a1a02000120192e89864d17a6030788a0800310122000002000000000000000000000000000000000005000000000000000000000000253bfdf302d3ac012ac8268505b44edf36182f2a14690c630d83a7eb32c5853a08ccb48c3358350a1c21b6884398a6e5262057e32f7e09af17b433693838e9b4161b9cec2b5ab5e8394715a6243c910831738e093542f25d1e8a3fa7150113a32e22720213c659b9225ac7c1285da1bd45cc18770aa63c19048eb6fa018179d300dfb6a91fde8a882cb772ea03596d3111fd7ab9467b42922d4396834258726b1d2330703a94005b21f438852081752c40ff19581ac1a49e30ffeff03be1eec73c24bdfe2760978f232d6a9a09d520ad061480a0294c65fb344763440ecb8d4d0b8b587210e7c1b518e4b09907152b041261f729198ab9053df8942b1b45c1270f22a49a3fa6838c4460cc7c0c668e383e10da5037d6d3e341e7d2ff";
hex"0288400100420b0280046b0641220186adb8a044003012020f2a880521281ac8811a000000400000000000000000000000000000000001000002000000000000000000310ea98a4210f9c54127bda61f6395ad119fb4a8085dbeaf35313e9e09b06d681cfe490634e21ac12783a6cc32d2d2123c22c3e0062f369e1e27267220a0a68d37357696465d217b161120881224f4a8242f1af52841f7290afa3e8640acf3d13b97e9fd00443a4543406bb547b9059d25a3cd1e0ed0c3260b15eb4d13fc94272d27bc4133af2cc23a1b8f6310ca9efe2a3ce35f140068482ec291e3295d68b1455f9a151db98c15239cd9c10c1f69823dc8d3844408d5792f3459d4182c9ff617a5b2cd15c003180df621af0f7ba34c26bb6c412cb066fb1b73563d0210215f3eaa563921098e690457fb180376e7520529b7c530f11de101fcc60522de7ddd193d3d6d2b96c37039cba287367b3af5384eee721aa809353f10da5007c52518";

/// @dev The build depth of the parser meta.

Expand All @@ -39,11 +39,11 @@ uint8 constant PARSE_META_BUILD_DEPTH = 2;
/// These positional indexes all map to the same indexes looked up in the parse
/// meta.
bytes constant OPERAND_HANDLER_FUNCTION_POINTERS =
hex"1ad51ad51ad51baa1cc11cc11cc11baa1baa1ad51ad51ad51cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11cc11ad51cc11cc1";
hex"1add1add1add1bb21cc91cc91cc91bb21bb21add1add1add1cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91cc91add1cc91cc9";

/// @dev Every two bytes is a function pointer for a literal parser.
/// Literal dispatches are determined by the first byte(s) of the literal
/// rather than a full word lookup, and are done with simple conditional
/// jumps as the possibilities are limited compared to the number of words we
/// have.
bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"161d184f18921930";
bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"16251857189a1938";
2 changes: 1 addition & 1 deletion src/generated/RainterpreterReferenceExtern.pointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
pragma solidity =0.8.25;

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0x168110fff91a799133a1d57d94ae612b831f264a5b1853d89eba5d5154ebc941);
bytes32 constant BYTECODE_HASH = bytes32(0x921c56ace3b8670c36bba13dc2e7ae2b002283ebbb87947f147780114604ba73);

/// @dev The hash of the meta that describes the contract.
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0xadf71693c6ecf3fd560904bc46973d1b6e651440d15366673f9b3984749e7c16);
Expand Down
14 changes: 7 additions & 7 deletions src/lib/op/LibAllStandardOps.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import {LibOpUint256Sub} from "./math/uint256/LibOpUint256Sub.sol";
import {LibOpAbs} from "./math/LibOpAbs.sol";
import {LibOpAdd} from "./math/LibOpAdd.sol";
import {LibOpAvg} from "./math/LibOpAvg.sol";
// import {LibOpCeil} from "./math/LibOpCeil.sol";
import {LibOpCeil} from "./math/LibOpCeil.sol";
import {LibOpMul} from "./math/LibOpMul.sol";
import {LibOpDiv} from "./math/LibOpDiv.sol";
import {LibOpE} from "./math/LibOpE.sol";
Expand Down Expand Up @@ -112,7 +112,7 @@ import {LibParseLiteralHex} from "../parse/literal/LibParseLiteralHex.sol";
import {LibParseLiteralSubParseable} from "../parse/literal/LibParseLiteralSubParseable.sol";

/// @dev Number of ops currently provided by `AllStandardOps`.
uint256 constant ALL_STANDARD_OPS_LENGTH = 71;
uint256 constant ALL_STANDARD_OPS_LENGTH = 72;
Comment thread
thedavidmeister marked this conversation as resolved.

/// @title LibAllStandardOps
/// @notice Every opcode available from the core repository laid out as a single
Expand Down Expand Up @@ -270,7 +270,7 @@ library LibAllStandardOps {
AuthoringMetaV2("abs", "The absolute value of a number."),
AuthoringMetaV2("add", "Adds all numbers together."),
AuthoringMetaV2("avg", "Arithmetic average (mean) of two numbers."),
// AuthoringMetaV2("ceil", "Ceiling of a number."),
AuthoringMetaV2("ceil", "Ceiling of a number. Lowest integer greater than or equal to the number."),
AuthoringMetaV2("div", "Divides the first number by all other numbers. Errors if any divisor is zero."),
AuthoringMetaV2("e", "The mathematical constant e."),
AuthoringMetaV2("exp", "Natural exponential e^x."),
Expand Down Expand Up @@ -466,8 +466,8 @@ library LibAllStandardOps {
LibParseOperand.handleOperandDisallowed,
// avg
LibParseOperand.handleOperandDisallowed,
// // ceil
// LibParseOperand.handleOperandDisallowed,
// ceil
LibParseOperand.handleOperandDisallowed,
// div
LibParseOperand.handleOperandDisallowed,
// e
Expand Down Expand Up @@ -601,7 +601,7 @@ library LibAllStandardOps {
LibOpAbs.integrity,
LibOpAdd.integrity,
LibOpAvg.integrity,
// LibOpCeil.integrity,
LibOpCeil.integrity,
LibOpDiv.integrity,
LibOpE.integrity,
LibOpExp.integrity,
Expand Down Expand Up @@ -712,7 +712,7 @@ library LibAllStandardOps {
LibOpAbs.run,
LibOpAdd.run,
LibOpAvg.run,
// LibOpCeil.run,
LibOpCeil.run,
LibOpDiv.run,
LibOpE.run,
LibOpExp.run,
Expand Down
76 changes: 40 additions & 36 deletions src/lib/op/math/LibOpCeil.sol
Original file line number Diff line number Diff line change
@@ -1,43 +1,47 @@
// SPDX-License-Identifier: CAL
pragma solidity ^0.8.18;

// import {UD60x18, ceil} from "prb-math/UD60x18.sol";
// import {OperandV2} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
// import {Pointer} from "rain.solmem/lib/LibPointer.sol";
// import {InterpreterState} from "../../state/LibInterpreterState.sol";
// import {IntegrityCheckState} from "../../integrity/LibIntegrityCheck.sol";
import {OperandV2, StackItem} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
import {Pointer} from "rain.solmem/lib/LibPointer.sol";
import {InterpreterState} from "../../state/LibInterpreterState.sol";
import {IntegrityCheckState} from "../../integrity/LibIntegrityCheck.sol";
import {Float, LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

// /// @title LibOpCeil
// /// @notice Opcode for the ceiling of an decimal 18 fixed point number.
// library LibOpCeil {
// function integrity(IntegrityCheckState memory, Operand) internal pure returns (uint256, uint256) {
// // There must be one inputs and one output.
// return (1, 1);
// }
/// @title LibOpCeil
/// @notice Opcode for the ceiling of a decimal floating point number.
library LibOpCeil {
using LibDecimalFloat for Float;

// /// ceil
// /// 18 decimal fixed point ceiling of a number.
// function run(InterpreterState memory, Operand, Pointer stackTop) internal pure returns (Pointer) {
// uint256 a;
// assembly ("memory-safe") {
// a := mload(stackTop)
// }
// a = UD60x18.unwrap(ceil(UD60x18.wrap(a)));
function integrity(IntegrityCheckState memory, OperandV2) internal pure returns (uint256, uint256) {
// There must be one input and one output.
return (1, 1);
}

// assembly ("memory-safe") {
// mstore(stackTop, a)
// }
// return stackTop;
// }
/// ceil
/// decimal floating point ceiling of a number.
function run(InterpreterState memory, OperandV2, Pointer stackTop) internal pure returns (Pointer) {
Float a;
assembly ("memory-safe") {
a := mload(stackTop)
}
a = a.ceil();

// /// Gas intensive reference implementation of ceil for testing.
// function referenceFn(InterpreterState memory, Operand, uint256[] memory inputs)
// internal
// pure
// returns (uint256[] memory)
// {
// uint256[] memory outputs = new uint256[](1);
// outputs[0] = UD60x18.unwrap(ceil(UD60x18.wrap(inputs[0])));
// return outputs;
// }
// }
assembly ("memory-safe") {
mstore(stackTop, a)
}
return stackTop;
}

/// Gas intensive reference implementation of ceil for testing.
function referenceFn(InterpreterState memory, OperandV2, StackItem[] memory inputs)
internal
pure
returns (StackItem[] memory)
{
Float a = Float.wrap(StackItem.unwrap(inputs[0]));
a = a.ceil();
StackItem[] memory outputs = new StackItem[](1);
outputs[0] = StackItem.wrap(Float.unwrap(a));
return outputs;
}
Comment thread
thedavidmeister marked this conversation as resolved.
}
12 changes: 9 additions & 3 deletions src/lib/op/math/LibOpHeadroom.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ library LibOpHeadroom {
assembly ("memory-safe") {
a := mload(stackTop)
}
a = LibDecimalFloat.FLOAT_ONE.sub(a.frac());
a = a.ceil().sub(a);
if (a.isZero()) {
a = LibDecimalFloat.FLOAT_ONE;
}

assembly ("memory-safe") {
mstore(stackTop, a)
Expand All @@ -42,10 +45,13 @@ library LibOpHeadroom {
{
// The headroom is 1 - frac(x).
Float a = Float.wrap(StackItem.unwrap(inputs[0]));
Float headroom = LibDecimalFloat.FLOAT_ONE.sub(a.frac());
a = a.ceil().sub(a);
if (a.isZero()) {
a = LibDecimalFloat.FLOAT_ONE;
}
Comment thread
thedavidmeister marked this conversation as resolved.

StackItem[] memory outputs = new StackItem[](1);
outputs[0] = StackItem.wrap(Float.unwrap(headroom));
outputs[0] = StackItem.wrap(Float.unwrap(a));
return outputs;
}
}
8 changes: 4 additions & 4 deletions test/src/concrete/RainterpreterReferenceExtern.intInc.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ contract RainterpreterReferenceExternIntIncTest is OpTest {
);

StackItem[] memory expectedStack = new StackItem[](3);
expectedStack[0] = StackItem.wrap(Float.unwrap(LibDecimalFloat.packLossless(4e37, -37)));
expectedStack[1] = StackItem.wrap(Float.unwrap(LibDecimalFloat.packLossless(3e37, -37)));
expectedStack[0] = StackItem.wrap(Float.unwrap(LibDecimalFloat.packLossless(4e66, -66)));
expectedStack[1] = StackItem.wrap(Float.unwrap(LibDecimalFloat.packLossless(3e66, -66)));
expectedStack[2] = StackItem.wrap(EncodedExternDispatchV2.unwrap(encodedExternDispatch));

checkHappy(
Expand All @@ -58,8 +58,8 @@ contract RainterpreterReferenceExternIntIncTest is OpTest {
RainterpreterReferenceExtern extern = new RainterpreterReferenceExtern();

StackItem[] memory expectedStack = new StackItem[](2);
expectedStack[0] = StackItem.wrap(Float.unwrap(LibDecimalFloat.packLossless(4e37, -37)));
expectedStack[1] = StackItem.wrap(Float.unwrap(LibDecimalFloat.packLossless(3e37, -37)));
expectedStack[0] = StackItem.wrap(Float.unwrap(LibDecimalFloat.packLossless(4e66, -66)));
expectedStack[1] = StackItem.wrap(Float.unwrap(LibDecimalFloat.packLossless(3e66, -66)));

checkHappy(
bytes(
Expand Down
Loading
Loading