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

/// @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"071c074e077208fe09c709d909eb0a040a280a5c0a6d0a7e0b200b3f0bee0c720c830c940c940ca50d320d4b0d5f0d780d910da40e060e540e850ed30f210f6f1056";
hex"07250757077b090709d009e209f40a0d0a310a650a760a870b290b480bf70c7b0c8c0c9d0c9d0cae0d3b0d540d680d810d9a0dad0e0f0e5d0eab0edc0f2a0f780fc610ad";
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(0x32ce28951182ae67a8783f6c482e3433eda8756bab71349543b7c621816c6c92);
bytes32 constant BYTECODE_HASH = bytes32(0x3dfba5f094aad903d939aeb443521b162f8a902e75fe1ddfcd9214d215b2f4da);

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

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

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

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

/// @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"14ea171c175f17fd";
bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"14f2172417671805";
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 = 33;
uint256 constant ALL_STANDARD_OPS_LENGTH = 34;

/// @title LibAllStandardOps
/// @notice Every opcode available from the core repository laid out as a single
Expand Down Expand Up @@ -264,7 +264,7 @@ library LibAllStandardOps {
// AuthoringMetaV2("ln", "Natural logarithm ln(x). Errors if the number is zero."),
// AuthoringMetaV2("log2", "Base 2 logarithm log2(x). Errors if the number is zero."),
// AuthoringMetaV2("log10", "Base 10 logarithm log10(x). Errors if the number is zero."),
// AuthoringMetaV2("max", "Finds the maximum number from all inputs."),
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."
Expand Down Expand Up @@ -477,8 +477,8 @@ library LibAllStandardOps {
// LibParseOperand.handleOperandDisallowed,
// // log10
// LibParseOperand.handleOperandDisallowed,
// // max
// LibParseOperand.handleOperandDisallowed,
// max
LibParseOperand.handleOperandDisallowed,
// max-value
LibParseOperand.handleOperandDisallowed,
// min
Expand Down Expand Up @@ -601,7 +601,7 @@ library LibAllStandardOps {
// LibOpLn.integrity,
// LibOpLog2.integrity,
// LibOpLog10.integrity,
// LibOpMax.integrity,
LibOpMax.integrity,
LibOpMaxValue.integrity,
LibOpMin.integrity,
// LibOpMod.integrity,
Expand Down Expand Up @@ -713,7 +713,7 @@ library LibAllStandardOps {
// LibOpLn.run,
// LibOpLog2.run,
// LibOpLog10.run,
// LibOpMax.run,
LibOpMax.run,
LibOpMaxValue.run,
LibOpMin.run,
// LibOpMod.run,
Expand Down
30 changes: 14 additions & 16 deletions src/lib/op/math/LibOpMax.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ 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 LibOpMax
/// @notice Opcode to find the max from N integers.
/// @notice Opcode to find the max from N floats.
library LibOpMax {
function integrity(IntegrityCheckState memory, OperandV2 operand) internal pure returns (uint256, uint256) {
// There must be at least two inputs.
Expand All @@ -17,18 +19,16 @@ library LibOpMax {
}

/// max
/// Finds the maximum value from N integers.
/// Finds the maximum value from N floats.
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.max(a, b);

{
uint256 inputs = uint256((OperandV2.unwrap(operand) >> 0x10) & bytes32(uint256(0x0F)));
Expand All @@ -38,9 +38,7 @@ library LibOpMax {
b := mload(stackTop)
stackTop := add(stackTop, 0x20)
}
if (a < b) {
a = b;
}
a = LibDecimalFloat.max(a, b);
unchecked {
i++;
}
Expand All @@ -55,20 +53,20 @@ library LibOpMax {
}

/// Gas intensive reference implementation of maximum 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.max(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));
}
}
}
4 changes: 2 additions & 2 deletions src/lib/op/math/LibOpMin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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.
/// @notice Opcode to find the min from N floats.
library LibOpMin {
function integrity(IntegrityCheckState memory, OperandV2 operand) internal pure returns (uint256, uint256) {
// There must be at least two inputs.
Expand All @@ -19,7 +19,7 @@ library LibOpMin {
}

/// min
/// Finds the minimum value from N integers.
/// Finds the minimum value from N floats.
function run(InterpreterState memory, OperandV2 operand, Pointer stackTop) internal pure returns (Pointer) {
Float a;
Float b;
Expand Down
33 changes: 4 additions & 29 deletions src/lib/op/math/LibOpMul.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,13 @@ library LibOpMul {
// 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 {
Float a;
uint256 overflows = 0;
(int256 signedCoefficientA, int256 exponentA) =
LibDecimalFloat.unpack(Float.wrap(StackItem.unwrap(inputs[0])));
if (int32(exponentA) != exponentA) {
overflows++;
}
Float acc = Float.wrap(StackItem.unwrap(inputs[0]));
for (uint256 i = 1; i < inputs.length; i++) {
(int256 signedCoefficientB, int256 exponentB) =
LibDecimalFloat.unpack(Float.wrap(StackItem.unwrap(inputs[i])));
if (int32(exponentB) != exponentB) {
overflows++;
break;
}

(signedCoefficientA, exponentA) =
LibDecimalFloatImplementation.mul(signedCoefficientA, exponentA, signedCoefficientB, exponentB);

if (int32(exponentA) != exponentA) {
overflows++;
break;
}
}
outputs = new StackItem[](1);

if (overflows > 0) {
a = Float.wrap(keccak256(abi.encodePacked("overflow sentinel")));
} else {
a = LibDecimalFloat.packLossless(signedCoefficientA, exponentA);
acc = LibDecimalFloat.mul(acc, Float.wrap(StackItem.unwrap(inputs[i])));
}

outputs[0] = StackItem.wrap(Float.unwrap(a));
outputs = new StackItem[](1);
outputs[0] = StackItem.wrap(Float.unwrap(acc));

return outputs;
}
Expand Down
Loading
Loading