Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024 08 16 swap numeric #280

Merged
merged 19 commits into from
Aug 25, 2024
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
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 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/"
}
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, AuthoringMetaV2} 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
21 changes: 10 additions & 11 deletions src/concrete/extern/RainterpreterReferenceExternNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import {
} 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 {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();
4 changes: 2 additions & 2 deletions src/generated/RainterpreterNPE2.pointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
pragma solidity =0.8.25;

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0xf8382556fc29d39e6e42d3c8a93f6004c731efce7e61a4bbb7eac4a772f05151);
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"06b407040746091209f90a0b0a1d0a400a820ad40ae50af60b980bd50c840d080d570e4d";
bytes constant OPCODE_FUNCTION_POINTERS = hex"06b407040746091209f90a0b0a1d0a360a780aca0adb0aec0b8e0bcb0c7a0cfe0d4d0e43";
6 changes: 3 additions & 3 deletions src/generated/RainterpreterParserNPE2.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(0x2b76af53c41e816a07cc5750e27098896d9d7ed695b884f2ff0b39621dfdb8c3);
bytes32 constant BYTECODE_HASH = bytes32(0x6ceb7c73c69eaf63e3a95805892de0f17ff921c8cc8ae7694745fd7f832ecad5);

/// @dev The parse meta that is used to lookup word definitions.
/// The structure of the parse meta is:
Expand Down Expand Up @@ -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"173517351735179a181318131813179a179a173517351735181318131813181318131813";
hex"1450145014501515160c160c160c15151515145014501450160c160c160c160c160c160c";

/// @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"0dab1073147a1554";
bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"0dab10731185125f";
8 changes: 4 additions & 4 deletions src/generated/RainterpreterReferenceExternNPE2.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(0x4247a5ea9bd8abcbe989b8ae09f2b9b29cafa521add389fc7b6f2b1ca3c49ecc);
bytes32 constant BYTECODE_HASH = bytes32(0xf8597dadf69ee1df0975d01a6e9e43563ff5966c950ed23c981086f46b4d7a8c);

/// @dev The hash of the meta that describes the contract.
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0xadf71693c6ecf3fd560904bc46973d1b6e651440d15366673f9b3984749e7c16);
Expand Down Expand Up @@ -47,17 +47,17 @@ bytes constant SUB_PARSER_WORD_PARSERS = hex"0775079707a607b607c7";
/// @dev Every two bytes is a function pointer for an operand handler.
/// These positional indexes all map to the same indexes looked up in the parse
/// meta.
bytes constant OPERAND_HANDLER_FUNCTION_POINTERS = hex"0a270a6c0a270a270a27";
bytes constant OPERAND_HANDLER_FUNCTION_POINTERS = hex"0abf0b040abf0abf0abf";

/// @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"09f8";
bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"0a8e";

/// @dev The function pointers for the integrity check fns.
bytes constant INTEGRITY_FUNCTION_POINTERS = hex"08ad";
bytes constant INTEGRITY_FUNCTION_POINTERS = hex"0935";

/// @dev The function pointers known to the interpreter for dynamic dispatch.
/// By setting these as a constant they can be inlined into the interpreter
Expand Down
5 changes: 4 additions & 1 deletion src/lib/extern/reference/op/LibExternOpIntIncNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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";

/// @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 All @@ -20,7 +21,9 @@ library LibExternOpIntIncNPE2 {
//slither-disable-next-line dead-code
function run(Operand, uint256[] memory inputs) internal pure returns (uint256[] memory) {
for (uint256 i = 0; i < inputs.length; i++) {
++inputs[i];
(int256 signedCoefficient, int256 exponent) = LibDecimalFloat.unpack(inputs[i]);
(signedCoefficient, exponent) = LibDecimalFloat.add(signedCoefficient, exponent, 1e37, -37);
inputs[i] = LibDecimalFloat.pack(signedCoefficient, exponent);
}
return inputs;
}
Expand Down
58 changes: 29 additions & 29 deletions src/lib/op/LibAllStandardOpsNP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import {LibOpUint256ERC20Allowance} from "./erc20/uint256/LibOpUint256ERC20Allow
import {LibOpUint256ERC20BalanceOf} from "./erc20/uint256/LibOpUint256ERC20BalanceOf.sol";
import {LibOpUint256ERC20TotalSupply} from "./erc20/uint256/LibOpUint256ERC20TotalSupply.sol";

import {LibOpERC20Allowance} from "./erc20/LibOpERC20Allowance.sol";
import {LibOpERC20BalanceOf} from "./erc20/LibOpERC20BalanceOf.sol";
import {LibOpERC20TotalSupply} from "./erc20/LibOpERC20TotalSupply.sol";
// import {LibOpERC20Allowance} from "./erc20/LibOpERC20Allowance.sol";
// import {LibOpERC20BalanceOf} from "./erc20/LibOpERC20BalanceOf.sol";
// import {LibOpERC20TotalSupply} from "./erc20/LibOpERC20TotalSupply.sol";

import {LibOpUint256ERC721BalanceOf} from "./erc721/uint256/LibOpUint256ERC721BalanceOf.sol";
import {LibOpERC721OwnerOf} from "./erc721/LibOpERC721OwnerOf.sol";
Expand All @@ -58,40 +58,40 @@ import {LibOpIsZeroNP} from "./logic/LibOpIsZeroNP.sol";
import {LibOpLessThanNP} from "./logic/LibOpLessThanNP.sol";
import {LibOpLessThanOrEqualToNP} from "./logic/LibOpLessThanOrEqualToNP.sol";

