Skip to content

Commit

Permalink
Merge branch 'main' into 2024-08-29-replays
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt authored Sep 3, 2024
2 parents 25bd275 + f391e15 commit d21471c
Show file tree
Hide file tree
Showing 207 changed files with 8,929 additions and 10,547 deletions.
1,764 changes: 615 additions & 1,149 deletions .gas-snapshot

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@
[submodule "lib/rain.lib.memkv"]
path = lib/rain.lib.memkv
url = https://github.com/rainprotocol/rain.lib.memkv
[submodule "lib/prb-math"]
path = lib/prb-math
url = https://github.com/PaulRBerg/prb-math
[submodule "lib/sol.lib.binmaskflag"]
path = lib/sol.lib.binmaskflag
url = https://github.com/rainprotocol/sol.lib.binmaskflag
[submodule "lib/rain.math.fixedpoint"]
path = lib/rain.math.fixedpoint
url = https://github.com/rainprotocol/rain.math.fixedpoint
[submodule "lib/rain.chainlink"]
path = lib/rain.chainlink
url = https://github.com/rainprotocol/rain.chainlink
[submodule "lib/rain.intorastring"]
path = lib/rain.intorastring
url = https://github.com/rainlanguage/rain.intorastring
Expand Down
1 change: 0 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ remappings = [
# The auto remapping wasn't appending /src/ for some reason.
"forge-std/=lib/rain.interpreter.interface/lib/forge-std/src/",
"rain.metadata/=lib/rain.metadata/src/",
"rain.math.saturating/=lib/rain.math.fixedpoint/lib/rain.math.saturating/src/",
"rain.sol.codegen/=lib/rain.sol.codegen/src/",
"rain.solmem/=lib/rain.interpreter.interface/lib/rain.solmem/src/",
"openzeppelin-contracts/=lib/rain.interpreter.interface/lib/openzeppelin-contracts/",
Expand Down
1 change: 0 additions & 1 deletion lib/prb-math
Submodule prb-math deleted from 77fa88
1 change: 0 additions & 1 deletion lib/rain.chainlink
Submodule rain.chainlink deleted from c9844b
2 changes: 1 addition & 1 deletion lib/rain.interpreter.interface
1 change: 0 additions & 1 deletion lib/rain.math.fixedpoint
Submodule rain.math.fixedpoint deleted from f0d74e
2 changes: 1 addition & 1 deletion lib/rain.math.float
2 changes: 1 addition & 1 deletion lib/rain.metadata
2 changes: 1 addition & 1 deletion slither.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"detectors_to_exclude": "assembly-usage,solc-version,different-pragma-directives-are-used,unused-imports",
"filter_paths": "lib/openzeppelin-contracts,lib/prb-math,test/"
"filter_paths": "lib/rain.math.float,lib/openzeppelin-contracts,lib/prb-math,lib/rain.interpreter.interface,test/"
}
2 changes: 1 addition & 1 deletion src/abstract/BaseRainterpreterExternNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Pointer} from "rain.solmem/lib/LibPointer.sol";
import {LibStackPointer} from "rain.solmem/lib/LibStackPointer.sol";
import {LibUint256Array} from "rain.solmem/lib/LibUint256Array.sol";

import {Operand} from "rain.interpreter.interface/interface/IInterpreterV3.sol";
import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
import {IInterpreterExternV3, ExternDispatch} from "rain.interpreter.interface/interface/IInterpreterExternV3.sol";
import {IIntegrityToolingV1} from "rain.sol.codegen/interface/IIntegrityToolingV1.sol";
import {IOpcodeToolingV1} from "rain.sol.codegen/interface/IOpcodeToolingV1.sol";
Expand Down
6 changes: 3 additions & 3 deletions src/abstract/BaseRainterpreterSubParserNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pragma solidity =0.8.25;
import {ERC165} from "openzeppelin-contracts/contracts/utils/introspection/ERC165.sol";
import {LibBytes, Pointer} from "rain.solmem/lib/LibBytes.sol";

