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
956 changes: 512 additions & 444 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(0x1f82584ad80b630eb25769669c965fc8efff9d8f9cd3dcc6f9fc0ac842e81474);
bytes32 constant BYTECODE_HASH = bytes32(0xca873fdc0fafdd8622956664b1ff707a348e5086104c9df4041da19e4ed40eb2);

/// @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"07c607f8081c09a80a710a830a950aae0ad20b060b170b280bca0be90ca70d570ddb0f1d10500ca7114911fb129d13151326133713371348138f1411142a143e14571470149b14b414cd14e01542159015de162c167a16c817161724177217a317f1183f188d1974";
hex"07d8080a082e09ba0a830a950aa70ac00ae40b180b290b3a0bdc0bfb0cb90d690ded0f2f10620cb9115b120d12af1327133813491349135a13a11423143c14501469148214ad14c614df14f2155415a215f0163e168c16da17281759176717b517e61834186518b3190119e8";
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(0xb76a360580b20009cee2999206d01cce8a7be9c16321becaa7a8897a4e8fc30c);
bytes32 constant BYTECODE_HASH = bytes32(0xbde8830f32466859d248ddbd93c3160f528590905b62e571cdf67a18f501b881);

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

/// @dev The function pointers for the integrity check fns.
bytes constant INTEGRITY_FUNCTION_POINTERS =
hex"0e580ed60f3a10b410be10be10c810d110ec1192119211ee1266127310be10c8127310be10c810be10be10be10c810b410b410b410b4127d12a210be10be10be10be10c810be10be10b412ac12ac12ac12ac12ac12ac12c610c812ac10b412ac12c612c610c812a2";
hex"0e680ee60f4a10c410ce10ce10d810e110fc11a211a211fe1276128310ce10d8128310ce10d810ce10ce10ce10d810c410c410c410c4128d12b210ce10ce10ce10ce10d810ce10ce10c412bc12bc12bc12bc12bc12bc12d610c410d812bc10c412bc10c412d612d610d812b2";
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(0x680382e10b1fa1d3a16b62c994f80ced2eff3fbd3cb51ed90817bf25bb904f08);
bytes32 constant BYTECODE_HASH = bytes32(0x2dd95b73bafe92197b507ea6cded7f00121a8dedfc9779057387ad0cdd34cb46);

/// @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(0x680382e10b1fa1d3a16b62c994f80ced2eff3
/// 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"0178ac80600029b010910908a00a3448c001280030060100180000200cc2200408a00c95d8383248145c3334b3f32ed587e204afc8f01e95a26007b9a51f0d5e6f2803ce312215fae0a1271233de118cfd53051c784d25a55ade1681ac9622ac6dfc2fa4e5e91f5fc32a0e92b2401dbbd837100ef76b00cd8814205902e62a9714ec13313592290d473b21f880501427634f0f23b4970ac0e53d0b895f991ac908be0983724f12c080bc309d7b7d28757aea2c3a7b86266f62e02b5c0ab5086d2a7b2390a6b319bcb24402af7d4506414b8117b04fb31cb2182f18ef532924c301e31b9314ad31fa5d8001336a592dab2461";
hex"0178ac80600029b010910908a00a7448c001280030060500180000200cc2200408a00c95d8383448145c3534b3f32fd587e204afc8f01e95a26007b9a51f0d5e6f2803ce312215fae0a1271233de118cfd53051c784d25a55ade3112233f1681ac9622ac6dfc30a4e5e91f5fc32a0e92b2401dbbd837100ef76b00cd8814205902e62a9714ec13313592290d473b21f880501427634f2ce048d30f23b4970ac0e53d0b895f991ac908be0983724f12c080bc329d7b7d28757aea2d3a7b86266f62e02b5c0ab5086d2a7b2390a6b319bcb24402af7d4506414b8117b04fb31cb2182f18ef532924c301e31b9314ad33fa5d8001336a592eab2461";

/// @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"1a3b1a3b1a3b1b101c271c271c271b101b101a3b1a3b1a3b1c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271c271a3b1c271c27";
hex"1a4b1a4b1a4b1b201c371c371c371b201b201a4b1a4b1a4b1c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371c371a4b1c371c37";

