Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Jan 26, 2025
1 parent f52b59c commit 348e7d3
Show file tree
Hide file tree
Showing 26 changed files with 134 additions and 151 deletions.
8 changes: 4 additions & 4 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,10 @@ LibParseUnexpectedRightParenTest:testParseUnexpectedRightParen() (gas: 41612)
LibParseUnexpectedRightParenTest:testParseUnexpectedRightParenNested() (gas: 47269)
LibSubParseSubParserExternTest:testLibSubParseSubParserExtern(address,uint8,uint8,uint8,uint16,uint8) (runs: 2049, μ: 13169, ~: 13112)
LibSubParseSubParserExternTest:testLibSubParseSubParserExternConstantsHeightOverflow(address,uint256,uint8,uint8,uint16,uint8) (runs: 2049, μ: 7949, ~: 7689)
RainterpreterExpressionDeployerNPE2DeployCheckTest:testRainterpreterExpressionDeployerDeployNoEIP1820() (gas: 7050191)
RainterpreterExpressionDeployerNPE2DescribedByMetaV1Test:testRainterpreterExpressionDeployerNPE2DescribedByMetaV1Happy() (gas: 7057837)
RainterpreterExpressionDeployerNPE2IERC165Test:testRainterpreterExpressionDeployerNPE2IERC165(bytes4) (runs: 2049, μ: 7057632, ~: 7057632)
RainterpreterExpressionDeployerNPE2MetaTest:testRainterpreterExpressionDeployerNPE2ExpectedConstructionMetaHash() (gas: 6178)
RainterpreterExpressionDeployerDeployCheckTest:testRainterpreterExpressionDeployerDeployNoEIP1820() (gas: 7050191)
RainterpreterExpressionDeployerDescribedByMetaV1Test:testRainterpreterExpressionDeployerDescribedByMetaV1Happy() (gas: 7057837)
RainterpreterExpressionDeployerIERC165Test:testRainterpreterExpressionDeployerIERC165(bytes4) (runs: 2049, μ: 7057632, ~: 7057632)
RainterpreterExpressionDeployerMetaTest:testRainterpreterExpressionDeployerExpectedConstructionMetaHash() (gas: 6178)
RainterpreterIERC165Test:testRainterpreterIERC165(bytes4) (runs: 2049, μ: 1516943, ~: 1516943)
RainterpreterPointersTest:testOpcodeFunctionPointers() (gas: 1517849)
RainterpreterStateOverlayTest:testStateOverlayGet() (gas: 52978)
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
-t cbor \
-e deflate \
-l none \
-o meta/RainterpreterExpressionDeployerNPE2.rain.meta \
-o meta/RainterpreterExpressionDeployer.rain.meta \
;
rain meta build \
Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fs_permissions = [
{ access = "write", path = "./deployments/latest/RainterpreterParserNPE2" },
{ access = "write", path = "./deployments/latest/RainterpreterStore" },
{ access = "write", path = "./deployments/latest/Rainterpreter" },
{ access = "write", path = "./deployments/latest/RainterpreterExpressionDeployerNPE2" }
{ access = "write", path = "./deployments/latest/RainterpreterExpressionDeployer" }
]

remappings = [
Expand Down
2 changes: 1 addition & 1 deletion lib/rain.interpreter.interface
23 changes: 9 additions & 14 deletions script/BuildPointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {Rainterpreter} from "src/concrete/Rainterpreter.sol";
import {RainterpreterStore} from "src/concrete/RainterpreterStore.sol";
import {RainterpreterParserNPE2, PARSE_META_BUILD_DEPTH} from "src/concrete/RainterpreterParserNPE2.sol";
import {
RainterpreterExpressionDeployerNPE2,
RainterpreterExpressionDeployerNPE2ConstructionConfigV2
} from "src/concrete/RainterpreterExpressionDeployerNPE2.sol";
RainterpreterExpressionDeployer,
RainterpreterExpressionDeployerConstructionConfigV2
} from "src/concrete/RainterpreterExpressionDeployer.sol";
import {
RainterpreterReferenceExtern,
LibRainterpreterReferenceExtern,
Expand All @@ -23,10 +23,7 @@ contract BuildPointers is Script {
Rainterpreter interpreter = new Rainterpreter();

LibFs.buildFileForContract(
vm,
address(interpreter),
"Rainterpreter",
LibCodeGen.opcodeFunctionPointersConstantString(vm, interpreter)
vm, address(interpreter), "Rainterpreter", LibCodeGen.opcodeFunctionPointersConstantString(vm, interpreter)
);
}

Expand All @@ -51,18 +48,16 @@ contract BuildPointers is Script {
);
}

