Skip to content

Commit

Permalink
Merge pull request #235 from rainlanguage/2024-05-18-uint256-words
Browse files Browse the repository at this point in the history
rename uint256 words
  • Loading branch information
thedavidmeister authored May 18, 2024
2 parents 4575c3e + 8796c66 commit 91a4186
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/concrete/RainterpreterExpressionDeployerNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bytes constant INTEGRITY_FUNCTION_POINTERS =
hex"0e780ef60f5b10d510df10df10e910f2110d11b311b3120f1289129610df10e910df10df10e910d510d510d510d512a012c512df10df12a010df10df129610e910df10df1296129612e912e912e912e910df10e912e910e910e910e910e910df10e910e910e910e910e912e912e912e912e910df10e910e910df10e910e910df10df10e912e912e910e912df";

/// @dev Hash of the metadata that describes the deployer (parsing).
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0xdaefc51add96722d31941d783f342cd84df168c76f277d90c3631f891d494943);
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0x89148873ea148e1c312c3c6cffbc5fb012194570f04ed1177db6002901e7bf38);

/// All config required to construct a `RainterpreterNPE2`.
/// @param interpreter The `IInterpreterV2` to use for evaluation. MUST match
Expand Down
4 changes: 2 additions & 2 deletions src/concrete/RainterpreterParserNPE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {LibParseInterstitial} from "../lib/parse/LibParseInterstitial.sol";

/// @dev The known hash of the parser bytecode. This is used by the deployer to
/// check that it is deploying a parser that is compatible with the interpreter.
bytes32 constant PARSER_BYTECODE_HASH = bytes32(0x63df383ee2349455a770275e9c476ea94fcd6a20c1f5de69572c85f036e456aa);
bytes32 constant PARSER_BYTECODE_HASH = bytes32(0x458b319779ec46db91b9a23ad6cef12479a4e05fa05f5c0094fa3211b1c937cd);

