Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into yonadaaa/delegation-m…
Browse files Browse the repository at this point in the history
…isconfigured
yonadaa committed Jan 17, 2024
2 parents cb4a653 + 07b57c3 commit 64fc6da
Showing 31 changed files with 383 additions and 146 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-guests-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": major
---

Separated core systems deployment from `CoreModule`, and added the systems as arguments to `CoreModule`
9 changes: 9 additions & 0 deletions .changeset/silver-ligers-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@latticexyz/world": major
---

- Split `CoreSystem` into `AccessManagementSystem`, `BalanceTransferSystem`, `BatchCallSystem`, `CoreRegistrationSystem`
- Changed `CoreModule` to receive the addresses of these systems as arguments, instead of deploying them
- Replaced `CORE_SYSTEM_ID` constant with `ACCESS_MANAGEMENT_SYSTEM_ID`, `BALANCE_TRANSFER_SYSTEM_ID`, `BATCH_CALL_SYSTEM_ID`, `CORE_REGISTRATION_SYSTEM_ID`, for each respective system

These changes separate the initcode of `CoreModule` from the bytecode of core systems, which effectively removes a limit on the total bytecode of all core systems.
79 changes: 76 additions & 3 deletions packages/cli/src/deploy/ensureWorldFactory.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,102 @@
import accessManagementSystemBuild from "@latticexyz/world/out/AccessManagementSystem.sol/AccessManagementSystem.json" assert { type: "json" };
import balanceTransferSystemBuild from "@latticexyz/world/out/BalanceTransferSystem.sol/BalanceTransferSystem.json" assert { type: "json" };
import batchCallSystemBuild from "@latticexyz/world/out/BatchCallSystem.sol/BatchCallSystem.json" assert { type: "json" };
import coreRegistrationSystemBuild from "@latticexyz/world/out/CoreRegistrationSystem.sol/CoreRegistrationSystem.json" assert { type: "json" };
import coreModuleBuild from "@latticexyz/world/out/CoreModule.sol/CoreModule.json" assert { type: "json" };
import coreModuleAbi from "@latticexyz/world/out/CoreModule.sol/CoreModule.abi.json" assert { type: "json" };
import worldFactoryBuild from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.json" assert { type: "json" };
import { Client, Transport, Chain, Account, Hex, parseAbi, getCreate2Address, encodeDeployData, size } from "viem";
import worldFactoryAbi from "@latticexyz/world/out/WorldFactory.sol/WorldFactory.abi.json" assert { type: "json" };
import { Client, Transport, Chain, Account, Hex, getCreate2Address, encodeDeployData, size } from "viem";
import { deployer } from "./ensureDeployer";
import { salt } from "./common";
import { ensureContractsDeployed } from "./ensureContractsDeployed";
import { Contract } from "./ensureContract";

export const accessManagementSystemDeployedBytecodeSize = size(
accessManagementSystemBuild.deployedBytecode.object as Hex
);
export const accessManagementSystemBytecode = encodeDeployData({
bytecode: accessManagementSystemBuild.bytecode.object as Hex,
abi: [],
});
export const accessManagementSystem = getCreate2Address({
from: deployer,
bytecode: accessManagementSystemBytecode,
salt,
});

export const balanceTransferSystemDeployedBytecodeSize = size(
balanceTransferSystemBuild.deployedBytecode.object as Hex
);
export const balanceTransferSystemBytecode = encodeDeployData({
bytecode: balanceTransferSystemBuild.bytecode.object as Hex,
abi: [],
});
export const balanceTransferSystem = getCreate2Address({
from: deployer,
bytecode: balanceTransferSystemBytecode,
salt,
});

export const batchCallSystemDeployedBytecodeSize = size(batchCallSystemBuild.deployedBytecode.object as Hex);
export const batchCallSystemBytecode = encodeDeployData({
bytecode: batchCallSystemBuild.bytecode.object as Hex,
abi: [],
});
export const batchCallSystem = getCreate2Address({ from: deployer, bytecode: batchCallSystemBytecode, salt });