import {LibOpExponentialGrowth} from "./math/growth/LibOpExponentialGrowth.sol";
import {LibOpLinearGrowth} from "./math/growth/LibOpLinearGrowth.sol";
// import {LibOpExponentialGrowth} from "./math/growth/LibOpExponentialGrowth.sol";
// import {LibOpLinearGrowth} from "./math/growth/LibOpLinearGrowth.sol";

import {LibOpUint256Div} from "./math/uint256/LibOpUint256Div.sol";
import {LibOpUint256Mul} from "./math/uint256/LibOpUint256Mul.sol";
import {LibOpUint256Pow} from "./math/uint256/LibOpUint256Pow.sol";

import {LibOpAdd} from "./math/LibOpAdd.sol";
import {LibOpAvg} from "./math/LibOpAvg.sol";
import {LibOpCeil} from "./math/LibOpCeil.sol";
import {LibOpMul} from "./math/LibOpMul.sol";
import {LibOpDiv} from "./math/LibOpDiv.sol";
import {LibOpE} from "./math/LibOpE.sol";
import {LibOpExp} from "./math/LibOpExp.sol";
import {LibOpExp2} from "./math/LibOpExp2.sol";
import {LibOpFloor} from "./math/LibOpFloor.sol";
import {LibOpFrac} from "./math/LibOpFrac.sol";
import {LibOpGm} from "./math/LibOpGm.sol";
import {LibOpHeadroom} from "./math/LibOpHeadroom.sol";
import {LibOpInv} from "./math/LibOpInv.sol";
import {LibOpLn} from "./math/LibOpLn.sol";
import {LibOpLog10} from "./math/LibOpLog10.sol";
// import {LibOpAvg} from "./math/LibOpAvg.sol";
// import {LibOpCeil} from "./math/LibOpCeil.sol";
// import {LibOpMul} from "./math/LibOpMul.sol";
// import {LibOpDiv} from "./math/LibOpDiv.sol";
// import {LibOpE} from "./math/LibOpE.sol";
// import {LibOpExp} from "./math/LibOpExp.sol";
// import {LibOpExp2} from "./math/LibOpExp2.sol";
// import {LibOpFloor} from "./math/LibOpFloor.sol";
// import {LibOpFrac} from "./math/LibOpFrac.sol";
// import {LibOpGm} from "./math/LibOpGm.sol";
// import {LibOpHeadroom} from "./math/LibOpHeadroom.sol";
// import {LibOpInv} from "./math/LibOpInv.sol";
// import {LibOpLn} from "./math/LibOpLn.sol";
// import {LibOpLog10} from "./math/LibOpLog10.sol";
import {LibOpMax} from "./math/LibOpMax.sol";
import {LibOpMin} from "./math/LibOpMin.sol";
import {LibOpMod} from "./math/LibOpMod.sol";
import {LibOpLog2} from "./math/LibOpLog2.sol";
import {LibOpPow} from "./math/LibOpPow.sol";
import {LibOpScale18Dynamic} from "./math/LibOpScale18Dynamic.sol";
import {LibOpScale18} from "./math/LibOpScale18.sol";
import {LibOpScaleNDynamic} from "./math/LibOpScaleNDynamic.sol";
import {LibOpScaleN} from "./math/LibOpScaleN.sol";
import {LibOpSnapToUnit} from "./math/LibOpSnapToUnit.sol";
import {LibOpSqrt} from "./math/LibOpSqrt.sol";
import {LibOpSub} from "./math/LibOpSub.sol";
// import {LibOpLog2} from "./math/LibOpLog2.sol";
// import {LibOpPow} from "./math/LibOpPow.sol";
// import {LibOpScale18Dynamic} from "./math/LibOpScale18Dynamic.sol";
// import {LibOpScale18} from "./math/LibOpScale18.sol";
// import {LibOpScaleNDynamic} from "./math/LibOpScaleNDynamic.sol";
// import {LibOpScaleN} from "./math/LibOpScaleN.sol";
// import {LibOpSnapToUnit} from "./math/LibOpSnapToUnit.sol";
// import {LibOpSqrt} from "./math/LibOpSqrt.sol";
// import {LibOpSub} from "./math/LibOpSub.sol";

import {LibOpGetNP} from "./store/LibOpGetNP.sol";
import {LibOpSetNP} from "./store/LibOpSetNP.sol";
Expand Down Expand Up @@ -329,7 +329,7 @@ library LibAllStandardOpsNP {
memory pointersFixed = [
lengthPointer,
LibParseLiteralHex.parseHex,
LibParseLiteralDecimal.parseDecimal,
LibParseLiteralDecimal.parseDecimalFloatPacked,
LibParseLiteralString.parseString,
LibParseLiteralSubParseable.parseSubParseable
];
Expand Down
5 changes: 2 additions & 3 deletions src/lib/op/bitwise/LibOpCtPopNP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {Operand} from "rain.interpreter.interface/interface/unstable/IInterprete
import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol";
import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol";
import {LibCtPop} from "rain.math.binary/lib/LibCtPop.sol";
import {FIXED_POINT_ONE} from "rain.math.fixedpoint/lib/FixedPointDecimalConstants.sol";

/// @title LibOpCtPopNP
/// @notice An opcode that counts the number of bits set in a word. This is
Expand All @@ -29,7 +28,7 @@ library LibOpCtPopNP {
value := mload(stackTop)
}
unchecked {
value = LibCtPop.ctpop(value) * FIXED_POINT_ONE;
value = LibCtPop.ctpop(value);
}
assembly ("memory-safe") {
mstore(stackTop, value)
Expand All @@ -43,7 +42,7 @@ library LibOpCtPopNP {
pure
returns (uint256[] memory)
{
inputs[0] = LibCtPop.ctpopSlow(inputs[0]) * FIXED_POINT_ONE;
inputs[0] = LibCtPop.ctpopSlow(inputs[0]);
return inputs;
}
}
Loading
Loading