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
812 changes: 418 additions & 394 deletions .gas-snapshot

Large diffs are not rendered by default.

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(0xe67bfbe2d8ebe116b64bcb02d5e29330d9ade17c1c3367def6883adee4d399e7);
bytes32 constant BYTECODE_HASH = bytes32(0x201dec199626b955935bb8907110beb3f69aeb86c149be19adf8adb5a01ec361);

/// @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"07120744076808f409bd09cf09e109fa0a1e0a520a630a740b160b350be40c680c790c8a0c8a0c9b0d280d410d550d6e0d870d9a0dfc0e4a0e7b0ec90f170ffe";
hex"071c074e077208fe09c709d909eb0a040a280a5c0a6d0a7e0b200b3f0bee0c720c830c940c940ca50d320d4b0d5f0d780d910da40e060e540e850ed30f210f6f1056";
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(0x84daba4ae586abd5a30c407378175e919ea82b291b9bff08604debfa5e59d183);
bytes32 constant BYTECODE_HASH = bytes32(0x32ce28951182ae67a8783f6c482e3433eda8756bab71349543b7c621816c6c92);

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

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

/// @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(0xd292c1e12f252b9afbe785ce00e0c8980c99b
/// 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"01092404940810009008201088000400e0010080000800001028010100080900090002cd70471e14fbe61685cf8700f861d11ad0e20c0e8be82d1f7c7f8004e5ab37194d06d00d67df8415fedd510602c61f08bcae760bcd088610f1c17805ac4b9f0a09bc09180ce432091ef7b011dfb72601a91367121faf890c2b9f481ce804c11bbd68ce14811fdb1726c459034a067c0fffb07907743c4a1d15024513edf10f";
hex"01092404940810009008201088000400e0010080000800001028010100080902090002cd70471f14fbe61c85bda21685cf8700f861d11ad0e20c0e8be82d207c7f8004e5ab37194d06d00d67df8415fedd510602c61f08bcae760bcd088610f1c17805ac4b9f0a09bc09180ce432091ef7b011dfb72601a91367121faf890c2b9f481de804c11bbd68ce14811fdb1726c459034a067c0fffb07907743c4a1e15024513edf10f";

/// @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"199a199a199a1a6f1b861b861b861a6f1a6f199a199a199a1b861b861b861b861b861b861b861b861b861b861b861b861b861b861b861b861b86199a1b861b86";
hex"19a219a219a21a771b8e1b8e1b8e1a771a7719a219a219a21b8e1b8e1b8e1b8e1b8e1b8e1b8e1b8e1b8e1b8e1b8e1b8e1b8e1b8e1b8e1b8e1b8e1b8e19a21b8e1b8e";

/// @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"14e21714175717f5";
bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"14ea171c175f17fd";
12 changes: 6 additions & 6 deletions src/lib/op/LibAllStandardOps.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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 = 32;
uint256 constant ALL_STANDARD_OPS_LENGTH = 33;

/// @title LibAllStandardOps
/// @notice Every opcode available from the core repository laid out as a single
Expand Down Expand Up @@ -269,7 +269,7 @@ library LibAllStandardOps {
"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."
),
// AuthoringMetaV2("min", "Finds the minimum number from all inputs."),
AuthoringMetaV2("min", "Finds the minimum number from all inputs."),
// 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 @@ -481,8 +481,8 @@ library LibAllStandardOps {
// LibParseOperand.handleOperandDisallowed,
// max-value
LibParseOperand.handleOperandDisallowed,
// // min
// LibParseOperand.handleOperandDisallowed,
// min
LibParseOperand.handleOperandDisallowed,
// // mod
// LibParseOperand.handleOperandDisallowed,
// mul
Expand Down Expand Up @@ -603,7 +603,7 @@ library LibAllStandardOps {
// LibOpLog10.integrity,
// LibOpMax.integrity,
LibOpMaxValue.integrity,
// LibOpMin.integrity,
LibOpMin.integrity,
// LibOpMod.integrity,
LibOpMul.integrity,
// LibOpPow.integrity,
Expand Down Expand Up @@ -715,7 +715,7 @@ library LibAllStandardOps {
// LibOpLog10.run,
// LibOpMax.run,
LibOpMaxValue.run,
// LibOpMin.run,
LibOpMin.run,
// LibOpMod.run,
LibOpMul.run,
// LibOpPow.run,
Expand Down
27 changes: 13 additions & 14 deletions src/lib/op/math/LibOpMin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {OperandV2} from "rain.interpreter.interface/interface/unstable/IInterpre
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";
import {StackItem} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";

/// @title LibOpMin
/// @notice Opcode to find the min from N integers.
Expand All @@ -19,16 +21,14 @@ library LibOpMin {
/// min
/// Finds the minimum value from N integers.
function run(InterpreterState memory, OperandV2 operand, Pointer stackTop) internal pure returns (Pointer) {
uint256 a;
uint256 b;
Float a;
Float b;
assembly ("memory-safe") {
a := mload(stackTop)
b := mload(add(stackTop, 0x20))
stackTop := add(stackTop, 0x40)
}
if (a > b) {
a = b;
}
a = LibDecimalFloat.min(a, b);

{
uint256 inputs = uint256((OperandV2.unwrap(operand) >> 0x10) & bytes32(uint256(0x0F)));
Expand All @@ -38,9 +38,8 @@ library LibOpMin {
b := mload(stackTop)
stackTop := add(stackTop, 0x20)
}
if (a > b) {
a = b;
}
a = LibDecimalFloat.min(a, b);

unchecked {
i++;
}
Expand All @@ -55,20 +54,20 @@ library LibOpMin {
}

/// Gas intensive reference implementation of minimum for testing.
function referenceFn(InterpreterState memory, OperandV2, uint256[] memory inputs)
function referenceFn(InterpreterState memory, OperandV2, StackItem[] memory inputs)
internal
pure
returns (uint256[] memory outputs)
returns (StackItem[] 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];
Float acc = Float.wrap(StackItem.unwrap(inputs[0]));
for (uint256 i = 1; i < inputs.length; i++) {
acc = acc > inputs[i] ? inputs[i] : acc;
acc = LibDecimalFloat.min(acc, Float.wrap(StackItem.unwrap(inputs[i])));
}
outputs = new uint256[](1);
outputs[0] = acc;
outputs = new StackItem[](1);
outputs[0] = StackItem.wrap(Float.unwrap(acc));
}
}
}
Loading
Loading