export const coreRegistrationSystemDeployedBytecodeSize = size(
coreRegistrationSystemBuild.deployedBytecode.object as Hex
);
export const coreRegistrationSystemBytecode = encodeDeployData({
bytecode: coreRegistrationSystemBuild.bytecode.object as Hex,
abi: [],
});
export const coreRegistrationSystem = getCreate2Address({
from: deployer,
bytecode: coreRegistrationSystemBytecode,
salt,
});

export const coreModuleDeployedBytecodeSize = size(coreModuleBuild.deployedBytecode.object as Hex);
export const coreModuleBytecode = encodeDeployData({
bytecode: coreModuleBuild.bytecode.object as Hex,
abi: [],
abi: coreModuleAbi,
args: [accessManagementSystem, balanceTransferSystem, batchCallSystem, coreRegistrationSystem],
});

export const coreModule = getCreate2Address({ from: deployer, bytecode: coreModuleBytecode, salt });

export const worldFactoryDeployedBytecodeSize = size(worldFactoryBuild.deployedBytecode.object as Hex);
export const worldFactoryBytecode = encodeDeployData({
bytecode: worldFactoryBuild.bytecode.object as Hex,
abi: parseAbi(["constructor(address)"]),
abi: worldFactoryAbi,
args: [coreModule],
});

export const worldFactory = getCreate2Address({ from: deployer, bytecode: worldFactoryBytecode, salt });

