Skip to content

Commit

Permalink
Merge pull request #291 from rainlanguage/2024-09-12-remapping
Browse files Browse the repository at this point in the history
fix remappings for float math
  • Loading branch information
thedavidmeister authored Sep 12, 2024
2 parents f391e15 + b5df403 commit 699d718
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 17 deletions.
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ remappings = [
"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/",
"rain.math.float/=lib/rain.math.float/src/",
]

[fuzz]
Expand Down
2 changes: 1 addition & 1 deletion src/concrete/extern/RainterpreterReferenceExternNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
INTEGRITY_FUNCTION_POINTERS,
OPCODE_FUNCTION_POINTERS
} from "../../generated/RainterpreterReferenceExternNPE2.pointers.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/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
2 changes: 1 addition & 1 deletion src/lib/extern/reference/op/LibExternOpIntIncNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.25;
import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
import {LibSubParse} from "../../../parse/LibSubParse.sol";
import {IInterpreterExternV3} from "rain.interpreter.interface/interface/IInterpreterExternV3.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

/// @dev Opcode index of the extern increment opcode. Needs to be manually kept
/// in sync with the extern opcode function pointers. Definitely write tests for
Expand Down
2 changes: 1 addition & 1 deletion src/lib/parse/LibParseOperand.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {CMASK_OPERAND_END, CMASK_WHITESPACE, CMASK_OPERAND_START} from "./LibPar
import {ParseState, OPERAND_VALUES_LENGTH, FSM_YANG_MASK} from "./LibParseState.sol";
import {LibParseError} from "./LibParseError.sol";
import {LibParseInterstitial} from "./LibParseInterstitial.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