import {ISubParserV3, COMPATIBILITY_V4} from "rain.interpreter.interface/interface/ISubParserV3.sol";
import {ISubParserV3, AuthoringMetaV2} from "rain.interpreter.interface/interface/ISubParserV3.sol";
import {IncompatibleSubParser} from "../error/ErrSubParse.sol";
import {LibSubParse, ParseState} from "../lib/parse/LibSubParse.sol";
import {LibSubParse, ParseState, CURRENT_COMPATIBILITY} from "../lib/parse/LibSubParse.sol";
import {CMASK_RHS_WORD_TAIL} from "../lib/parse/LibParseCMask.sol";
import {LibParse, Operand} from "../lib/parse/LibParse.sol";
import {LibParseMeta} from "rain.interpreter.interface/lib/parse/LibParseMeta.sol";
Expand Down Expand Up @@ -118,7 +118,7 @@ abstract contract BaseRainterpreterSubParserNPE2 is
/// same commit the abstract sub parser is pulled from.
//slither-disable-next-line dead-code
function subParserCompatibility() internal pure virtual returns (bytes32) {
return COMPATIBILITY_V4;
return CURRENT_COMPATIBILITY;
}

/// Overrideable function to allow implementations to define their
Expand Down
8 changes: 4 additions & 4 deletions src/concrete/RainterpreterExpressionDeployerNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import {
UnexpectedParserBytecodeHash,
UnexpectedPointers
} from "../error/ErrDeploy.sol";
import {IParserV1View} from "rain.interpreter.interface/interface/deprecated/IParserV1View.sol";
import {IInterpreterV3} from "rain.interpreter.interface/interface/IInterpreterV3.sol";
import {IInterpreterStoreV2} from "rain.interpreter.interface/interface/IInterpreterStoreV2.sol";
import {IDescribedByMetaV1} from "rain.metadata/interface/IDescribedByMetaV1.sol";
import {IInterpreterV4} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";

import {LibIntegrityCheckNP} from "../lib/integrity/LibIntegrityCheckNP.sol";
import {LibInterpreterStateDataContractNP} from "../lib/state/LibInterpreterStateDataContractNP.sol";
Expand All @@ -33,6 +32,7 @@ import {
DESCRIBED_BY_META_HASH
} from "../generated/RainterpreterExpressionDeployerNPE2.pointers.sol";
import {IIntegrityToolingV1} from "rain.sol.codegen/interface/IIntegrityToolingV1.sol";
import {IParserV1View} from "rain.interpreter.interface/interface/deprecated/IParserV1View.sol";

/// All config required to construct a `RainterpreterNPE2`.
/// @param interpreter The `IInterpreterV2` to use for evaluation. MUST match
Expand All @@ -59,14 +59,14 @@ contract RainterpreterExpressionDeployerNPE2 is

/// The interpreter with known bytecode that this deployer is constructed
/// for.
IInterpreterV3 public immutable iInterpreter;
IInterpreterV4 public immutable iInterpreter;
/// The store with known bytecode that this deployer is constructed for.
IInterpreterStoreV2 public immutable iStore;
IParserV1View public immutable iParser;