export const worldFactoryContracts: readonly Contract[] = [
{
bytecode: accessManagementSystemBytecode,
deployedBytecodeSize: accessManagementSystemDeployedBytecodeSize,
label: "access management system",
},
{
bytecode: balanceTransferSystemBytecode,
deployedBytecodeSize: balanceTransferSystemDeployedBytecodeSize,
label: "balance transfer system",
},
{
bytecode: batchCallSystemBytecode,
deployedBytecodeSize: batchCallSystemDeployedBytecodeSize,
label: "batch call system",
},
{
bytecode: coreRegistrationSystemBytecode,
deployedBytecodeSize: coreRegistrationSystemDeployedBytecodeSize,
label: "core registration system",
},
{
bytecode: coreModuleBytecode,
deployedBytecodeSize: coreModuleDeployedBytecodeSize,
44 changes: 35 additions & 9 deletions packages/store/test/FieldLayout.t.sol
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import { Test, console } from "forge-std/Test.sol";
import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol";
import { FieldLayout, FieldLayoutLib } from "../src/FieldLayout.sol";
import { FieldLayoutEncodeHelper } from "./FieldLayoutEncodeHelper.sol";
import { MAX_TOTAL_FIELDS, MAX_DYNAMIC_FIELDS } from "../src/constants.sol";

// TODO add tests for all lengths
contract FieldLayoutTest is Test, GasReporter {
@@ -69,13 +70,14 @@ contract FieldLayoutTest is Test, GasReporter {
fieldLayout[20] = 32;
fieldLayout[21] = 32;
fieldLayout[22] = 32;
FieldLayout encodedFieldLayout = FieldLayoutLib.encode(fieldLayout, 5);
FieldLayout encodedFieldLayout = FieldLayoutLib.encode(fieldLayout, MAX_DYNAMIC_FIELDS);

assertEq(encodedFieldLayout.numStaticFields() + encodedFieldLayout.numDynamicFields(), 28);
}

function testFailEncodeTooLong() public pure {
function testEncodeTooLong() public {
uint256[] memory fieldLayout = new uint256[](17);
uint256 dynamicFields = 12;
fieldLayout[0] = 32;
fieldLayout[1] = 32;
fieldLayout[2] = 32;
@@ -93,19 +95,34 @@ contract FieldLayoutTest is Test, GasReporter {
fieldLayout[14] = 32;
fieldLayout[15] = 32;
fieldLayout[16] = 32;
FieldLayoutLib.encode(fieldLayout, 12);
vm.expectRevert(
abi.encodeWithSelector(
FieldLayoutLib.FieldLayoutLib_TooManyFields.selector,
fieldLayout.length + dynamicFields,
MAX_TOTAL_FIELDS
)
);
FieldLayoutLib.encode(fieldLayout, dynamicFields);
}

function testEncodeMaxValidDynamic() public {
uint256[] memory fieldLayout = new uint256[](0);
FieldLayout encodedFieldLayout = FieldLayoutLib.encode(fieldLayout, 5);
FieldLayout encodedFieldLayout = FieldLayoutLib.encode(fieldLayout, MAX_DYNAMIC_FIELDS);

assertEq(encodedFieldLayout.numDynamicFields(), 5);
assertEq(encodedFieldLayout.numDynamicFields(), MAX_DYNAMIC_FIELDS);
}

function testFailEncodeTooManyDynamic() public pure {
function testEncodeTooManyDynamic() public {
uint256[] memory fieldLayout = new uint256[](0);
FieldLayoutLib.encode(fieldLayout, 6);
uint256 dynamicFields = 6;
vm.expectRevert(
abi.encodeWithSelector(
FieldLayoutLib.FieldLayoutLib_TooManyDynamicFields.selector,
fieldLayout.length + dynamicFields,
MAX_DYNAMIC_FIELDS
)
);
FieldLayoutLib.encode(fieldLayout, dynamicFields);
}

function testGetStaticFieldLayoutLength() public {
@@ -173,14 +190,23 @@ contract FieldLayoutTest is Test, GasReporter {
fieldLayout[20] = 32;
fieldLayout[21] = 32;
fieldLayout[22] = 32;
FieldLayout encodedFieldLayout = FieldLayoutLib.encode(fieldLayout, 5);
FieldLayout encodedFieldLayout = FieldLayoutLib.encode(fieldLayout, MAX_DYNAMIC_FIELDS);

startGasReport("validate field layout");
encodedFieldLayout.validate();
endGasReport();
}

function testFailValidate() public pure {
function testValidateInvalidLayout() public {
FieldLayout encodedFieldLayout = FieldLayout.wrap(keccak256("some invalid field layout"));

vm.expectRevert(
abi.encodeWithSelector(
FieldLayoutLib.FieldLayoutLib_TooManyDynamicFields.selector,
encodedFieldLayout.numDynamicFields(),
MAX_DYNAMIC_FIELDS
)
);
FieldLayout.wrap(keccak256("some invalid field layout")).validate();
}

17 changes: 13 additions & 4 deletions packages/store/test/Schema.t.sol
Original file line number Diff line number Diff line change
@@ -36,7 +36,8 @@ contract SchemaTest is Test, GasReporter {
assertEq(uint8(schema.atIndex(5)), uint8(SchemaType.UINT32_ARRAY));
}

function testFailInvalidSchemaStaticAfterDynamic() public pure {
function testInvalidSchemaStaticAfterDynamic() public {
vm.expectRevert(abi.encodeWithSelector(SchemaLib.SchemaLib_StaticTypeAfterDynamicType.selector));
SchemaEncodeHelper.encode(SchemaType.UINT8, SchemaType.UINT32_ARRAY, SchemaType.UINT16);
}

@@ -75,7 +76,7 @@ contract SchemaTest is Test, GasReporter {
assertEq(encodedSchema.numStaticFields() + encodedSchema.numDynamicFields(), 28);
}

function testFailEncodeTooLong() public pure {
function testEncodeTooLong() public {
SchemaType[] memory schema = new SchemaType[](29);
schema[0] = SchemaType.UINT256;
schema[1] = SchemaType.UINT256;
@@ -106,6 +107,7 @@ contract SchemaTest is Test, GasReporter {
schema[26] = SchemaType.UINT32_ARRAY;
schema[27] = SchemaType.UINT32_ARRAY;
schema[28] = SchemaType.UINT32_ARRAY;
vm.expectRevert(abi.encodeWithSelector(SchemaLib.SchemaLib_InvalidLength.selector, schema.length));
SchemaLib.encode(schema);
}

@@ -121,14 +123,15 @@ contract SchemaTest is Test, GasReporter {
assertEq(encodedSchema.numDynamicFields(), 5);
}

function testFailEncodeTooManyDynamic() public pure {
function testEncodeTooManyDynamic() public {
SchemaType[] memory schema = new SchemaType[](6);
schema[0] = SchemaType.UINT32_ARRAY;
schema[1] = SchemaType.UINT32_ARRAY;
schema[2] = SchemaType.UINT32_ARRAY;
schema[3] = SchemaType.UINT32_ARRAY;
schema[4] = SchemaType.UINT32_ARRAY;
schema[5] = SchemaType.UINT32_ARRAY;
vm.expectRevert(abi.encodeWithSelector(SchemaLib.SchemaLib_InvalidLength.selector, schema.length));
SchemaLib.encode(schema);
}

@@ -237,7 +240,13 @@ contract SchemaTest is Test, GasReporter {
endGasReport();
}

function testFailValidate() public pure {
function testValidateInvalidSchema() public {
Schema encodedSchema = Schema.wrap(keccak256("some invalid schema"));

vm.expectRevert(
abi.encodeWithSelector(SchemaLib.SchemaLib_InvalidLength.selector, encodedSchema.numDynamicFields())
);

Schema.wrap(keccak256("some invalid schema")).validate({ allowEmpty: false });
}

28 changes: 14 additions & 14 deletions packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
@@ -75,13 +75,13 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
"name": "install keys in table module",
"gasUsed": 1413384
"gasUsed": 1419104
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "install keys in table module",
"gasUsed": 1413384
"gasUsed": 1419104
},
{
"file": "test/KeysInTableModule.t.sol",
@@ -93,13 +93,13 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallSingleton",
"name": "install keys in table module",
"gasUsed": 1413384
"gasUsed": 1419104
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "install keys in table module",
"gasUsed": 1413384
"gasUsed": 1419104
},
{
"file": "test/KeysInTableModule.t.sol",
@@ -117,7 +117,7 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "install keys in table module",
"gasUsed": 1413384
"gasUsed": 1419104
},
{
"file": "test/KeysInTableModule.t.sol",
@@ -135,7 +135,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testGetKeysWithValueGas",
"name": "install keys with value module",
"gasUsed": 668150
"gasUsed": 674321
},
{
"file": "test/KeysWithValueModule.t.sol",
@@ -153,7 +153,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testInstall",
"name": "install keys with value module",
"gasUsed": 668150
"gasUsed": 674321
},
{
"file": "test/KeysWithValueModule.t.sol",
@@ -165,7 +165,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "install keys with value module",
"gasUsed": 668150
"gasUsed": 674321
},
{
"file": "test/KeysWithValueModule.t.sol",
@@ -183,7 +183,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetField",
"name": "install keys with value module",
"gasUsed": 668150
"gasUsed": 674321
},
{
"file": "test/KeysWithValueModule.t.sol",
@@ -267,7 +267,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromCallboundDelegation",
"name": "register a callbound delegation",
"gasUsed": 118291
"gasUsed": 118138
},
{
"file": "test/StandardDelegationsModule.t.sol",
@@ -279,7 +279,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromSystemDelegation",
"name": "register a systembound delegation",
"gasUsed": 115844
"gasUsed": 115691
},
{
"file": "test/StandardDelegationsModule.t.sol",
@@ -291,7 +291,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromTimeboundDelegation",
"name": "register a timebound delegation",
"gasUsed": 112767
"gasUsed": 112614
},
{
"file": "test/StandardDelegationsModule.t.sol",
@@ -303,7 +303,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "install unique entity module",
"gasUsed": 694902
"gasUsed": 694733
},
{
"file": "test/UniqueEntityModule.t.sol",
@@ -315,7 +315,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "installRoot unique entity module",
"gasUsed": 663830
"gasUsed": 663752
},
{
"file": "test/UniqueEntityModule.t.sol",
Loading

0 comments on commit 64fc6da

Please sign in to comment.