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
120 changes: 66 additions & 54 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 @@ -9,11 +9,11 @@
pragma solidity =0.8.25;

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

/// @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"06ce071e076009280a0f0a210a330a4c0a8e0ae00af10b020ba40be10c900d140d430d920d920dc10eb7";
hex"06d70727076909310a180a2a0a3c0a550a970ae90afa0b0b0bad0bea0c990d1d0d4c0d7b0dca0dca0df90eef";
6 changes: 3 additions & 3 deletions src/generated/RainterpreterExpressionDeployer.pointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
pragma solidity =0.8.25;

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

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

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

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

/// @dev The parse meta that is used to lookup word definitions.
/// The structure of the parse meta is:
Expand All @@ -28,7 +28,7 @@ bytes32 constant BYTECODE_HASH = bytes32(0xcd53a237a45964c4dec598f020953afc10b49
/// 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"010400000084000020000100001480c000080022000000000a08000004004020248012247f9a0c1a71f803f3886500e75aa00b0a5e5a04c0e25d0f17e2ab0560a375134b1708083394ab0e908778020d55c6118cb51c01cc16a510c43a440dacafd5099918c50ab2278f14cae7b20698c5d007a441f5";
hex"010400000084000020000100001480c000088022000000000a08000004004020248013247f9a0c1a71f803f3886500e75aa00b0a5e5a04c0e25d1017e2ab0560a375144b1708083394ab0e9087780f97bf37020d55c6128cb51c01cc16a511c43a440dacafd5099918c50ab2278f15cae7b20698c5d007a441f5";

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

Expand All @@ -38,11 +38,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"1d001d001d001dc91ec81ec81ec81dc91dc91d001d001d001ec81ec81ec81ec81ec81ec81ec81ec81ec8";
hex"1d081d081d081dd11ed01ed01ed01dd11dd11d081d081d081ed01ed01ed01ed01ed01ed01ed01ed01ed01ed0";

/// @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"173c1a041a351b0f";
bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"17441a0c1a3d1b17";
14 changes: 7 additions & 7 deletions src/lib/op/LibAllStandardOps.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {LibOpERC721OwnerOf} from "./erc721/LibOpERC721OwnerOf.sol";

import {LibOpERC5313OwnerNP} from "./erc5313/LibOpERC5313OwnerNP.sol";

import {LibOpBlockNumberNP} from "./evm/LibOpBlockNumberNP.sol";
import {LibOpBlockNumber} from "./evm/LibOpBlockNumber.sol";
import {LibOpChainId} from "./evm/LibOpChainId.sol";
import {LibOpMaxUint256NP} from "./evm/LibOpMaxUint256NP.sol";
import {LibOpTimestamp} from "./evm/LibOpTimestamp.sol";
Expand Down Expand Up @@ -103,7 +103,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 = 21;
uint256 constant ALL_STANDARD_OPS_LENGTH = 22;

/// @title LibAllStandardOps
/// @notice Every opcode available from the core repository laid out as a single
Expand Down Expand Up @@ -193,7 +193,7 @@ library LibAllStandardOps {
"erc5313-owner",
"Gets the owner of an erc5313 compatible contract. Note that erc5313 specifically DOES NOT do any onchain compatibility checks, so the expression author is responsible for ensuring the contract is compatible. The input is the contract address to get the owner of."
),
// AuthoringMetaV2("block-number", "The current block number."),
AuthoringMetaV2("block-number", "The current block number."),
AuthoringMetaV2("chain-id", "The current chain id."),
AuthoringMetaV2("uint256-max-value", "The maximum possible unsigned integer value (all binary bits are 1)."),
AuthoringMetaV2("block-timestamp", "The current block timestamp."),
Expand Down Expand Up @@ -400,8 +400,8 @@ library LibAllStandardOps {
LibParseOperand.handleOperandDisallowed,
// erc5313-owner
LibParseOperand.handleOperandDisallowed,
// // block-number
// LibParseOperand.handleOperandDisallowed,
// block-number
LibParseOperand.handleOperandDisallowed,
// chain-id
LibParseOperand.handleOperandDisallowed,
// max-value
Expand Down Expand Up @@ -558,7 +558,7 @@ library LibAllStandardOps {
// LibOpUint256ERC721BalanceOf.integrity,
LibOpERC721OwnerOf.integrity,
LibOpERC5313OwnerNP.integrity,
// LibOpBlockNumberNP.integrity,
LibOpBlockNumber.integrity,
LibOpChainId.integrity,
LibOpMaxUint256NP.integrity,
LibOpTimestamp.integrity,
Expand Down Expand Up @@ -670,7 +670,7 @@ library LibAllStandardOps {
// LibOpUint256ERC721BalanceOf.run,
LibOpERC721OwnerOf.run,
LibOpERC5313OwnerNP.run,
// LibOpBlockNumberNP.run,
LibOpBlockNumber.run,
LibOpChainId.run,
LibOpMaxUint256NP.run,
LibOpTimestamp.run,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
pragma solidity ^0.8.18;

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

/// @title LibOpBlockNumberNP
/// @title LibOpBlockNumber
/// Implementation of the EVM `BLOCKNUMBER` opcode as a standard Rainlang opcode.
library LibOpBlockNumberNP {
library LibOpBlockNumber {
using LibDecimalFloat for Float;

function integrity(IntegrityCheckState memory, OperandV2) internal pure returns (uint256, uint256) {
return (0, 1);
}
Expand All @@ -21,13 +24,14 @@ library LibOpBlockNumberNP {
return stackTop;
}

function referenceFn(InterpreterState memory, OperandV2, uint256[] memory)
function referenceFn(InterpreterState memory, OperandV2, StackItem[] memory)
internal
view
returns (uint256[] memory)
returns (StackItem[] memory)
{
uint256[] memory outputs = new uint256[](1);
outputs[0] = block.number;
StackItem[] memory outputs = new StackItem[](1);
outputs[0] =
StackItem.wrap(PackedFloat.unwrap(LibDecimalFloat.fromFixedDecimalLosslessMem(block.number, 0).pack()));
return outputs;
}
}
78 changes: 78 additions & 0 deletions test/src/lib/op/evm/LibOpBlockNumber.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.25;

import {OpTest} from "test/abstract/OpTest.sol";

import {LibPointer, Pointer} from "rain.solmem/lib/LibPointer.sol";
import {
IInterpreterV4,
OperandV2,
SourceIndexV2,
FullyQualifiedNamespace,
StackItem
} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
import {LibStackPointer} from "rain.solmem/lib/LibStackPointer.sol";
import {IMetaV1} from "rain.metadata/interface/deprecated/IMetaV1.sol";
import {IInterpreterStoreV2} from "rain.interpreter.interface/interface/IInterpreterStoreV2.sol";
import {LibInterpreterState, InterpreterState} from "src/lib/state/LibInterpreterState.sol";
import {IntegrityCheckState, BadOpInputsLength} from "src/lib/integrity/LibIntegrityCheckNP.sol";
import {LibContext} from "rain.interpreter.interface/lib/caller/LibContext.sol";
import {SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV3.sol";
import {LibOpBlockNumber} from "src/lib/op/evm/LibOpBlockNumber.sol";
import {LibOperand} from "test/lib/operand/LibOperand.sol";

/// @title LibOpBlockNumberTest
/// @notice Test the runtime and integrity time logic of LibOpBlockNumber.
contract LibOpBlockNumberTest is OpTest {
using LibPointer for Pointer;
using LibStackPointer for Pointer;
using LibInterpreterState for InterpreterState;

/// Directly test the integrity logic of LibOpBlockNumber.
function testOpBlockNumberIntegrity(
IntegrityCheckState memory state,
uint8 inputs,
uint8 outputs,
uint16 operandData
) external pure {
inputs = uint8(bound(inputs, 0, 0x0F));
outputs = uint8(bound(outputs, 0, 0x0F));
(uint256 calcInputs, uint256 calcOutputs) =
LibOpBlockNumber.integrity(state, LibOperand.build(inputs, outputs, operandData));

assertEq(calcInputs, 0);
assertEq(calcOutputs, 1);
}

/// Directly test the runtime logic of LibOpBlockNumber. This tests that the
/// opcode correctly pushes the block number onto the stack.
function testOpBlockNumberRun(uint256 blockNumber, uint16 operandData) external {
blockNumber = bound(blockNumber, 0, uint256(uint128(type(int128).max)));
InterpreterState memory state = opTestDefaultInterpreterState();
vm.roll(blockNumber);
StackItem[] memory inputs = new StackItem[](0);
OperandV2 operand = LibOperand.build(0, 1, operandData);
opReferenceCheck(
state, operand, LibOpBlockNumber.referenceFn, LibOpBlockNumber.integrity, LibOpBlockNumber.run, inputs
);
}

/// Test the eval of a block number opcode parsed from a string.
function testOpBlockNumberEval(uint256 blockNumber) public {
blockNumber = bound(blockNumber, 0, uint256(int256(type(int128).max)));
vm.roll(blockNumber);
checkHappy("_: block-number();", bytes32(uint256(blockNumber)), "");
}

function testOpBlockNumberEvalOneInput() external {
checkBadInputs("_: block-number(0x00);", 1, 0, 1);
}

function testOpBlockNumberEvalZeroOutputs() external {
checkBadOutputs(": block-number();", 0, 1, 0);
}

function testOpBlockNumberEvalTwoOutputs() external {
checkBadOutputs("_ _: block-number();", 0, 1, 2);
}
}
77 changes: 0 additions & 77 deletions test/src/lib/op/evm/LibOpBlockNumberNP.t.sol

This file was deleted.