constructor(RainterpreterExpressionDeployerNPE2ConstructionConfigV2 memory config) {
// Set the immutables.
IInterpreterV3 interpreter = IInterpreterV3(config.interpreter);
IInterpreterV4 interpreter = IInterpreterV4(config.interpreter);
IInterpreterStoreV2 store = IInterpreterStoreV2(config.store);
IParserV1View parser = IParserV1View(config.parser);

Expand Down
42 changes: 14 additions & 28 deletions src/concrete/RainterpreterNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,15 @@ import {ERC165} from "openzeppelin-contracts/contracts/utils/introspection/ERC16
import {LibPointer, Pointer} from "rain.solmem/lib/LibPointer.sol";
import {LibStackPointer} from "rain.solmem/lib/LibStackPointer.sol";
import {LibUint256Array} from "rain.solmem/lib/LibUint256Array.sol";
import {LibMemoryKV, MemoryKV} from "rain.lib.memkv/lib/LibMemoryKV.sol";
import {LibMemoryKV, MemoryKV, MemoryKVKey, MemoryKVVal} from "rain.lib.memkv/lib/LibMemoryKV.sol";
import {LibCast} from "rain.lib.typecast/LibCast.sol";
import {LibDataContract} from "rain.datacontract/lib/LibDataContract.sol";

import {LibEvalNP} from "../lib/eval/LibEvalNP.sol";
import {LibInterpreterStateDataContractNP} from "../lib/state/LibInterpreterStateDataContractNP.sol";
import {LibEncodedDispatch} from "rain.interpreter.interface/lib/deprecated/caller/LibEncodedDispatch.sol";
import {InterpreterStateNP} from "../lib/state/LibInterpreterStateNP.sol";
import {LibAllStandardOpsNP} from "../lib/op/LibAllStandardOpsNP.sol";
import {
SourceIndexV2,
IInterpreterV3,
StateNamespace,
FullyQualifiedNamespace,
IInterpreterStoreV2
} from "rain.interpreter.interface/interface/IInterpreterV3.sol";
import {IInterpreterV4, SourceIndexV2, EvalV4} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
import {
BYTECODE_HASH as INTERPRETER_BYTECODE_HASH,
OPCODE_FUNCTION_POINTERS
Expand All @@ -30,35 +23,28 @@ import {IOpcodeToolingV1} from "rain.sol.codegen/interface/IOpcodeToolingV1.sol"
/// @title RainterpreterNPE2
/// @notice Implementation of a Rainlang interpreter that is compatible with
/// native onchain Rainlang parsing.
contract RainterpreterNPE2 is IInterpreterV3, IOpcodeToolingV1, ERC165 {
contract RainterpreterNPE2 is IInterpreterV4, IOpcodeToolingV1, ERC165 {
using LibEvalNP for InterpreterStateNP;
using LibInterpreterStateDataContractNP for bytes;

/// @inheritdoc IInterpreterV3
function eval3(
IInterpreterStoreV2 store,
FullyQualifiedNamespace namespace,
bytes calldata bytecode,
SourceIndexV2 sourceIndex,
uint256[][] calldata context,
uint256[] calldata inputs
) external view virtual override returns (uint256[] memory, uint256[] memory) {
InterpreterStateNP memory state = bytecode.unsafeDeserializeNP(
SourceIndexV2.unwrap(sourceIndex), namespace, store, context, OPCODE_FUNCTION_POINTERS
/// @inheritdoc IInterpreterV4
function eval4(EvalV4 calldata eval) external view virtual override returns (uint256[] memory, uint256[] memory) {
InterpreterStateNP memory state = eval.bytecode.unsafeDeserializeNP(
SourceIndexV2.unwrap(eval.sourceIndex), eval.namespace, eval.store, eval.context, OPCODE_FUNCTION_POINTERS
);
for (uint256 i = 0; i < eval.stateOverlay.length; i += 2) {
state.stateKV = LibMemoryKV.set(
state.stateKV, MemoryKVKey.wrap(eval.stateOverlay[i]), MemoryKVVal.wrap(eval.stateOverlay[i + 1])
);
}
// We use the return by returning it. Slither false positive.
//slither-disable-next-line unused-return
return state.eval2(inputs, type(uint256).max);
return state.eval2(eval.inputs, type(uint256).max);
}

/// @inheritdoc ERC165
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IInterpreterV3).interfaceId || super.supportsInterface(interfaceId);
}

/// @inheritdoc IInterpreterV3
function functionPointers() external view virtual override returns (bytes memory) {
return buildOpcodeFunctionPointers();
return interfaceId == type(IInterpreterV4).interfaceId || super.supportsInterface(interfaceId);
}

/// @inheritdoc IOpcodeToolingV1
Expand Down
2 changes: 1 addition & 1 deletion src/concrete/RainterpreterParserNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {IERC165, ERC165} from "openzeppelin-contracts/contracts/utils/introspect

import {LibParse} from "../lib/parse/LibParse.sol";
import {IParserPragmaV1, PragmaV1} from "rain.interpreter.interface/interface/IParserPragmaV1.sol";
import {IParserV1View} from "rain.interpreter.interface/interface/deprecated/IParserV1View.sol";
import {LibParseState, ParseState} from "../lib/parse/LibParseState.sol";
import {LibParsePragma} from "../lib/parse/LibParsePragma.sol";
import {LibParseLiteral} from "../lib/parse/literal/LibParseLiteral.sol";
Expand All @@ -20,6 +19,7 @@ import {
PARSE_META_BUILD_DEPTH
} from "../generated/RainterpreterParserNPE2.pointers.sol";
import {IParserToolingV1} from "rain.sol.codegen/interface/IParserToolingV1.sol";
import {IParserV1View} from "rain.interpreter.interface/interface/deprecated/IParserV1View.sol";

/// @title RainterpreterParserNPE2
/// @dev The parser implementation.
Expand Down
25 changes: 12 additions & 13 deletions src/concrete/extern/RainterpreterReferenceExternNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import {BaseRainterpreterExternNPE2, Operand} from "../../abstract/BaseRainterpr
import {
BaseRainterpreterSubParserNPE2,
IParserToolingV1,
ISubParserToolingV1
ISubParserToolingV1,
AuthoringMetaV2
} from "../../abstract/BaseRainterpreterSubParserNPE2.sol";
import {LibExtern, EncodedExternDispatch} from "../../lib/extern/LibExtern.sol";
import {IInterpreterExternV3} from "rain.interpreter.interface/interface/IInterpreterExternV3.sol";
import {LibSubParse} from "../../lib/parse/LibSubParse.sol";
import {AuthoringMetaV2} from "rain.interpreter.interface/interface/deprecated/IParserV1View.sol";
import {LibSubParse, CURRENT_COMPATIBILITY} from "../../lib/parse/LibSubParse.sol";
import {LibParseState, ParseState} from "../../lib/parse/LibParseState.sol";
import {LibParseOperand} from "../../lib/parse/LibParseOperand.sol";
import {LibParseLiteral} from "../../lib/parse/literal/LibParseLiteral.sol";
import {COMPATIBILITY_V4} from "rain.interpreter.interface/interface/ISubParserV3.sol";
import {LibExternOpIntIncNPE2, OP_INDEX_INCREMENT} from "../../lib/extern/reference/op/LibExternOpIntIncNPE2.sol";
import {LibExternOpStackOperandNPE2} from "../../lib/extern/reference/op/LibExternOpStackOperandNPE2.sol";
import {LibExternOpContextSenderNPE2} from "../../lib/extern/reference/op/LibExternOpContextSenderNPE2.sol";
Expand All @@ -25,7 +24,6 @@ import {LibExternOpContextCallingContractNPE2} from
import {LibExternOpContextRainlenNPE2} from "../../lib/extern/reference/op/LibExternOpContextRainlenNPE2.sol";
import {LibParseLiteralRepeat} from "../../lib/extern/reference/literal/LibParseLiteralRepeat.sol";
import {LibParseLiteralDecimal} from "../../lib/parse/literal/LibParseLiteralDecimal.sol";
import {LibFixedPointDecimalScale} from "rain.math.fixedpoint/lib/LibFixedPointDecimalScale.sol";
import {
DESCRIBED_BY_META_HASH,
PARSE_META as SUB_PARSER_PARSE_META,
Expand All @@ -36,6 +34,7 @@ import {
INTEGRITY_FUNCTION_POINTERS,
OPCODE_FUNCTION_POINTERS
} from "../../generated/RainterpreterReferenceExternNPE2.pointers.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";

/// @dev The number of subparser functions available to the parser. This is NOT
/// 1:1 with the number of opcodes provided by the extern component of this
Expand Down Expand Up @@ -66,7 +65,7 @@ bytes32 constant SUB_PARSER_LITERAL_REPEAT_KEYWORD_MASK =
uint256 constant SUB_PARSER_LITERAL_REPEAT_INDEX = 0;

/// @dev Thrown when the repeat literal parser is not a single digit.
error InvalidRepeatCount(uint256 value);
error InvalidRepeatCount();

/// @dev Number of opcode function pointers available to run at eval time.
uint256 constant OPCODE_FUNCTION_POINTERS_LENGTH = 1;
Expand Down Expand Up @@ -186,7 +185,7 @@ contract RainterpreterReferenceExternNPE2 is BaseRainterpreterSubParserNPE2, Bas
/// known constant value, which should allow the compiler to optimise the
/// entire function call away.
function subParserCompatibility() internal pure override returns (bytes32) {
return COMPATIBILITY_V4;
return CURRENT_COMPATIBILITY;
}

/// Overrides the base function pointers for opcodes. Simply returns the
Expand Down Expand Up @@ -247,17 +246,17 @@ contract RainterpreterReferenceExternNPE2 is BaseRainterpreterSubParserNPE2, Bas
ParseState memory state = LibParseState.newState("", "", "", "");
// If we have a match on the keyword then the next chars MUST
// be a decimal, otherwise it's an error.
uint256 value;
(cursor, value) = LibParseLiteralDecimal.parseDecimal(
int256 signedCoefficient;
int256 exponent;
(cursor, signedCoefficient, exponent) = LibParseLiteralDecimal.parseDecimalFloat(
state, cursor + SUB_PARSER_LITERAL_REPEAT_KEYWORD_BYTES_LENGTH, end
);
value = LibFixedPointDecimalScale.scaleToIntegerLossless(value);
// We can only repeat a single digit.
if (value > 9) {
revert InvalidRepeatCount(value);
if (LibDecimalFloat.gt(signedCoefficient, exponent, 9, 0)) {
revert InvalidRepeatCount();
}

return (true, SUB_PARSER_LITERAL_REPEAT_INDEX, value);
return (true, SUB_PARSER_LITERAL_REPEAT_INDEX, LibDecimalFloat.pack(signedCoefficient, exponent));
} else {
return (false, 0, 0);
}
Expand Down
3 changes: 3 additions & 0 deletions src/error/ErrParse.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,6 @@ error BadSubParserResult(bytes bytecode);

/// Thrown when there are more than 16 inputs or outputs for a given opcode.
error OpcodeIOOverflow(uint256 offset);

/// Thrown when an operand value is larger than the maximum allowed.
error OperandOverflow();
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(0x120bb857e25b094e30d19b11f0bf73b80df656781d0e28d7e7150775a3eebdad);
bytes32 constant BYTECODE_HASH = bytes32(0xa2aa82665525441e4ba146a7c61a296a6e430ff63355414354b1ef53ae3c3e66);

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

/// @dev The function pointers for the integrity check fns.
bytes constant INTEGRITY_FUNCTION_POINTERS =
hex"0f4c0fca102f11a911b311b311bd11c611e11287128712e3135d136a11b311bd136a11b311bd11b311b311bd11a911a911a911a911a91374139913b311b3137411b311b3136a11bd11b311b3136a136a13bd13bd13bd13bd11b311bd13bd11a911bd11bd11bd11bd11b311bd11bd11bd11bd11bd13bd13bd13bd13bd11b311bd11bd11b311bd11bd11b311b311bd13bd13bd11bd13b3";
hex"0d840e020e670fe10feb0feb0ff50ffe101910bf10bf111b11950feb0ff50fe10ff511a2";
5 changes: 2 additions & 3 deletions src/generated/RainterpreterNPE2.pointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
pragma solidity =0.8.25;

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

/// @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"077c07cd080f09db0ac20ad40ae60b090b4b0b9d0bae0bbf0c610c9e0d5c0e0c0e900fd310fa0d5c11f6129813101349138213d113d1140a146f1543159615aa16031617162c164616511665167a16b216d9175917a717f51843185b187418c218f91907191519301945195d19761984199219a019ae19fc1a4a1a981ae61afe1afe1b151b431b431b5a1b891bde1bec1bec1c901d77";
bytes constant OPCODE_FUNCTION_POINTERS = hex"06b407040746091209f90a0b0a1d0a360a780aca0adb0aec0b8e0bcb0c7a0cfe0d4d0e43";
Loading

0 comments on commit d21471c

Please sign in to comment.