diff --git a/.changeset/eleven-zebras-travel.md b/.changeset/eleven-zebras-travel.md new file mode 100644 index 0000000000..5eac8b38c4 --- /dev/null +++ b/.changeset/eleven-zebras-travel.md @@ -0,0 +1,6 @@ +--- +"@latticexyz/store": patch +"@latticexyz/world": patch +--- + +Renamed the `requireNoCallback` modifier to `prohibitDirectCallback`. diff --git a/packages/store/src/FieldLayout.sol b/packages/store/src/FieldLayout.sol index 09f46a3ebd..bd1ea91a4d 100644 --- a/packages/store/src/FieldLayout.sol +++ b/packages/store/src/FieldLayout.sol @@ -35,21 +35,21 @@ library FieldLayoutLib { * @notice Encodes the given field layout into a single bytes32. * @dev Ensures various constraints on the length and size of the fields. * Reverts if total fields, static field length, or static byte length exceed allowed limits. - * @param _staticFields An array of static field lengths. + * @param _staticFieldLengths An array of static field lengths. * @param numDynamicFields The number of dynamic fields. * @return A FieldLayout structure containing the encoded field layout. */ - function encode(uint256[] memory _staticFields, uint256 numDynamicFields) internal pure returns (FieldLayout) { + function encode(uint256[] memory _staticFieldLengths, uint256 numDynamicFields) internal pure returns (FieldLayout) { uint256 fieldLayout; uint256 totalLength; - uint256 totalFields = _staticFields.length + numDynamicFields; + uint256 totalFields = _staticFieldLengths.length + numDynamicFields; if (totalFields > MAX_TOTAL_FIELDS) revert FieldLayoutLib_TooManyFields(totalFields, MAX_TOTAL_FIELDS); if (numDynamicFields > MAX_DYNAMIC_FIELDS) revert FieldLayoutLib_TooManyDynamicFields(numDynamicFields, MAX_DYNAMIC_FIELDS); // Compute the total static length and store the field lengths in the encoded fieldLayout - for (uint256 i = 0; i < _staticFields.length; ) { - uint256 staticByteLength = _staticFields[i]; + for (uint256 i = 0; i < _staticFieldLengths.length; ) { + uint256 staticByteLength = _staticFieldLengths[i]; if (staticByteLength == 0) { revert FieldLayoutLib_StaticLengthIsZero(); } else if (staticByteLength > WORD_SIZE) { @@ -57,11 +57,11 @@ library FieldLayoutLib { } unchecked { - // (safe because 28 (max _staticFields.length) * 32 (max static length) < 2**16) + // (safe because 28 (max _staticFieldLengths.length) * 32 (max static length) < 2**16) totalLength += staticByteLength; // Sequentially store lengths after the first 4 bytes (which are reserved for total length and field numbers) - // (safe because of the initial _staticFields.length check) - fieldLayout |= uint256(_staticFields[i]) << ((WORD_LAST_INDEX - 4 - i) * BYTE_TO_BITS); + // (safe because of the initial _staticFieldLengths.length check) + fieldLayout |= uint256(_staticFieldLengths[i]) << ((WORD_LAST_INDEX - 4 - i) * BYTE_TO_BITS); i++; } } @@ -71,7 +71,7 @@ library FieldLayoutLib { // number of dynamic fields in the 4th byte // (optimizer can handle this, no need for unchecked or single-line assignment) fieldLayout |= totalLength << LayoutOffsets.TOTAL_LENGTH; - fieldLayout |= _staticFields.length << LayoutOffsets.NUM_STATIC_FIELDS; + fieldLayout |= _staticFieldLengths.length << LayoutOffsets.NUM_STATIC_FIELDS; fieldLayout |= numDynamicFields << LayoutOffsets.NUM_DYNAMIC_FIELDS; return FieldLayout.wrap(bytes32(fieldLayout)); diff --git a/packages/store/src/Hook.sol b/packages/store/src/Hook.sol index c62e3bb7c8..f9ac5c3bff 100644 --- a/packages/store/src/Hook.sol +++ b/packages/store/src/Hook.sol @@ -30,15 +30,15 @@ library HookLib { * @notice Filter a hook from the hook list by its address. * @dev This function writes the updated hook list to the table in place. * @param hookTableId The resource ID of the hook table. - * @param tableWithHooks The resource ID of the table with hooks to filter. + * @param resourceWithHooks The resource ID of the table with hooks to filter. * @param hookAddressToRemove The address of the hook to remove. */ function filterListByAddress( ResourceId hookTableId, - ResourceId tableWithHooks, + ResourceId resourceWithHooks, address hookAddressToRemove ) internal { - bytes21[] memory currentHooks = Hooks._get(hookTableId, tableWithHooks); + bytes21[] memory currentHooks = Hooks._get(hookTableId, resourceWithHooks); // Initialize the new hooks array with the same length because we don't know if the hook is registered yet bytes21[] memory newHooks = new bytes21[](currentHooks.length); @@ -61,7 +61,7 @@ library HookLib { } // Set the new hooks table - Hooks._set(hookTableId, tableWithHooks, newHooks); + Hooks._set(hookTableId, resourceWithHooks, newHooks); } } diff --git a/packages/world/src/Create2.sol b/packages/world/src/Create2.sol index 3b06186d5c..486dadb5c2 100644 --- a/packages/world/src/Create2.sol +++ b/packages/world/src/Create2.sol @@ -15,20 +15,20 @@ library Create2 { * * Requirements: * - * - `bytecode` must not be empty. - * - `salt` must have not been used for `bytecode` already. + * - `creationCode` must not be empty. + * - `salt` must have not been used for `creationCode` already. * - * @param byteCode The bytecode of the contract to be deployed. + * @param creationCode The bytecode of the contract to be deployed. * @param salt A 256-bit value that, combined with the bytecode, determines the address. * @return addr The address of the newly deployed contract. * @dev If the CREATE2 fails, reverts */ - function deploy(bytes memory byteCode, uint256 salt) internal returns (address addr) { + function deploy(bytes memory creationCode, uint256 salt) internal returns (address addr) { assembly { - // byteCode is one word (0x20 bytes) with the length, followed by the actual - // code for the constructor. So the code starts at byteCode+0x20, and is mload(byteCode) + // creationCode is one word (0x20 bytes) with the length, followed by the actual + // code for the constructor. So the code starts at creationCode+0x20, and is mload(creationCode) // bytes long. - addr := create2(0, add(byteCode, 0x20), mload(byteCode), salt) + addr := create2(0, add(creationCode, 0x20), mload(creationCode), salt) if iszero(extcodesize(addr)) { revert(0, 0) } diff --git a/packages/world/src/World.sol b/packages/world/src/World.sol index fbd17cc510..20284534c1 100644 --- a/packages/world/src/World.sol +++ b/packages/world/src/World.sol @@ -52,7 +52,7 @@ contract World is StoreData, IWorldKernel { /** * @dev Prevents the World contract from calling itself. */ - modifier requireNoCallback() { + modifier prohibitDirectCallback() { if (msg.sender == address(this)) { revert World_CallbackNotAllowed(msg.sig); } @@ -64,7 +64,7 @@ contract World is StoreData, IWorldKernel { * @param coreModule The core module to initialize the World with. * @dev Only the initial creator can initialize. This can be done only once. */ - function initialize(IModule coreModule) public requireNoCallback { + function initialize(IModule coreModule) public prohibitDirectCallback { // Only the initial creator of the World can initialize it if (msg.sender != creator) { revert World_AccessDenied(ROOT_NAMESPACE_ID.toString(), msg.sender); @@ -85,7 +85,7 @@ contract World is StoreData, IWorldKernel { * @param args Arguments for module installation. * @dev The caller must own the root namespace. */ - function installRootModule(IModule module, bytes memory args) public requireNoCallback { + function installRootModule(IModule module, bytes memory args) public prohibitDirectCallback { AccessControl.requireOwner(ROOT_NAMESPACE_ID, msg.sender); _installRootModule(module, args); } @@ -131,7 +131,7 @@ contract World is StoreData, IWorldKernel { bytes calldata staticData, PackedCounter encodedLengths, bytes calldata dynamicData - ) public virtual requireNoCallback { + ) public virtual prohibitDirectCallback { // Require access to the namespace or name AccessControl.requireAccess(tableId, msg.sender); @@ -151,7 +151,7 @@ contract World is StoreData, IWorldKernel { bytes32[] calldata keyTuple, uint48 start, bytes calldata data - ) public virtual requireNoCallback { + ) public virtual prohibitDirectCallback { // Require access to the namespace or name AccessControl.requireAccess(tableId, msg.sender); @@ -175,7 +175,7 @@ contract World is StoreData, IWorldKernel { uint40 startWithinField, uint40 deleteCount, bytes calldata data - ) public virtual requireNoCallback { + ) public virtual prohibitDirectCallback { // Require access to the namespace or name AccessControl.requireAccess(tableId, msg.sender); @@ -195,7 +195,7 @@ contract World is StoreData, IWorldKernel { bytes32[] calldata keyTuple, uint8 fieldIndex, bytes calldata data - ) public virtual requireNoCallback { + ) public virtual prohibitDirectCallback { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); @@ -217,7 +217,7 @@ contract World is StoreData, IWorldKernel { uint8 fieldIndex, bytes calldata data, FieldLayout fieldLayout - ) public virtual requireNoCallback { + ) public virtual prohibitDirectCallback { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); @@ -240,7 +240,7 @@ contract World is StoreData, IWorldKernel { uint8 fieldIndex, bytes calldata data, FieldLayout fieldLayout - ) public virtual requireNoCallback { + ) public virtual prohibitDirectCallback { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); @@ -260,7 +260,7 @@ contract World is StoreData, IWorldKernel { bytes32[] calldata keyTuple, uint8 dynamicFieldIndex, bytes calldata data - ) public virtual requireNoCallback { + ) public virtual prohibitDirectCallback { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); @@ -280,7 +280,7 @@ contract World is StoreData, IWorldKernel { bytes32[] calldata keyTuple, uint8 dynamicFieldIndex, bytes calldata dataToPush - ) public virtual requireNoCallback { + ) public virtual prohibitDirectCallback { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); @@ -300,7 +300,7 @@ contract World is StoreData, IWorldKernel { bytes32[] calldata keyTuple, uint8 dynamicFieldIndex, uint256 byteLengthToPop - ) public virtual requireNoCallback { + ) public virtual prohibitDirectCallback { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); @@ -314,7 +314,7 @@ contract World is StoreData, IWorldKernel { * @param keyTuple Array of keys identifying the record to delete. * @dev Requires the caller to have access to the table's namespace or name. */ - function deleteRecord(ResourceId tableId, bytes32[] calldata keyTuple) public virtual requireNoCallback { + function deleteRecord(ResourceId tableId, bytes32[] calldata keyTuple) public virtual prohibitDirectCallback { // Require access to namespace or name AccessControl.requireAccess(tableId, msg.sender); @@ -338,7 +338,7 @@ contract World is StoreData, IWorldKernel { function call( ResourceId systemId, bytes memory callData - ) external payable virtual requireNoCallback returns (bytes memory) { + ) external payable virtual prohibitDirectCallback returns (bytes memory) { return SystemCall.callWithHooksOrRevert(msg.sender, systemId, callData, msg.value); } @@ -354,7 +354,7 @@ contract World is StoreData, IWorldKernel { address delegator, ResourceId systemId, bytes memory callData - ) external payable virtual requireNoCallback returns (bytes memory) { + ) external payable virtual prohibitDirectCallback returns (bytes memory) { // If the delegator is the caller, call the system directly if (delegator == msg.sender) { return SystemCall.callWithHooksOrRevert(msg.sender, systemId, callData, msg.value); @@ -402,7 +402,7 @@ contract World is StoreData, IWorldKernel { /** * @dev Fallback function to call registered function selectors. */ - fallback() external payable requireNoCallback { + fallback() external payable prohibitDirectCallback { (ResourceId systemId, bytes4 systemFunctionSelector) = FunctionSelectors._get(msg.sig); if (ResourceId.unwrap(systemId) == 0) revert World_FunctionSelectorNotFound(msg.sig);