/// @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"158317b517f81896";
bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"159317c5180818a6";
25 changes: 17 additions & 8 deletions src/lib/op/LibAllStandardOps.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import {LibOpAdd} from "./math/LibOpAdd.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";
import {LibOpE} from "./math/LibOpE.sol";
// import {LibOpExp} from "./math/LibOpExp.sol";
// import {LibOpExp2} from "./math/LibOpExp2.sol";
// import {LibOpFloor} from "./math/LibOpFloor.sol";
Expand All @@ -87,6 +87,7 @@ import {LibOpInv} from "./math/LibOpInv.sol";
import {LibOpMax} from "./math/LibOpMax.sol";
import {LibOpMaxValue} from "./math/LibOpMaxValue.sol";
import {LibOpMin} from "./math/LibOpMin.sol";
import {LibOpMinValue} from "./math/LibOpMinValue.sol";
import {LibOpMod} from "./math/LibOpMod.sol";
// import {LibOpLog2} from "./math/LibOpLog2.sol";
// import {LibOpPow} from "./math/LibOpPow.sol";
Expand All @@ -108,7 +109,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 = 52;
uint256 constant ALL_STANDARD_OPS_LENGTH = 54;

/// @title LibAllStandardOps
/// @notice Every opcode available from the core repository laid out as a single
Expand Down Expand Up @@ -267,7 +268,7 @@ library LibAllStandardOps {
// AuthoringMetaV2("avg", "Arithmetic average (mean) of two numbers."),
// AuthoringMetaV2("ceil", "Ceiling of a number."),
AuthoringMetaV2("div", "Divides the first number by all other numbers. Errors if any divisor is zero."),
// AuthoringMetaV2("e", "The mathematical constant e."),
AuthoringMetaV2("e", "The mathematical constant e."),
// AuthoringMetaV2("exp", "Natural exponential e^x. Errors if the exponentiation exceeds `max-value()`."),
// AuthoringMetaV2("exp2", "Binary exponential 2^x where x. Errors if the exponentiation exceeds `max-value()`."),
// AuthoringMetaV2("floor", "Floor of a number."),
Expand All @@ -284,9 +285,13 @@ library LibAllStandardOps {
AuthoringMetaV2("max", "Finds the maximum number from all inputs."),
AuthoringMetaV2(
"max-value",
"The maximum representable float value. This is so large that it is effectively infinity (it has ~2.1 billion zero digits). Almost all numbers that you could possibly subtract from it will be ignored as a rounding error."
"The maximum representable float value. This is so large that it is effectively infinity. Almost all numbers that you could possibly subtract from it will be ignored as a rounding error."
),
AuthoringMetaV2("min", "Finds the minimum number from all inputs."),
AuthoringMetaV2(
"min-value",
"The minimum representable float value. This is so small that it is effectively negative infinity. Almost all numbers that you could possibly add to it will be ignored as a rounding error."
),
// AuthoringMetaV2("mod", "Modulos the first number by all other numbers. Errors if any divisor is zero."),
AuthoringMetaV2("mul", "Multiplies all numbers together."),
// AuthoringMetaV2(
Expand Down Expand Up @@ -478,8 +483,8 @@ library LibAllStandardOps {
// LibParseOperand.handleOperandDisallowed,
// div
LibParseOperand.handleOperandDisallowed,
// // e
// LibParseOperand.handleOperandDisallowed,
// e
LibParseOperand.handleOperandDisallowed,
// // exp
// LibParseOperand.handleOperandDisallowed,
// // exp2
Expand All @@ -506,6 +511,8 @@ library LibAllStandardOps {
LibParseOperand.handleOperandDisallowed,
// min
LibParseOperand.handleOperandDisallowed,
// min-value
LibParseOperand.handleOperandDisallowed,
// // mod
// LibParseOperand.handleOperandDisallowed,
// mul
Expand Down Expand Up @@ -616,7 +623,7 @@ library LibAllStandardOps {
// LibOpAvg.integrity,
// LibOpCeil.integrity,
LibOpDiv.integrity,
// LibOpE.integrity,
LibOpE.integrity,
// LibOpExp.integrity,
// LibOpExp2.integrity,
// LibOpFloor.integrity,
Expand All @@ -630,6 +637,7 @@ library LibAllStandardOps {
LibOpMax.integrity,
LibOpMaxValue.integrity,
LibOpMin.integrity,
LibOpMinValue.integrity,
// LibOpMod.integrity,
LibOpMul.integrity,
// LibOpPow.integrity,
Expand Down Expand Up @@ -731,7 +739,7 @@ library LibAllStandardOps {
// LibOpAvg.run,
// LibOpCeil.run,
LibOpDiv.run,
// LibOpE.run,
LibOpE.run,
// LibOpExp.run,
// LibOpExp2.run,
// LibOpFloor.run,
Expand All @@ -745,6 +753,7 @@ library LibAllStandardOps {
LibOpMax.run,
LibOpMaxValue.run,
LibOpMin.run,
LibOpMinValue.run,
// LibOpMod.run,
LibOpMul.run,
// LibOpPow.run,
Expand Down
58 changes: 30 additions & 28 deletions src/lib/op/math/LibOpE.sol
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
// SPDX-License-Identifier: CAL
pragma solidity ^0.8.18;

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

// /// @title LibOpE
// /// Stacks the mathematical constant e.
// library LibOpE {
// function integrity(IntegrityCheckState memory, Operand) internal pure returns (uint256, uint256) {
// return (0, 1);
// }
/// @title LibOpE
/// Stacks the mathematical constant e.
library LibOpE {
function integrity(IntegrityCheckState memory, OperandV2) internal pure returns (uint256, uint256) {
return (0, 1);
}

// function run(InterpreterState memory, Operand, Pointer stackTop) internal pure returns (Pointer) {
// uint256 e = FIXED_POINT_E;
// assembly ("memory-safe") {
// stackTop := sub(stackTop, 0x20)
// mstore(stackTop, e)
// }
// return stackTop;
// }
function run(InterpreterState memory, OperandV2, Pointer stackTop) internal pure returns (Pointer) {
Float e = LibDecimalFloat.FLOAT_E;
assembly ("memory-safe") {
stackTop := sub(stackTop, 0x20)
mstore(stackTop, e)
}
return stackTop;
}

// function referenceFn(InterpreterState memory, Operand, uint256[] memory)
// internal
// pure
// returns (uint256[] memory)
// {
// uint256[] memory outputs = new uint256[](1);
// outputs[0] = FIXED_POINT_E;
// return outputs;
// }
// }
function referenceFn(InterpreterState memory, OperandV2, StackItem[] memory)
internal
pure
returns (StackItem[] memory)
{
StackItem[] memory outputs = new StackItem[](1);
outputs[0] = StackItem.wrap(Float.unwrap(LibDecimalFloat.FLOAT_E));
return outputs;
}
}
4 changes: 1 addition & 3 deletions src/lib/op/math/LibOpMaxValue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {InterpreterState} from "../../state/LibInterpreterState.sol";
import {Pointer} from "rain.solmem/lib/LibPointer.sol";
import {Float, LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

uint256 constant MAX_VALUE = uint256(0x7fffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffff);

/// @title LibOpMaxValue
/// Exposes the maximum representable float value as a Rainlang opcode.
library LibOpMaxValue {
Expand All @@ -19,7 +17,7 @@ library LibOpMaxValue {
}

function run(InterpreterState memory, OperandV2, Pointer stackTop) internal pure returns (Pointer) {
uint256 value = MAX_VALUE;
Float value = LibDecimalFloat.FLOAT_MAX_VALUE;
assembly ("memory-safe") {
stackTop := sub(stackTop, 0x20)
mstore(stackTop, value)
Expand Down
37 changes: 37 additions & 0 deletions src/lib/op/math/LibOpMinValue.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: CAL
pragma solidity ^0.8.18;

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

/// @title LibOpMinValue
/// Exposes the minimum representable float value as a Rainlang opcode.
library LibOpMinValue {
using LibDecimalFloat for Float;

function integrity(IntegrityCheckState memory, OperandV2) internal pure returns (uint256, uint256) {
return (0, 1);
}

function run(InterpreterState memory, OperandV2, Pointer stackTop) internal pure returns (Pointer) {
Float value = LibDecimalFloat.FLOAT_MIN_NEGATIVE_VALUE;
assembly ("memory-safe") {
stackTop := sub(stackTop, 0x20)
mstore(stackTop, value)
}
return stackTop;
}

function referenceFn(InterpreterState memory, OperandV2, StackItem[] memory)
internal
pure
returns (StackItem[] memory)
{
StackItem[] memory outputs = new StackItem[](1);
outputs[0] = StackItem.wrap(Float.unwrap(LibDecimalFloat.packLossless(type(int224).min, type(int32).max)));
return outputs;
}
}
Loading
Loading