library LibParseOperand {
using LibParseError for ParseState;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/parse/literal/LibParseLiteralDecimal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from "../LibParseCMask.sol";
import {LibParseError} from "../LibParseError.sol";
import {LibParse} from "../LibParse.sol";
import {LibDecimalFloatImplementation, LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloatImplementation, LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

/// @dev The default is 18 decimal places for a fractional number.
uint256 constant DECIMAL_SCALE = 18;
Expand Down
2 changes: 1 addition & 1 deletion test/src/concrete/RainterpreterNPE2.stateOverlay.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {RainterpreterExpressionDeployerNPE2DeploymentTest} from
import {FullyQualifiedNamespace, StateNamespace} from "rain.interpreter.interface/interface/IInterpreterStoreV2.sol";
import {EvalV4, SourceIndexV2} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
import {LibNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

contract RainterpreterNPE2StateOverlayTest is RainterpreterExpressionDeployerNPE2DeploymentTest {
/// Show that state overlay can prewarm a get.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {LibExtern} from "src/lib/extern/LibExtern.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
import {OPCODE_EXTERN} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
import {ExternDispatchConstantsHeightOverflow} from "src/error/ErrSubParse.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";
import {CURRENT_COMPATIBILITY} from "src/lib/parse/LibSubParse.sol";

contract RainterpreterReferenceExternNPE2IntIncTest is OpTest {
Expand Down Expand Up @@ -70,6 +70,7 @@ contract RainterpreterReferenceExternNPE2IntIncTest is OpTest {
}

/// Directly test the subparsing of the reference extern opcode.
/// forge-config: default.fuzz.runs = 100
function testRainterpreterReferenceExternNPE2IntIncSubParseKnownWord(uint16 constantsHeight, bytes1 ioByte)
external
{
Expand Down Expand Up @@ -107,6 +108,7 @@ contract RainterpreterReferenceExternNPE2IntIncTest is OpTest {
/// Directly test the subparsing of the reference extern opcode. Check that
/// we get a false for success if the subparser doesn't recognize the word
/// but the data is otherwise valid.
/// forge-config: default.fuzz.runs = 100
function testRainterpreterReferenceExternNPE2IntIncSubParseUnknownWord(
uint16 constantsHeight,
bytes1 ioByte,
Expand All @@ -129,6 +131,7 @@ contract RainterpreterReferenceExternNPE2IntIncTest is OpTest {

/// Test the inc library directly. The run function should increment every
/// value it is passed by 1.
/// forge-config: default.fuzz.runs = 100
function testRainterpreterReferenceExternNPE2IntIncRun(Operand operand, uint256[] memory inputs) external pure {
uint256[] memory expectedOutputs = new uint256[](inputs.length);
for (uint256 i = 0; i < inputs.length; i++) {
Expand All @@ -147,6 +150,7 @@ contract RainterpreterReferenceExternNPE2IntIncTest is OpTest {

/// Test the inc library directly. The integrity function should return the
/// same inputs and outputs.
/// forge-config: default.fuzz.runs = 100
function testRainterpreterReferenceExternNPE2IntIncIntegrity(Operand operand, uint256 inputs, uint256 outputs)
external
pure
Expand Down
7 changes: 5 additions & 2 deletions test/src/concrete/RainterpreterStoreNPE2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ contract RainterpreterStoreNPE2Test is Test {

/// Ensure the store gives a decent error message when an odd number of
/// arguments is passed to `set`.
/// forge-config: default.fuzz.runs = 100
function testRainterpreterStoreNPE2SetOddLength(StateNamespace namespace, uint256[] memory kvs) external {
vm.assume(kvs.length % 2 != 0);

Expand All @@ -45,6 +46,7 @@ contract RainterpreterStoreNPE2Test is Test {

/// Store should set and get values correctly.
/// This test assumes no dupes.
/// forge-config: default.fuzz.runs = 100
function testRainterpreterStoreNPE2SetGetNoDupesSingle(StateNamespace namespace, uint256[] memory kvs) external {
// Truncate to even length.
uint256 newLength = kvs.length - (kvs.length % 2);
Expand All @@ -71,7 +73,8 @@ contract RainterpreterStoreNPE2Test is Test {
uint256[] kvs;
}

/// Store should get and set values correctly across many namespaces.
/// Store should get and set values correctly across many namespaces.j
/// forge-config: default.fuzz.runs = 100
function testRainterpreterStoreNPE2SetGetNoDupesMany(Set[] memory sets) external {
uint256 setsLength = sets.length >= 10 ? 10 : sets.length;
uint256[] memory refs;
Expand Down Expand Up @@ -115,7 +118,7 @@ contract RainterpreterStoreNPE2Test is Test {
/// previous writes to the same key (i.e. like a k/v store). The assumption
/// is that the fuzzer will generate some dupes just randomly, so there's
/// no special logic to make that happen.

/// forge-config: default.fuzz.runs = 100
function testRainterpreterStoreNPE2SetGetDupes(Set11[] memory sets) external {
vm.assume(sets.length < 20);

Expand Down
2 changes: 1 addition & 1 deletion test/src/lib/op/00/LibOpConstantNP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {IInterpreterStoreV2} from "rain.interpreter.interface/interface/IInterpr
import {SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV3.sol";
import {LibOperand} from "test/lib/operand/LibOperand.sol";
import {BadOpOutputsLength} from "src/error/ErrIntegrity.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

/// @title LibOpConstantNPTest
/// @notice Test the runtime and integrity time logic of LibOpConstantNP.
Expand Down
8 changes: 8 additions & 0 deletions test/src/lib/op/00/LibOpContextNP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contract LibOpContextNPTest is OpTest {

/// Directly test the runtime logic of LibOpContextNP. This tests that the
/// values in the context matrix can be pushed to the stack via. the operand.
/// forge-config: default.fuzz.runs = 100
function testOpContextNPRun(uint256[][] memory context, uint256 i, uint256 j) external view {
InterpreterStateNP memory state = opTestDefaultInterpreterState();
state.context = context;
Expand All @@ -52,6 +53,7 @@ contract LibOpContextNPTest is OpTest {

/// Directly test the reference logic of LibOpContextNP. This tests that the
/// runtime logic will revert if the indexes are OOB. Tests that i is OOB.
/// forge-config: default.fuzz.runs = 100
function testOpContextNPRunOOBi(uint256[][] memory context, uint256 i, uint256 j) external {
InterpreterStateNP memory state = opTestDefaultInterpreterState();
state.context = context;
Expand All @@ -68,6 +70,7 @@ contract LibOpContextNPTest is OpTest {

/// Directly test the reference logic of LibOpContextNP. This tests that the
/// runtime logic will revert if the indexes are OOB. Tests that j is OOB.
/// forge-config: default.fuzz.runs = 100
function testOpContextNPRunOOBj(uint256[][] memory context, uint256 i, uint256 j) external {
InterpreterStateNP memory state = opTestDefaultInterpreterState();
state.context = context;
Expand All @@ -85,6 +88,7 @@ contract LibOpContextNPTest is OpTest {
}

/// Test the eval of context opcode parsed from a string. This tests 0 0.
/// forge-config: default.fuzz.runs = 100
function testOpContextNPEval00(uint256[][] memory context) external view {
vm.assume(context.length > 0);
vm.assume(context[0].length > 0);
Expand All @@ -108,6 +112,7 @@ contract LibOpContextNPTest is OpTest {
}

/// Test the eval of context opcode parsed from a string. This tests 0 1.
/// forge-config: default.fuzz.runs = 100
function testOpContextNPEval01(uint256[][] memory context) external view {
vm.assume(context.length > 0);
vm.assume(context[0].length > 1);
Expand All @@ -130,6 +135,7 @@ contract LibOpContextNPTest is OpTest {
}

/// Test the eval of context opcode parsed from a string. This tests 1 0.
/// forge-config: default.fuzz.runs = 100
function testOpContextNPEval10(uint256[][] memory context) external view {
vm.assume(context.length > 1);
vm.assume(context[1].length > 0);
Expand All @@ -153,6 +159,7 @@ contract LibOpContextNPTest is OpTest {
}

/// Test the eval of context opcode parsed from a string. This tests 1 1.
/// forge-config: default.fuzz.runs = 100
function testOpContextNPEval11(uint256[][] memory context) external view {
vm.assume(context.length > 1);
vm.assume(context[1].length > 1);
Expand All @@ -176,6 +183,7 @@ contract LibOpContextNPTest is OpTest {
}

/// Test the eval of context opcode parsed from a string. This tests OOB i.
/// forge-config: default.fuzz.runs = 100
function testOpContextNPEvalOOBi(uint256[] memory context0) external {
uint256[][] memory context = new uint256[][](1);
context[0] = context0;
Expand Down
2 changes: 1 addition & 1 deletion test/src/lib/op/00/LibOpExternNP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import {IERC165} from "openzeppelin-contracts/contracts/utils/introspection/IERC165.sol";
import {LibOperand} from "test/lib/operand/LibOperand.sol";
import {LibUint256Array} from "rain.solmem/lib/LibUint256Array.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

/// @title LibOpExternNPTest
/// @notice Test the runtime and integrity time logic of LibOpExternNP.
Expand Down
3 changes: 2 additions & 1 deletion test/src/lib/op/00/LibOpStackNP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {OpTest, PRE, POST} from "test/abstract/OpTest.sol";
import {SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV3.sol";
import {LibOperand} from "test/lib/operand/LibOperand.sol";
import {BadOpOutputsLength} from "src/error/ErrIntegrity.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

/// @title LibOpStackNPTest
/// @notice Test the runtime and integrity time logic of LibOpStackNP.
Expand Down Expand Up @@ -69,6 +69,7 @@ contract LibOpStackNPTest is OpTest {

/// Directly test the runtime logic of LibOpStackNP. This tests that the
/// operand always puts a single value on the stack.
/// forge-config: default.fuzz.runs = 100
function testOpStackNPRun(uint256[][] memory stacks, uint256 stackIndex) external view {
InterpreterStateNP memory state = opTestDefaultInterpreterState();
uint256 stackValue;
Expand Down
3 changes: 3 additions & 0 deletions test/src/lib/op/bitwise/LibOpShiftBitsRightNP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ contract LibOpShiftBitsRightNPTest is OpTest {
/// Directly test the integrity logic of LibOpShiftBitsRightNP. Tests the
/// happy path where the integrity check does not error due to an unsupported
/// shift amount.
/// forge-config: default.fuzz.runs = 100
function testOpShiftBitsRightNPIntegrityHappy(
IntegrityCheckStateNP memory state,
uint8 inputs,
Expand All @@ -40,6 +41,7 @@ contract LibOpShiftBitsRightNPTest is OpTest {
/// Directly test the execution logic of LibOpShiftBitsRightNP. Tests that
/// any shift amount that always results in an output of 0 will error as
/// an unsupported shift amount.
/// forge-config: default.fuzz.runs = 100
function testOpShiftBitsRightNPIntegrityZero(IntegrityCheckStateNP memory state, uint8 inputs, uint16 shiftAmount16)
external
{
Expand All @@ -53,6 +55,7 @@ contract LibOpShiftBitsRightNPTest is OpTest {
/// Directly test the execution logic of LibOpShiftBitsRightNP. Tests that
/// any shift amount that is a noop (0) will error as an unsupported shift
/// amount.
/// forge-config: default.fuzz.runs = 100
function testOpShiftBitsRightNPIntegrityNoop(IntegrityCheckStateNP memory state, uint8 inputs) external {
Operand operand = Operand.wrap(uint256(inputs) << 0x10);
vm.expectRevert(abi.encodeWithSelector(UnsupportedBitwiseShiftAmount.selector, 0));
Expand Down
2 changes: 1 addition & 1 deletion test/src/lib/op/call/LibOpCallNP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {LibBytecode, SourceIndexOutOfBounds} from "rain.interpreter.interface/li
import {BadOpInputsLength} from "src/lib/integrity/LibIntegrityCheckNP.sol";
import {STACK_TRACER} from "src/lib/state/LibInterpreterStateNP.sol";
import {LibOperand} from "test/lib/operand/LibOperand.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

/// @title LibOpCallNPTest
/// @notice Test the LibOpCallNP library that includes the "call" word.
Expand Down
2 changes: 1 addition & 1 deletion test/src/lib/op/crypto/LibOpHashNP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {SignedContextV1} from "rain.interpreter.interface/interface/IInterpreter
import {LibIntegrityCheckNP, IntegrityCheckStateNP} from "src/lib/integrity/LibIntegrityCheckNP.sol";
import {InterpreterStateNP, LibInterpreterStateNP} from "src/lib/state/LibInterpreterStateNP.sol";
import {LibOperand} from "test/lib/operand/LibOperand.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

/// @title LibOpHashNPTest
/// @notice Test the runtime and integrity time logic of LibOpHashNP.
Expand Down
2 changes: 1 addition & 1 deletion test/src/lib/parse/LibParse.literalIntegerDecimal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {DecimalLiteralOverflow} from "src/lib/parse/literal/LibParseLiteral.sol"
import {LibParse, UnexpectedRHSChar, UnexpectedRightParen} from "src/lib/parse/LibParse.sol";
import {LibBytecode} from "rain.interpreter.interface/lib/bytecode/LibBytecode.sol";
import {ParseState} from "src/lib/parse/LibParseState.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

/// @title LibParseLiteralIntegerDecimalTest
/// Tests parsing integer literal decimal values.
Expand Down
5 changes: 5 additions & 0 deletions test/src/lib/parse/LibParse.literalString.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ contract LibParseLiteralStringTest is Test {

/// Any ASCII printable string shorter than 32 bytes should be parsed
/// correctly.
/// forge-config: default.fuzz.runs = 100
function testParseStringLiteralShortASCII(string memory str) external view {
vm.assume(bytes(str).length < 0x20);
LibLiteralString.conformValidPrintableStringContent(str);
Expand All @@ -75,6 +76,7 @@ contract LibParseLiteralStringTest is Test {
}

/// Can parse 2 valid strings.
/// forge-config: default.fuzz.runs = 100
function testParseStringLiteralTwo(string memory strA, string memory strB) external view {
vm.assume(bytes(strA).length < 0x20);
LibLiteralString.conformValidPrintableStringContent(strA);
Expand All @@ -99,6 +101,7 @@ contract LibParseLiteralStringTest is Test {
}

/// Valid ASCII printable strings 32 bytes or longer should error.
/// forge-config: default.fuzz.runs = 100
function testParseStringLiteralLongASCII(string memory str) external {
vm.assume(bytes(str).length >= 0x20);
LibLiteralString.conformValidPrintableStringContent(str);
Expand All @@ -110,6 +113,7 @@ contract LibParseLiteralStringTest is Test {

/// Invalid chars beyond the 31 byte valid range will not be parsed. Instead
/// a `StringTooLong` error will be thrown.
/// forge-config: default.fuzz.runs = 100
function testParseStringLiteralInvalidCharAfter(string memory strA, string memory strB) external {
vm.assume(bytes(strA).length >= 0x20);
LibLiteralString.conformValidPrintableStringContent(strA);
Expand All @@ -126,6 +130,7 @@ contract LibParseLiteralStringTest is Test {

/// Invalid chars anywhere in the parsed string will cause an unclosed
/// string literal error.
/// forge-config: default.fuzz.runs = 100
function testParseStringLiteralInvalidCharWithin(string memory str, uint256 badIndex) external {
vm.assume(bytes(str).length > 0);
LibLiteralString.conformValidPrintableStringContent(str);
Expand Down
2 changes: 1 addition & 1 deletion test/src/lib/parse/LibParse.namedLHS.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Operand, LibParseOperand} from "src/lib/parse/LibParseOperand.sol";
import {LibConvert} from "rain.lib.typecast/LibConvert.sol";
import {LibAllStandardOpsNP} from "src/lib/op/LibAllStandardOpsNP.sol";
import {LibGenParseMeta} from "rain.sol.codegen/lib/LibGenParseMeta.sol";
import {LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";
import {LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";

/// @title LibParseNamedLHSTest
contract LibParseNamedLHSTest is Test {
Expand Down
Loading

0 comments on commit 699d718

Please sign in to comment.