function buildRainterpreterExpressionDeployerNPE2Pointers() internal {
function buildRainterpreterExpressionDeployerPointers() internal {
Rainterpreter interpreter = new Rainterpreter();
RainterpreterStore store = new RainterpreterStore();
RainterpreterParserNPE2 parser = new RainterpreterParserNPE2();

RainterpreterExpressionDeployerNPE2 deployer = new RainterpreterExpressionDeployerNPE2(
RainterpreterExpressionDeployerNPE2ConstructionConfigV2(
address(interpreter), address(store), address(parser)
)
RainterpreterExpressionDeployer deployer = new RainterpreterExpressionDeployer(
RainterpreterExpressionDeployerConstructionConfigV2(address(interpreter), address(store), address(parser))
);

string memory name = "RainterpreterExpressionDeployerNPE2";
string memory name = "RainterpreterExpressionDeployer";

LibFs.buildFileForContract(
vm,
Expand Down Expand Up @@ -104,7 +99,7 @@ contract BuildPointers is Script {
buildRainterpreterPointers();
buildRainterpreterStorePointers();
buildRainterpreterParserNPE2Pointers();
buildRainterpreterExpressionDeployerNPE2Pointers();
buildRainterpreterExpressionDeployerPointers();
buildRainterpreterReferenceExternPointers();
}
}
16 changes: 7 additions & 9 deletions script/Deploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {RainterpreterStore} from "../src/concrete/RainterpreterStore.sol";
import {Rainterpreter} from "../src/concrete/Rainterpreter.sol";
import {RainterpreterParserNPE2} from "../src/concrete/RainterpreterParserNPE2.sol";
import {
RainterpreterExpressionDeployerNPE2,
RainterpreterExpressionDeployerNPE2ConstructionConfigV2
} from "../src/concrete/RainterpreterExpressionDeployerNPE2.sol";
RainterpreterExpressionDeployer,
RainterpreterExpressionDeployerConstructionConfigV2
} from "../src/concrete/RainterpreterExpressionDeployer.sol";
import {IMetaBoardV1_2} from "rain.metadata/interface/unstable/IMetaBoardV1_2.sol";
import {LibDescribedByMeta} from "rain.metadata/lib/LibDescribedByMeta.sol";

Expand All @@ -18,7 +18,7 @@ import {LibDescribedByMeta} from "rain.metadata/lib/LibDescribedByMeta.sol";
contract Deploy is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY");
bytes memory constructionMeta = vm.readFileBinary("meta/RainterpreterExpressionDeployerNPE2.rain.meta");
bytes memory constructionMeta = vm.readFileBinary("meta/RainterpreterExpressionDeployer.rain.meta");
IMetaBoardV1_2 metaboard = IMetaBoardV1_2(vm.envAddress("DEPLOY_METABOARD_ADDRESS"));

vm.startBroadcast(deployerPrivateKey);
Expand All @@ -32,14 +32,12 @@ contract Deploy is Script {
Rainterpreter interpreter = new Rainterpreter();
vm.writeFile("deployments/latest/Rainterpreter", vm.toString(address(interpreter)));

RainterpreterExpressionDeployerNPE2 deployer = new RainterpreterExpressionDeployerNPE2(
RainterpreterExpressionDeployerNPE2ConstructionConfigV2(
address(interpreter), address(store), address(parser)
)
RainterpreterExpressionDeployer deployer = new RainterpreterExpressionDeployer(
RainterpreterExpressionDeployerConstructionConfigV2(address(interpreter), address(store), address(parser))
);
LibDescribedByMeta.emitForDescribedAddress(metaboard, deployer, constructionMeta);

vm.writeFile("deployments/latest/RainterpreterExpressionDeployerNPE2", vm.toString(address(deployer)));
vm.writeFile("deployments/latest/RainterpreterExpressionDeployer", vm.toString(address(deployer)));

vm.stopBroadcast();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {STORE_BYTECODE_HASH} from "./RainterpreterStore.sol";
import {
INTEGRITY_FUNCTION_POINTERS,
DESCRIBED_BY_META_HASH
} from "../generated/RainterpreterExpressionDeployerNPE2.pointers.sol";
} from "../generated/RainterpreterExpressionDeployer.pointers.sol";
import {IIntegrityToolingV1} from "rain.sol.codegen/interface/IIntegrityToolingV1.sol";
import {IParserV1View} from "rain.interpreter.interface/interface/deprecated/IParserV1View.sol";

Expand All @@ -39,14 +39,14 @@ import {IParserV1View} from "rain.interpreter.interface/interface/deprecated/IPa
/// known bytecode.
/// @param store The `IInterpreterStoreV2`. MUST match known bytecode.
/// @param parser The `IParserV1View`. MUST match known bytecode.
struct RainterpreterExpressionDeployerNPE2ConstructionConfigV2 {
struct RainterpreterExpressionDeployerConstructionConfigV2 {
address interpreter;
address store;
address parser;
}

/// @title RainterpreterExpressionDeployerNPE2
contract RainterpreterExpressionDeployerNPE2 is
/// @title RainterpreterExpressionDeployer
contract RainterpreterExpressionDeployer is
IDescribedByMetaV1,
IParserV2,
IParserPragmaV1,
Expand All @@ -64,7 +64,7 @@ contract RainterpreterExpressionDeployerNPE2 is
IInterpreterStoreV2 public immutable iStore;
IParserV1View public immutable iParser;

constructor(RainterpreterExpressionDeployerNPE2ConstructionConfigV2 memory config) {
constructor(RainterpreterExpressionDeployerConstructionConfigV2 memory config) {
// Set the immutables.
IInterpreterV4 interpreter = IInterpreterV4(config.interpreter);
IInterpreterStoreV2 store = IInterpreterStoreV2(config.store);
Expand Down Expand Up @@ -110,9 +110,9 @@ contract RainterpreterExpressionDeployerNPE2 is

/// @inheritdoc IParserV2
function parse2(bytes memory data) external view virtual override returns (bytes memory) {
(bytes memory bytecode, uint256[] memory constants) = iParser.parse(data);
(bytes memory bytecode, bytes32[] memory constants) = iParser.parse(data);

uint256 size = LibInterpreterStateDataContract.serializeSizeNP(bytecode, constants);
uint256 size = LibInterpreterStateDataContract.serializeSize(bytecode, constants);
bytes memory serialized;
Pointer cursor;
assembly ("memory-safe") {
Expand All @@ -121,7 +121,7 @@ contract RainterpreterExpressionDeployerNPE2 is
mstore(serialized, size)
cursor := add(serialized, 0x20)
}
LibInterpreterStateDataContract.unsafeSerializeNP(cursor, bytecode, constants);
LibInterpreterStateDataContract.unsafeSerialize(cursor, bytecode, constants);

bytes memory io = LibIntegrityCheckNP.integrityCheck2(INTEGRITY_FUNCTION_POINTERS, bytecode, constants);
// Nothing is done with IO in IParserV2.
Expand Down
6 changes: 3 additions & 3 deletions src/concrete/RainterpreterStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ contract RainterpreterStore is IInterpreterStoreV3, ERC165 {
/// callers cannot attack each other
/// 1. StateNamespace is caller-provided namespace so that expressions cannot
/// attack each other
/// 2. `uint256` is expression-provided key
/// 3. `uint256` is expression-provided value
/// 2. `bytes32` is expression-provided key
/// 3. `bytes32` is expression-provided value
///
/// tiers 0 and 1 are both embodied in the `FullyQualifiedNamespace`.
// Slither doesn't like the leading underscore.
//solhint-disable-next-line private-vars-leading-underscore
mapping(FullyQualifiedNamespace fullyQualifiedNamespace => mapping(uint256 key => uint256 value)) internal sStore;
mapping(FullyQualifiedNamespace fullyQualifiedNamespace => mapping(bytes32 key => bytes32 value)) internal sStore;

/// @inheritdoc ERC165
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
Expand Down
2 changes: 1 addition & 1 deletion src/error/ErrDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract ErrDeploy {}
/// address upon construction.
error UnexpectedPointers(bytes actualPointers);

/// Thrown when the `RainterpreterExpressionDeployerNPE2` is constructed with
/// Thrown when the `RainterpreterExpressionDeployer` is constructed with
/// unknown interpreter bytecode.
/// @param expectedBytecodeHash The bytecode hash that was expected at the
/// interpreter address upon construction.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants/ExpressionDeployerNPConstants.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: CAL
pragma solidity ^0.8.18;

string constant EXPRESSION_DEPLOYER_NP_META_PATH = "meta/RainterpreterExpressionDeployerNPE2.rain.meta";
string constant EXPRESSION_DEPLOYER_NP_META_PATH = "meta/RainterpreterExpressionDeployer.rain.meta";
4 changes: 2 additions & 2 deletions src/lib/state/LibInterpreterStateDataContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {InterpreterState} from "./LibInterpreterState.sol";
library LibInterpreterStateDataContract {
using LibBytes for bytes;

function serializeSizeNP(bytes memory bytecode, bytes32[] memory constants) internal pure returns (uint256 size) {
function serializeSize(bytes memory bytecode, bytes32[] memory constants) internal pure returns (uint256 size) {
unchecked {
// bytecode length + constants length * 0x20 + 0x40 for both the bytecode and constants length words.
size = bytecode.length + constants.length * 0x20 + 0x40;
}
}

function unsafeSerializeNP(Pointer cursor, bytes memory bytecode, bytes32[] memory constants) internal pure {
function unsafeSerialize(Pointer cursor, bytes memory bytecode, bytes32[] memory constants) internal pure {
unchecked {
// Copy constants into place with length.
assembly ("memory-safe") {
Expand Down
32 changes: 16 additions & 16 deletions test/abstract/OpTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {MemoryKV} from "rain.lib.memkv/lib/LibMemoryKV.sol";
import {LibUint256Array} from "rain.solmem/lib/LibUint256Array.sol";
import {LibPointer, Pointer} from "rain.solmem/lib/LibPointer.sol";

import {RainterpreterExpressionDeployerNPE2DeploymentTest} from
"./RainterpreterExpressionDeployerNPE2DeploymentTest.sol";
import {RainterpreterExpressionDeployerDeploymentTest} from "./RainterpreterExpressionDeployerDeploymentTest.sol";
import {LibInterpreterState, InterpreterState} from "../../src/lib/state/LibInterpreterState.sol";
import {IntegrityCheckState, LibIntegrityCheckNP} from "../../src/lib/integrity/LibIntegrityCheckNP.sol";

Expand All @@ -19,8 +18,9 @@ import {
OperandV2,
IInterpreterV4,
SourceIndexV2,
IInterpreterStoreV2,
EvalV4
IInterpreterStoreV3,
EvalV4,
StackItem
} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
import {FullyQualifiedNamespace, StateNamespace} from "rain.interpreter.interface/interface/IInterpreterStoreV2.sol";
import {SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV3.sol";
Expand All @@ -29,7 +29,7 @@ import {LibNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.sol";
uint256 constant PRE = uint256(keccak256(abi.encodePacked("pre")));
uint256 constant POST = uint256(keccak256(abi.encodePacked("post")));

abstract contract OpTest is RainterpreterExpressionDeployerNPE2DeploymentTest {
abstract contract OpTest is RainterpreterExpressionDeployerDeploymentTest {
using LibInterpreterState for InterpreterState;
using LibUint256Array for uint256[];
using LibPointer for Pointer;
Expand Down Expand Up @@ -62,20 +62,20 @@ abstract contract OpTest is RainterpreterExpressionDeployerNPE2DeploymentTest {
}

function opTestDefaultIngegrityCheckState() internal pure returns (IntegrityCheckState memory) {
return IntegrityCheckState(0, 0, 0, new uint256[](0), 0, "");
return IntegrityCheckState(0, 0, 0, new bytes32[](0), 0, "");
}

function opTestDefaultInterpreterState() internal view returns (InterpreterState memory) {
return InterpreterState(
new Pointer[](0),
new uint256[](0),
new bytes32[](0),
0,
MemoryKV.wrap(0),
// Treat ourselves as the sender as we eval internally to directly
// test the opcode logic.
LibNamespace.qualifyNamespace(StateNamespace.wrap(0), address(this)),
IInterpreterStoreV2(address(iStore)),
new uint256[][](0),
IInterpreterStoreV3(address(iStore)),
new bytes32[][](0),
"",
""
);
Expand All @@ -84,13 +84,13 @@ abstract contract OpTest is RainterpreterExpressionDeployerNPE2DeploymentTest {
function opReferenceCheckIntegrity(
function(IntegrityCheckState memory, OperandV2) view returns (uint256, uint256) integrityFn,
OperandV2 operand,
uint256[] memory constants,
bytes32[] memory constants,
uint256[] memory inputs
) internal view returns (uint256) {
IntegrityCheckState memory integrityState = LibIntegrityCheckNP.newState("", 0, constants);
(uint256 calcInputs, uint256 calcOutputs) = integrityFn(integrityState, operand);
assertEq(calcInputs, inputs.length, "inputs length");
assertEq(calcInputs, uint256((OperandV2.unwrap(operand) >> 0x10) & 0x0F), "operand inputs");
assertEq(calcInputs, uint256((OperandV2.unwrap(operand) >> 0x10) & bytes32(uint256(0x0F))), "operand inputs");
assertEq(calcOutputs, uint256(OperandV2.unwrap(operand) >> 0x14), "operand outputs");
return calcOutputs;
}
Expand Down Expand Up @@ -190,19 +190,19 @@ abstract contract OpTest is RainterpreterExpressionDeployerNPE2DeploymentTest {
function parseAndEval(bytes memory rainString, uint256[][] memory context)
internal
view
returns (uint256[] memory, uint256[] memory)
returns (StackItem[] memory, bytes32[] memory)
{
bytes memory bytecode = iDeployer.parse2(rainString);

(uint256[] memory stack, uint256[] memory kvs) = iInterpreter.eval4(
(StackItem[] memory stack, bytes32[] memory kvs) = iInterpreter.eval4(
EvalV4({
store: iStore,
namespace: LibNamespace.qualifyNamespace(StateNamespace.wrap(0), address(this)),
bytecode: bytecode,
sourceIndex: SourceIndexV2.wrap(0),
context: context,
inputs: new uint256[](0),
stateOverlay: new uint256[](0)
inputs: new StackItem[](0),
stateOverlay: new bytes32[](0)
})
);
return (stack, kvs);
Expand All @@ -211,7 +211,7 @@ abstract contract OpTest is RainterpreterExpressionDeployerNPE2DeploymentTest {
/// 90%+ of the time we don't need to pass a context. This overloads a
/// simplified interface to parse and eval.
function parseAndEval(bytes memory rainString) internal view returns (uint256[] memory, uint256[] memory) {
return parseAndEval(rainString, LibContext.build(new uint256[][](0), new SignedContextV1[](0)));
return parseAndEval(rainString, LibContext.build(new bytes32[][](0), new SignedContextV1[](0)));
}

function checkHappy(bytes memory rainString, uint256 expectedValue, string memory errString) internal view {
Expand Down
Loading

0 comments on commit 348e7d3

Please sign in to comment.