/// @dev Encodes the parser meta that is used to lookup word definitions.
/// The structure of the parser meta is:
Expand All @@ -34,7 +34,7 @@ bytes32 constant PARSER_BYTECODE_HASH = bytes32(0x63df383ee2349455a770275e9c476e
/// 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"029280d0000430610132c412e1426060706098a2144a04900817008118207c1122080000400000000000000000000000000000000000000000000000004000000000000b5e49bb380578dd354d94b70369074e10212ea109609a690dbdd2601ab661e606e9a0f11e79a3c019a3bf081571cbb03a253a5641142dec43939f82322fe3673f8bd71b1114140208a6bbfd22b37cbc37fe60ab2bd890881b00e7793df9f87b1783810e287eb62d2165d32307a294af2df7d93e2336225029e1166b4502286c2fde1fc436d9b5932cedb4ad2627277e12db71382a77ab82166e13b00c9d78f61409a0b03b0c6db8135dfecc0ea46b263ebb5ab92012325b1cd0e81840b898c418f0b3c82e49f5b3443326d604095a090f9e8635026d7b0d245b862742b77f3d25b47f030a2081ac310a9c5e278d28c1003a80e53064dd3133a5359601571cc305b71f5d1db3cf3739c6e9c61f86455b3c8cf0fc34ae0940";
hex"027d02482901b41410193601380a408092011324604290a201223062960011040a8900000000000000000800000008000000100000000000000000000000000000000037af1e5831ee31ff1a4c426226d999cd14d454a62287204a17ca041510bfc04d05382451258fb9fe30e745fd28dbc3c529415aff38530a92368e9cbd2f4c3a173b402c5804ea67600a2aa235164d56371805a7653edd323d0cd5a68e1e3f22703f2237031f80073412d4a5b3119bd3ec068483ae402e554c35f6dc5d23f0c0a632fef45a2da6feff1c9677b92edb58d43c742e374178613501d4fa88030cae020885d59f2b766a3e158413022a67b453194070aa2040ab0f245a53d84392737c335bcbd00ff7e3283d5a200713686f5c39bd3f5f024641b909f14a300b1ec71b27a38323349552b91d792a60425d96b7457b8cf22153f8d14433bccc0d403ded0791b7eb002ddffc0e1abd702ce98c713ac04abd1b4507bb";

/// @dev The build depth of the parser meta.
uint8 constant PARSE_META_BUILD_DEPTH = 2;
Expand Down
47 changes: 24 additions & 23 deletions src/lib/op/LibAllStandardOpsNP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import {LibOpCallNP} from "./call/LibOpCallNP.sol";

import {LibOpHashNP} from "./crypto/LibOpHashNP.sol";

import {LibOpERC20AllowanceNP} from "./erc20/LibOpERC20AllowanceNP.sol";
import {LibOpERC20BalanceOfNP} from "./erc20/LibOpERC20BalanceOfNP.sol";
import {LibOpERC20TotalSupplyNP} from "./erc20/LibOpERC20TotalSupplyNP.sol";
import {LibOpUint256ERC20Allowance} from "./erc20/uint256/LibOpUint256ERC20Allowance.sol";
import {LibOpUint256ERC20BalanceOf} from "./erc20/uint256/LibOpUint256ERC20BalanceOf.sol";
import {LibOpUint256ERC20TotalSupply} from "./erc20/uint256/LibOpUint256ERC20TotalSupply.sol";

import {LibOpERC721BalanceOfNP} from "./erc721/LibOpERC721BalanceOfNP.sol";
import {LibOpERC721OwnerOfNP} from "./erc721/LibOpERC721OwnerOfNP.sol";
import {LibOpUint256ERC721BalanceOf} from "./erc721/uint256/LibOpUint256ERC721BalanceOf.sol";
import {LibOpERC721OwnerOf} from "./erc721/LibOpERC721OwnerOf.sol";

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

Expand Down Expand Up @@ -139,19 +139,20 @@ library LibAllStandardOpsNP {
),
AuthoringMetaV2("hash", "Hashes all inputs into a single 32 byte value using keccak256."),
AuthoringMetaV2(
"erc20-allowance",
"Gets the allowance of an erc20 token for an account. The first input is the token address, the second is the owner address, and the third is the spender address."
"uint256-erc20-allowance",
"Gets the allowance of an erc20 token for an account as a uint256 value. The first input is the token address, the second is the owner address, and the third is the spender address."
),
AuthoringMetaV2(
"erc20-balance-of",
"Gets the balance of an erc20 token for an account. The first input is the token address and the second is the account address."
"uint256-erc20-balance-of",
"Gets the balance of an erc20 token for an account as a uint256 value. The first input is the token address and the second is the account address."
),
AuthoringMetaV2(
"erc20-total-supply", "Gets the total supply of an erc20 token. The input is the token address."
"uint256-erc20-total-supply",
"Gets the total supply of an erc20 token as a uint256 value. The input is the token address."
),
AuthoringMetaV2(
"erc721-balance-of",
"Gets the balance of an erc721 token for an account. The first input is the token address and the second is the account address."
"uint256-erc721-balance-of",
"Gets the balance of an erc721 token for an account as a uint256 value. The first input is the token address and the second is the account address."
),
AuthoringMetaV2(
"erc721-owner-of",
Expand Down Expand Up @@ -354,7 +355,7 @@ library LibAllStandardOpsNP {
LibParseOperand.handleOperandDisallowed,
// erc20-total-supply
LibParseOperand.handleOperandDisallowed,
// erc721-balance-of
// uint256-erc721-balance-of
LibParseOperand.handleOperandDisallowed,
// erc721-owner-of
LibParseOperand.handleOperandDisallowed,
Expand Down Expand Up @@ -505,11 +506,11 @@ library LibAllStandardOpsNP {
LibOpShiftBitsRightNP.integrity,
LibOpCallNP.integrity,
LibOpHashNP.integrity,
LibOpERC20AllowanceNP.integrity,
LibOpERC20BalanceOfNP.integrity,
LibOpERC20TotalSupplyNP.integrity,
LibOpERC721BalanceOfNP.integrity,
LibOpERC721OwnerOfNP.integrity,
LibOpUint256ERC20Allowance.integrity,
LibOpUint256ERC20BalanceOf.integrity,
LibOpUint256ERC20TotalSupply.integrity,
LibOpUint256ERC721BalanceOf.integrity,
LibOpERC721OwnerOf.integrity,
LibOpERC5313OwnerNP.integrity,
LibOpBlockNumberNP.integrity,
LibOpChainIdNP.integrity,
Expand Down Expand Up @@ -611,11 +612,11 @@ library LibAllStandardOpsNP {
LibOpShiftBitsRightNP.run,
LibOpCallNP.run,
LibOpHashNP.run,
LibOpERC20AllowanceNP.run,
LibOpERC20BalanceOfNP.run,
LibOpERC20TotalSupplyNP.run,
LibOpERC721BalanceOfNP.run,
LibOpERC721OwnerOfNP.run,
LibOpUint256ERC20Allowance.run,
LibOpUint256ERC20BalanceOf.run,
LibOpUint256ERC20TotalSupply.run,
LibOpUint256ERC721BalanceOf.run,
LibOpERC721OwnerOf.run,
LibOpERC5313OwnerNP.run,
LibOpBlockNumberNP.run,
LibOpChainIdNP.run,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ pragma solidity ^0.8.18;

import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {Pointer} from "rain.solmem/lib/LibPointer.sol";
import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol";
import {IntegrityCheckStateNP} from "../../../integrity/LibIntegrityCheckNP.sol";
import {Operand} from "rain.interpreter.interface/interface/IInterpreterV2.sol";
import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol";
import {InterpreterStateNP} from "../../../state/LibInterpreterStateNP.sol";

/// @title OpERC20AllowanceNP
/// @title LibOpUint256ERC20Allowance
/// @notice Opcode for getting the current erc20 allowance of an account.
library LibOpERC20AllowanceNP {
library LibOpUint256ERC20Allowance {
function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) {
// Always 3 inputs, the token, the owner and the spender.
// Always 1 output, the allowance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ pragma solidity ^0.8.18;

import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {Pointer} from "rain.solmem/lib/LibPointer.sol";
import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol";
import {IntegrityCheckStateNP} from "../../../integrity/LibIntegrityCheckNP.sol";
import {Operand} from "rain.interpreter.interface/interface/IInterpreterV2.sol";
import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol";
import {InterpreterStateNP} from "../../../state/LibInterpreterStateNP.sol";

/// @title OpERC20BalanceOfNP
/// @title OpUint256ERC20BalanceOf
/// @notice Opcode for getting the current erc20 balance of an account.
library LibOpERC20BalanceOfNP {
library LibOpUint256ERC20BalanceOf {
function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) {
// Always 2 inputs, the token and the account.
// Always 1 output, the balance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ pragma solidity ^0.8.25;

import {IERC20} from "openzeppelin-contracts/contracts/interfaces/IERC20.sol";
import {Pointer} from "rain.solmem/lib/LibPointer.sol";
import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol";
import {IntegrityCheckStateNP} from "../../../integrity/LibIntegrityCheckNP.sol";
import {Operand} from "rain.interpreter.interface/interface/IInterpreterV2.sol";
import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol";
import {InterpreterStateNP} from "../../../state/LibInterpreterStateNP.sol";

/// @title LibOpERC20TotalSupplyNP
/// @title LibOpUint256ERC20TotalSupply
/// @notice Opcode for ERC20 `totalSupply`.
library LibOpERC20TotalSupplyNP {
library LibOpUint256ERC20TotalSupply {
function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) {
// Always 1 input, the contract.
// Always 1 output, the total supply.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol";
import {Operand} from "rain.interpreter.interface/interface/IInterpreterV2.sol";
import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol";

/// @title LibOpERC721OwnerOfNP
/// @title LibOpERC721OwnerOf
/// @notice Opcode for getting the current owner of an erc721 token.
library LibOpERC721OwnerOfNP {
library LibOpERC721OwnerOf {
function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) {
// Always 2 inputs, the token and the tokenId.
// Always 1 output, the owner.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ pragma solidity ^0.8.18;

import {IERC721} from "openzeppelin-contracts/contracts/token/ERC721/IERC721.sol";
import {Pointer} from "rain.solmem/lib/LibPointer.sol";
import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol";
import {IntegrityCheckStateNP} from "../../../integrity/LibIntegrityCheckNP.sol";
import {Operand} from "rain.interpreter.interface/interface/IInterpreterV2.sol";
import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol";
import {InterpreterStateNP} from "../../../state/LibInterpreterStateNP.sol";

/// @title OpERC721BalanceOfNP
/// @title OpUint256ERC721BalanceOf
/// @notice Opcode for getting the current erc721 balance of an account.
library LibOpERC721BalanceOfNP {
library LibOpUint256ERC721BalanceOf {
function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) {
// Always 2 inputs, the token and the account.
// Always 1 output, the balance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ pragma solidity =0.8.25;
import {OpTest} from "test/abstract/OpTest.sol";
import {IntegrityCheckStateNP} from "src/lib/integrity/LibIntegrityCheckNP.sol";
import {Operand} from "rain.interpreter.interface/interface/IInterpreterV2.sol";
import {LibOpERC20AllowanceNP} from "src/lib/op/erc20/LibOpERC20AllowanceNP.sol";
import {LibOpUint256ERC20Allowance} from "src/lib/op/erc20/uint256/LibOpUint256ERC20Allowance.sol";
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {UnexpectedOperand} from "src/error/ErrParse.sol";
import {LibOperand} from "test/lib/operand/LibOperand.sol";

/// @title LibOpERC20AllowanceNPTest
/// @title LibOpUint256ERC20AllowanceTest
/// @notice Test the opcode for getting the allowance of an erc20 token.
contract LibOpERC20AllowanceNPTest is OpTest {
contract LibOpUint256ERC20AllowanceTest is OpTest {
function testOpERC20AllowanceNPIntegrity(IntegrityCheckStateNP memory state, Operand operand) external {
(uint256 calcInputs, uint256 calcOutputs) = LibOpERC20AllowanceNP.integrity(state, operand);
(uint256 calcInputs, uint256 calcOutputs) = LibOpUint256ERC20Allowance.integrity(state, operand);

assertEq(calcInputs, 3);
assertEq(calcOutputs, 1);
Expand All @@ -36,9 +36,9 @@ contract LibOpERC20AllowanceNPTest is OpTest {
opReferenceCheck(
opTestDefaultInterpreterState(),
operand,
LibOpERC20AllowanceNP.referenceFn,
LibOpERC20AllowanceNP.integrity,
LibOpERC20AllowanceNP.run,
LibOpUint256ERC20Allowance.referenceFn,
LibOpUint256ERC20Allowance.integrity,
LibOpUint256ERC20Allowance.run,
inputs
);
}
Expand All @@ -51,39 +51,41 @@ contract LibOpERC20AllowanceNPTest is OpTest {
abi.encode(allowance)
);
checkHappy(
"_: erc20-allowance(0xdeadbeef 0xdeadc0de 0xdeaddead);", allowance, "0xdeadbeef 0xdeadc0de 0xdeaddead"
"_: uint256-erc20-allowance(0xdeadbeef 0xdeadc0de 0xdeaddead);",
allowance,
"0xdeadbeef 0xdeadc0de 0xdeaddead"
);
}

/// Test that a allowance with bad inputs fails integrity.
function testOpERC20AllowanceNPEvalZeroInputs() external {
checkBadInputs("_: erc20-allowance();", 0, 3, 0);
checkBadInputs("_: uint256-erc20-allowance();", 0, 3, 0);
}

function testOpERC20AllowanceNPEvalOneInput() external {
checkBadInputs("_: erc20-allowance(0xdeadbeef);", 1, 3, 1);
checkBadInputs("_: uint256-erc20-allowance(0xdeadbeef);", 1, 3, 1);
}

function testOpERC20AllowanceNPEvalTwoInputs() external {
checkBadInputs("_: erc20-allowance(0xdeadbeef 0xdeadc0de);", 2, 3, 2);
checkBadInputs("_: uint256-erc20-allowance(0xdeadbeef 0xdeadc0de);", 2, 3, 2);
}

function testOpERC20AllowanceNPEvalFourInputs() external {
checkBadInputs("_: erc20-allowance(0xdeadbeef 0xdeadc0de 0xdeaddead 0xdeaddead);", 4, 3, 4);
checkBadInputs("_: uint256-erc20-allowance(0xdeadbeef 0xdeadc0de 0xdeaddead 0xdeaddead);", 4, 3, 4);
}

function testOpERC20AllowanceNPEvalZeroOutputs() external {
checkBadOutputs(": erc20-allowance(0xdeadbeef 0xdeadc0de 0xdeaddead);", 3, 1, 0);
checkBadOutputs(": uint256-erc20-allowance(0xdeadbeef 0xdeadc0de 0xdeaddead);", 3, 1, 0);
}

function testOpERC20AllowanceNPEvalTwoOutputs() external {
checkBadOutputs("_ _: erc20-allowance(0xdeadbeef 0xdeadc0de 0xdeaddead);", 3, 1, 2);
checkBadOutputs("_ _: uint256-erc20-allowance(0xdeadbeef 0xdeadc0de 0xdeaddead);", 3, 1, 2);
}

/// Test that operand is disallowed.
function testOpERC20AllowanceNPEvalOperandDisallowed() external {
checkUnhappyParse(
"_: erc20-allowance<0>(0xdeadbeef 0xdeadc0de 0xdeaddead);",
"_: uint256-erc20-allowance<0>(0xdeadbeef 0xdeadc0de 0xdeaddead);",
abi.encodeWithSelector(UnexpectedOperand.selector)
);
}
Expand Down
Loading

0 comments on commit 91a4186

Please sign in to comment.