diff --git a/.changeset/lovely-fireants-behave.md b/.changeset/lovely-fireants-behave.md new file mode 100644 index 0000000000..6e6968e1ca --- /dev/null +++ b/.changeset/lovely-fireants-behave.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/world": patch +--- + +Renamed all `funcSelectorAndArgs` arguments to `callData` for clarity. diff --git a/packages/world/mud.config.ts b/packages/world/mud.config.ts index 97563a1cdf..1ad535703d 100644 --- a/packages/world/mud.config.ts +++ b/packages/world/mud.config.ts @@ -150,7 +150,7 @@ export default mudConfig({ delegator: "address", delegatee: "address", resourceSelector: "bytes32", - funcSelectorAndArgsHash: "bytes32", + callDataHash: "bytes32", }, valueSchema: { availableCalls: "uint256", diff --git a/packages/world/src/Delegation.sol b/packages/world/src/Delegation.sol index c4140ea0d7..8a4a0b9b8e 100644 --- a/packages/world/src/Delegation.sol +++ b/packages/world/src/Delegation.sol @@ -32,7 +32,7 @@ library DelegationInstance { address delegator, address delegatee, bytes32 systemId, - bytes memory funcSelectorAndArgs + bytes memory callData ) internal returns (bool) { // Early return if there is an unlimited delegation if (isUnlimited(self)) return true; @@ -44,12 +44,7 @@ library DelegationInstance { (bool success, bytes memory data) = SystemCall.call({ caller: delegatee, resourceSelector: Delegation.unwrap(self), - funcSelectorAndArgs: abi.encodeWithSelector( - IDelegationControl.verify.selector, - delegator, - systemId, - funcSelectorAndArgs - ), + callData: abi.encodeWithSelector(IDelegationControl.verify.selector, delegator, systemId, callData), value: 0 }); diff --git a/packages/world/src/SystemCall.sol b/packages/world/src/SystemCall.sol index e6ec08e28f..27241b9a6b 100644 --- a/packages/world/src/SystemCall.sol +++ b/packages/world/src/SystemCall.sol @@ -31,7 +31,7 @@ library SystemCall { address caller, uint256 value, bytes32 resourceSelector, - bytes memory funcSelectorAndArgs + bytes memory callData ) internal returns (bool success, bytes memory data) { // Load the system data (address systemAddress, bool publicAccess) = Systems._get(resourceSelector); @@ -55,13 +55,13 @@ library SystemCall { msgSender: caller, msgValue: value, target: systemAddress, - funcSelectorAndArgs: funcSelectorAndArgs + callData: callData }) : WorldContextProvider.callWithContext({ msgSender: caller, msgValue: value, target: systemAddress, - funcSelectorAndArgs: funcSelectorAndArgs + callData: callData }); } @@ -72,7 +72,7 @@ library SystemCall { function callWithHooks( address caller, bytes32 resourceSelector, - bytes memory funcSelectorAndArgs, + bytes memory callData, uint256 value ) internal returns (bool success, bytes memory data) { // Get system hooks @@ -82,23 +82,18 @@ library SystemCall { for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(BEFORE_CALL_SYSTEM)) { - ISystemHook(hook.getAddress()).onBeforeCallSystem(caller, resourceSelector, funcSelectorAndArgs); + ISystemHook(hook.getAddress()).onBeforeCallSystem(caller, resourceSelector, callData); } } // Call the system and forward any return data - (success, data) = call({ - caller: caller, - value: value, - resourceSelector: resourceSelector, - funcSelectorAndArgs: funcSelectorAndArgs - }); + (success, data) = call({ caller: caller, value: value, resourceSelector: resourceSelector, callData: callData }); // Call onAfterCallSystem hooks (after calling the system) for (uint256 i; i < hooks.length; i++) { Hook hook = Hook.wrap(hooks[i]); if (hook.isEnabled(AFTER_CALL_SYSTEM)) { - ISystemHook(hook.getAddress()).onAfterCallSystem(caller, resourceSelector, funcSelectorAndArgs); + ISystemHook(hook.getAddress()).onAfterCallSystem(caller, resourceSelector, callData); } } } @@ -110,14 +105,14 @@ library SystemCall { function callWithHooksOrRevert( address caller, bytes32 resourceSelector, - bytes memory funcSelectorAndArgs, + bytes memory callData, uint256 value ) internal returns (bytes memory data) { (bool success, bytes memory returnData) = callWithHooks({ caller: caller, value: value, resourceSelector: resourceSelector, - funcSelectorAndArgs: funcSelectorAndArgs + callData: callData }); if (!success) revertWithBytes(returnData); return returnData; diff --git a/packages/world/src/World.sol b/packages/world/src/World.sol index 88265fa063..7b61f52e0e 100644 --- a/packages/world/src/World.sol +++ b/packages/world/src/World.sol @@ -85,7 +85,7 @@ contract World is StoreRead, IStoreData, IWorldKernel { msgSender: msg.sender, msgValue: 0, target: address(module), - funcSelectorAndArgs: abi.encodeWithSelector(IModule.installRoot.selector, args) + callData: abi.encodeWithSelector(IModule.installRoot.selector, args) }); // Register the module in the InstalledModules table @@ -212,11 +212,8 @@ contract World is StoreRead, IStoreData, IWorldKernel { * Call the system at the given resourceSelector. * If the system is not public, the caller must have access to the namespace or name (encoded in the resourceSelector). */ - function call( - bytes32 resourceSelector, - bytes memory funcSelectorAndArgs - ) external payable virtual returns (bytes memory) { - return SystemCall.callWithHooksOrRevert(msg.sender, resourceSelector, funcSelectorAndArgs, msg.value); + function call(bytes32 resourceSelector, bytes memory callData) external payable virtual returns (bytes memory) { + return SystemCall.callWithHooksOrRevert(msg.sender, resourceSelector, callData, msg.value); } /** @@ -226,26 +223,26 @@ contract World is StoreRead, IStoreData, IWorldKernel { function callFrom( address delegator, bytes32 resourceSelector, - bytes memory funcSelectorAndArgs + bytes memory callData ) external payable virtual returns (bytes memory) { // If the delegator is the caller, call the system directly if (delegator == msg.sender) { - return SystemCall.callWithHooksOrRevert(msg.sender, resourceSelector, funcSelectorAndArgs, msg.value); + return SystemCall.callWithHooksOrRevert(msg.sender, resourceSelector, callData, msg.value); } // Check if there is an explicit authorization for this caller to perform actions on behalf of the delegator Delegation explicitDelegation = Delegation.wrap(Delegations._get({ delegator: delegator, delegatee: msg.sender })); - if (explicitDelegation.verify(delegator, msg.sender, resourceSelector, funcSelectorAndArgs)) { + if (explicitDelegation.verify(delegator, msg.sender, resourceSelector, callData)) { // forward the call as `delegator` - return SystemCall.callWithHooksOrRevert(delegator, resourceSelector, funcSelectorAndArgs, msg.value); + return SystemCall.callWithHooksOrRevert(delegator, resourceSelector, callData, msg.value); } // Check if the delegator has a fallback delegation control set Delegation fallbackDelegation = Delegation.wrap(Delegations._get({ delegator: delegator, delegatee: address(0) })); - if (fallbackDelegation.verify(delegator, msg.sender, resourceSelector, funcSelectorAndArgs)) { + if (fallbackDelegation.verify(delegator, msg.sender, resourceSelector, callData)) { // forward the call with `from` as `msgSender` - return SystemCall.callWithHooksOrRevert(delegator, resourceSelector, funcSelectorAndArgs, msg.value); + return SystemCall.callWithHooksOrRevert(delegator, resourceSelector, callData, msg.value); } revert DelegationNotFound(delegator, msg.sender); diff --git a/packages/world/src/WorldContext.sol b/packages/world/src/WorldContext.sol index 167bb88ee8..7c29e09f25 100644 --- a/packages/world/src/WorldContext.sol +++ b/packages/world/src/WorldContext.sol @@ -46,21 +46,21 @@ abstract contract WorldContextConsumer is IWorldContextConsumer { */ library WorldContextProvider { function appendContext( - bytes memory funcSelectorAndArgs, + bytes memory callData, address msgSender, uint256 msgValue ) internal pure returns (bytes memory) { - return abi.encodePacked(funcSelectorAndArgs, msgSender, msgValue); + return abi.encodePacked(callData, msgSender, msgValue); } function callWithContext( address msgSender, uint256 msgValue, address target, - bytes memory funcSelectorAndArgs + bytes memory callData ) internal returns (bool success, bytes memory data) { (success, data) = target.call{ value: 0 }( - appendContext({ funcSelectorAndArgs: funcSelectorAndArgs, msgSender: msgSender, msgValue: msgValue }) + appendContext({ callData: callData, msgSender: msgSender, msgValue: msgValue }) ); } @@ -68,10 +68,10 @@ library WorldContextProvider { address msgSender, uint256 msgValue, address target, - bytes memory funcSelectorAndArgs + bytes memory callData ) internal returns (bool success, bytes memory data) { (success, data) = target.delegatecall( - appendContext({ funcSelectorAndArgs: funcSelectorAndArgs, msgSender: msgSender, msgValue: msgValue }) + appendContext({ callData: callData, msgSender: msgSender, msgValue: msgValue }) ); } @@ -79,13 +79,13 @@ library WorldContextProvider { address msgSender, uint256 msgValue, address target, - bytes memory funcSelectorAndArgs + bytes memory callData ) internal returns (bytes memory data) { (bool success, bytes memory _data) = callWithContext({ msgSender: msgSender, msgValue: msgValue, target: target, - funcSelectorAndArgs: funcSelectorAndArgs + callData: callData }); if (!success) revertWithBytes(_data); return _data; @@ -95,13 +95,13 @@ library WorldContextProvider { address msgSender, uint256 msgValue, address target, - bytes memory funcSelectorAndArgs + bytes memory callData ) internal returns (bytes memory data) { (bool success, bytes memory _data) = delegatecallWithContext({ msgSender: msgSender, msgValue: msgValue, target: target, - funcSelectorAndArgs: funcSelectorAndArgs + callData: callData }); if (!success) revertWithBytes(_data); return _data; diff --git a/packages/world/src/interfaces/IDelegationControl.sol b/packages/world/src/interfaces/IDelegationControl.sol index 2da8324ec1..3f77f24632 100644 --- a/packages/world/src/interfaces/IDelegationControl.sol +++ b/packages/world/src/interfaces/IDelegationControl.sol @@ -8,5 +8,5 @@ bytes4 constant DELEGATION_CONTROL_INTERFACE_ID = IDelegationControl.verify.sele WORLD_CONTEXT_CONSUMER_INTERFACE_ID; interface IDelegationControl is IWorldContextConsumer { - function verify(address delegator, bytes32 systemId, bytes calldata funcSelectorAndArgs) external returns (bool); + function verify(address delegator, bytes32 systemId, bytes calldata callData) external returns (bool); } diff --git a/packages/world/src/interfaces/ISystemHook.sol b/packages/world/src/interfaces/ISystemHook.sol index cb1526bcf2..a09c15f796 100644 --- a/packages/world/src/interfaces/ISystemHook.sol +++ b/packages/world/src/interfaces/ISystemHook.sol @@ -9,7 +9,7 @@ bytes4 constant SYSTEM_HOOK_INTERFACE_ID = ISystemHook.onBeforeCallSystem.select ERC165_INTERFACE_ID; interface ISystemHook is IERC165 { - function onBeforeCallSystem(address msgSender, bytes32 resourceSelector, bytes memory funcSelectorAndArgs) external; + function onBeforeCallSystem(address msgSender, bytes32 resourceSelector, bytes memory callData) external; - function onAfterCallSystem(address msgSender, bytes32 resourceSelector, bytes memory funcSelectorAndArgs) external; + function onAfterCallSystem(address msgSender, bytes32 resourceSelector, bytes memory callData) external; } diff --git a/packages/world/src/interfaces/IWorldKernel.sol b/packages/world/src/interfaces/IWorldKernel.sol index d5b1c5cec4..72395d553d 100644 --- a/packages/world/src/interfaces/IWorldKernel.sol +++ b/packages/world/src/interfaces/IWorldKernel.sol @@ -18,7 +18,7 @@ interface IWorldCall { * Call the system at the given resourceSelector. * If the system is not public, the caller must have access to the namespace or name (encoded in the resourceSelector). */ - function call(bytes32 resourceSelector, bytes memory funcSelectorAndArgs) external payable returns (bytes memory); + function call(bytes32 resourceSelector, bytes memory callData) external payable returns (bytes memory); /** * Call the system at the given resourceSelector on behalf of the given delegator. @@ -27,7 +27,7 @@ interface IWorldCall { function callFrom( address delegator, bytes32 resourceSelector, - bytes memory funcSelectorAndArgs + bytes memory callData ) external payable returns (bytes memory); } diff --git a/packages/world/src/interfaces/IWorldRegistrationSystem.sol b/packages/world/src/interfaces/IWorldRegistrationSystem.sol index 8b319aef9a..eda464a074 100644 --- a/packages/world/src/interfaces/IWorldRegistrationSystem.sol +++ b/packages/world/src/interfaces/IWorldRegistrationSystem.sol @@ -27,9 +27,5 @@ interface IWorldRegistrationSystem { bytes4 systemFunctionSelector ) external returns (bytes4); - function registerDelegation( - address delegatee, - bytes32 delegationControlId, - bytes memory initFuncSelectorAndArgs - ) external; + function registerDelegation(address delegatee, bytes32 delegationControlId, bytes memory initCallData) external; } diff --git a/packages/world/src/modules/core/CoreModule.sol b/packages/world/src/modules/core/CoreModule.sol index a9712b4576..341e1aebeb 100644 --- a/packages/world/src/modules/core/CoreModule.sol +++ b/packages/world/src/modules/core/CoreModule.sol @@ -90,7 +90,7 @@ contract CoreModule is Module { msgSender: _msgSender(), msgValue: 0, target: coreSystem, - funcSelectorAndArgs: abi.encodeCall( + callData: abi.encodeCall( WorldRegistrationSystem.registerSystem, (ResourceSelector.from(ROOT_NAMESPACE, CORE_SYSTEM_NAME), CoreSystem(coreSystem), true) ) @@ -134,7 +134,7 @@ contract CoreModule is Module { msgSender: _msgSender(), msgValue: 0, target: coreSystem, - funcSelectorAndArgs: abi.encodeCall( + callData: abi.encodeCall( WorldRegistrationSystem.registerRootFunctionSelector, (ResourceSelector.from(ROOT_NAMESPACE, CORE_SYSTEM_NAME), functionSelectors[i], functionSelectors[i]) ) diff --git a/packages/world/src/modules/core/implementations/ModuleInstallationSystem.sol b/packages/world/src/modules/core/implementations/ModuleInstallationSystem.sol index 80a004975a..527cf62eba 100644 --- a/packages/world/src/modules/core/implementations/ModuleInstallationSystem.sol +++ b/packages/world/src/modules/core/implementations/ModuleInstallationSystem.sol @@ -24,7 +24,7 @@ contract ModuleInstallationSystem is System { msgSender: _msgSender(), msgValue: 0, target: address(module), - funcSelectorAndArgs: abi.encodeWithSelector(IModule.install.selector, args) + callData: abi.encodeWithSelector(IModule.install.selector, args) }); // Register the module in the InstalledModules table diff --git a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol b/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol index eacfff6087..eee36e25fd 100644 --- a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol +++ b/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol @@ -57,7 +57,7 @@ contract StoreRegistrationSystem is System, IWorldErrors { msgSender: _msgSender(), msgValue: 0, target: systemAddress, - funcSelectorAndArgs: abi.encodeWithSelector(WorldRegistrationSystem.registerNamespace.selector, namespace) + callData: abi.encodeWithSelector(WorldRegistrationSystem.registerNamespace.selector, namespace) }); } else { // otherwise require caller to own the namespace diff --git a/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol b/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol index 03cd41a7ec..a4d8ceea7b 100644 --- a/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol +++ b/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol @@ -202,16 +202,12 @@ contract WorldRegistrationSystem is System, IWorldErrors { /** * Register a delegation from the caller to the given delegatee. */ - function registerDelegation( - address delegatee, - bytes32 delegationControlId, - bytes memory initFuncSelectorAndArgs - ) public { + function registerDelegation(address delegatee, bytes32 delegationControlId, bytes memory initCallData) public { // Store the delegation control contract address Delegations.set({ delegator: _msgSender(), delegatee: delegatee, delegationControlId: delegationControlId }); // If the delegation is not unlimited... - if (delegationControlId != UNLIMITED_DELEGATION && initFuncSelectorAndArgs.length > 0) { + if (delegationControlId != UNLIMITED_DELEGATION && initCallData.length > 0) { // Require the delegationControl contract to implement the IDelegationControl interface (address delegationControl, ) = Systems._get(delegationControlId); requireInterface(delegationControl, DELEGATION_CONTROL_INTERFACE_ID); @@ -220,7 +216,7 @@ contract WorldRegistrationSystem is System, IWorldErrors { SystemCall.call({ caller: _msgSender(), resourceSelector: delegationControlId, - funcSelectorAndArgs: initFuncSelectorAndArgs, + callData: initCallData, value: 0 }); } diff --git a/packages/world/src/modules/std-delegations/CallboundDelegationControl.sol b/packages/world/src/modules/std-delegations/CallboundDelegationControl.sol index 66785b0bfa..fbb62081ee 100644 --- a/packages/world/src/modules/std-delegations/CallboundDelegationControl.sol +++ b/packages/world/src/modules/std-delegations/CallboundDelegationControl.sol @@ -8,15 +8,15 @@ contract CallboundDelegationControl is DelegationControl { /** * Verify a delegation by checking if the delegator has any available calls left in the CallboundDelegations table and decrementing the available calls if so. */ - function verify(address delegator, bytes32 resourceSelector, bytes memory funcSelectorAndArgs) public returns (bool) { - bytes32 funcSelectorAndArgsHash = keccak256(funcSelectorAndArgs); + function verify(address delegator, bytes32 resourceSelector, bytes memory callData) public returns (bool) { + bytes32 callDataHash = keccak256(callData); - // Get the number of available calls for the given delegator, resourceSelector and funcSelectorAndArgs + // Get the number of available calls for the given delegator, resourceSelector and callData uint256 availableCalls = CallboundDelegations.get({ delegator: delegator, delegatee: _msgSender(), resourceSelector: resourceSelector, - funcSelectorAndArgsHash: funcSelectorAndArgsHash + callDataHash: callDataHash }); if (availableCalls == 1) { @@ -25,7 +25,7 @@ contract CallboundDelegationControl is DelegationControl { delegator: delegator, delegatee: _msgSender(), resourceSelector: resourceSelector, - funcSelectorAndArgsHash: funcSelectorAndArgsHash + callDataHash: callDataHash }); return true; } @@ -39,7 +39,7 @@ contract CallboundDelegationControl is DelegationControl { delegator: delegator, delegatee: _msgSender(), resourceSelector: resourceSelector, - funcSelectorAndArgsHash: funcSelectorAndArgsHash, + callDataHash: callDataHash, availableCalls: availableCalls }); return true; @@ -51,17 +51,12 @@ contract CallboundDelegationControl is DelegationControl { /** * Initialize a delegation by setting the number of available calls in the CallboundDelegations table */ - function initDelegation( - address delegatee, - bytes32 resourceSelector, - bytes memory funcSelectorAndArgs, - uint256 numCalls - ) public { + function initDelegation(address delegatee, bytes32 resourceSelector, bytes memory callData, uint256 numCalls) public { CallboundDelegations.set({ delegator: _msgSender(), delegatee: delegatee, resourceSelector: resourceSelector, - funcSelectorAndArgsHash: keccak256(funcSelectorAndArgs), + callDataHash: keccak256(callData), availableCalls: numCalls }); } diff --git a/packages/world/src/modules/std-delegations/TimeboundDelegationControl.sol b/packages/world/src/modules/std-delegations/TimeboundDelegationControl.sol index ca792336bf..efeb00663e 100644 --- a/packages/world/src/modules/std-delegations/TimeboundDelegationControl.sol +++ b/packages/world/src/modules/std-delegations/TimeboundDelegationControl.sol @@ -7,7 +7,7 @@ import { TimeboundDelegations } from "./tables/TimeboundDelegations.sol"; contract TimeboundDelegationControl is DelegationControl { /** * Verify a delegation by checking if the current block timestamp is not larger than the max valid timestamp for the delegation. - * Note: the delegation control check ignores the resourceSelector and funcSelectorAndArgs parameters. + * Note: the delegation control check ignores the resourceSelector and callData parameters. */ function verify(address delegator, bytes32, bytes memory) public view returns (bool) { // Get the max valid timestamp for the given delegator diff --git a/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol b/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol index f36c9e45b5..69367d5c30 100644 --- a/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol +++ b/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol @@ -56,7 +56,7 @@ library CallboundDelegations { keyNames[0] = "delegator"; keyNames[1] = "delegatee"; keyNames[2] = "resourceSelector"; - keyNames[3] = "funcSelectorAndArgsHash"; + keyNames[3] = "callDataHash"; } /** Get the table's field names */ @@ -85,13 +85,13 @@ library CallboundDelegations { address delegator, address delegatee, bytes32 resourceSelector, - bytes32 funcSelectorAndArgsHash + bytes32 callDataHash ) internal view returns (uint256 availableCalls) { bytes32[] memory _keyTuple = new bytes32[](4); _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); _keyTuple[2] = resourceSelector; - _keyTuple[3] = funcSelectorAndArgsHash; + _keyTuple[3] = callDataHash; bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); return (uint256(bytes32(_blob))); @@ -102,13 +102,13 @@ library CallboundDelegations { address delegator, address delegatee, bytes32 resourceSelector, - bytes32 funcSelectorAndArgsHash + bytes32 callDataHash ) internal view returns (uint256 availableCalls) { bytes32[] memory _keyTuple = new bytes32[](4); _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); _keyTuple[2] = resourceSelector; - _keyTuple[3] = funcSelectorAndArgsHash; + _keyTuple[3] = callDataHash; bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); return (uint256(bytes32(_blob))); @@ -120,13 +120,13 @@ library CallboundDelegations { address delegator, address delegatee, bytes32 resourceSelector, - bytes32 funcSelectorAndArgsHash + bytes32 callDataHash ) internal view returns (uint256 availableCalls) { bytes32[] memory _keyTuple = new bytes32[](4); _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); _keyTuple[2] = resourceSelector; - _keyTuple[3] = funcSelectorAndArgsHash; + _keyTuple[3] = callDataHash; bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); return (uint256(bytes32(_blob))); @@ -137,14 +137,14 @@ library CallboundDelegations { address delegator, address delegatee, bytes32 resourceSelector, - bytes32 funcSelectorAndArgsHash, + bytes32 callDataHash, uint256 availableCalls ) internal { bytes32[] memory _keyTuple = new bytes32[](4); _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); _keyTuple[2] = resourceSelector; - _keyTuple[3] = funcSelectorAndArgsHash; + _keyTuple[3] = callDataHash; StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout); } @@ -154,14 +154,14 @@ library CallboundDelegations { address delegator, address delegatee, bytes32 resourceSelector, - bytes32 funcSelectorAndArgsHash, + bytes32 callDataHash, uint256 availableCalls ) internal { bytes32[] memory _keyTuple = new bytes32[](4); _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); _keyTuple[2] = resourceSelector; - _keyTuple[3] = funcSelectorAndArgsHash; + _keyTuple[3] = callDataHash; StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout); } @@ -172,14 +172,14 @@ library CallboundDelegations { address delegator, address delegatee, bytes32 resourceSelector, - bytes32 funcSelectorAndArgsHash, + bytes32 callDataHash, uint256 availableCalls ) internal { bytes32[] memory _keyTuple = new bytes32[](4); _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); _keyTuple[2] = resourceSelector; - _keyTuple[3] = funcSelectorAndArgsHash; + _keyTuple[3] = callDataHash; _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout); } @@ -204,29 +204,24 @@ library CallboundDelegations { address delegator, address delegatee, bytes32 resourceSelector, - bytes32 funcSelectorAndArgsHash + bytes32 callDataHash ) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](4); _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); _keyTuple[2] = resourceSelector; - _keyTuple[3] = funcSelectorAndArgsHash; + _keyTuple[3] = callDataHash; return _keyTuple; } /* Delete all data for given keys */ - function deleteRecord( - address delegator, - address delegatee, - bytes32 resourceSelector, - bytes32 funcSelectorAndArgsHash - ) internal { + function deleteRecord(address delegator, address delegatee, bytes32 resourceSelector, bytes32 callDataHash) internal { bytes32[] memory _keyTuple = new bytes32[](4); _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); _keyTuple[2] = resourceSelector; - _keyTuple[3] = funcSelectorAndArgsHash; + _keyTuple[3] = callDataHash; StoreSwitch.deleteRecord(_tableId, _keyTuple, _fieldLayout); } @@ -236,13 +231,13 @@ library CallboundDelegations { address delegator, address delegatee, bytes32 resourceSelector, - bytes32 funcSelectorAndArgsHash + bytes32 callDataHash ) internal { bytes32[] memory _keyTuple = new bytes32[](4); _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); _keyTuple[2] = resourceSelector; - _keyTuple[3] = funcSelectorAndArgsHash; + _keyTuple[3] = callDataHash; StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } @@ -253,13 +248,13 @@ library CallboundDelegations { address delegator, address delegatee, bytes32 resourceSelector, - bytes32 funcSelectorAndArgsHash + bytes32 callDataHash ) internal { bytes32[] memory _keyTuple = new bytes32[](4); _keyTuple[0] = bytes32(uint256(uint160(delegator))); _keyTuple[1] = bytes32(uint256(uint160(delegatee))); _keyTuple[2] = resourceSelector; - _keyTuple[3] = funcSelectorAndArgsHash; + _keyTuple[3] = callDataHash; _store.deleteRecord(_tableId, _keyTuple, _fieldLayout); } diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index e1129733e0..7cf3111d2c 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -136,12 +136,12 @@ contract PayableFallbackSystem is System { contract EchoSystemHook is SystemHook { event SystemHookCalled(bytes data); - function onBeforeCallSystem(address msgSender, bytes32 resourceSelector, bytes memory funcSelectorAndArgs) public { - emit SystemHookCalled(abi.encode("before", msgSender, resourceSelector, funcSelectorAndArgs)); + function onBeforeCallSystem(address msgSender, bytes32 resourceSelector, bytes memory callData) public { + emit SystemHookCalled(abi.encode("before", msgSender, resourceSelector, callData)); } - function onAfterCallSystem(address msgSender, bytes32 resourceSelector, bytes memory funcSelectorAndArgs) public { - emit SystemHookCalled(abi.encode("after", msgSender, resourceSelector, funcSelectorAndArgs)); + function onAfterCallSystem(address msgSender, bytes32 resourceSelector, bytes memory callData) public { + emit SystemHookCalled(abi.encode("after", msgSender, resourceSelector, callData)); } } @@ -738,7 +738,7 @@ contract WorldTest is Test, GasReporter { WorldTestSystem.delegateCallSubSystem.selector, // Function in system address(subSystem), // Address of subsystem WorldContextProvider.appendContext({ - funcSelectorAndArgs: abi.encodeWithSelector(WorldTestSystem.msgSender.selector), + callData: abi.encodeWithSelector(WorldTestSystem.msgSender.selector), msgSender: address(this), msgValue: uint256(0) }) @@ -1005,20 +1005,20 @@ contract WorldTest is Test, GasReporter { ISystemHook systemHook = new EchoSystemHook(); world.registerSystemHook(systemId, systemHook, BEFORE_CALL_SYSTEM | AFTER_CALL_SYSTEM); - bytes memory funcSelectorAndArgs = abi.encodeWithSelector(bytes4(keccak256("fallbackselector"))); + bytes memory callData = abi.encodeWithSelector(bytes4(keccak256("fallbackselector"))); // Expect the hooks to be called in correct order vm.expectEmit(true, true, true, true); - emit SystemHookCalled(abi.encode("before", address(this), systemId, funcSelectorAndArgs)); + emit SystemHookCalled(abi.encode("before", address(this), systemId, callData)); vm.expectEmit(true, true, true, true); emit WorldTestSystemLog("fallback"); vm.expectEmit(true, true, true, true); - emit SystemHookCalled(abi.encode("after", address(this), systemId, funcSelectorAndArgs)); + emit SystemHookCalled(abi.encode("after", address(this), systemId, callData)); // Call a system fallback function without arguments via the World - world.call(systemId, funcSelectorAndArgs); + world.call(systemId, callData); } function testUnregisterSystemHook() public { @@ -1036,27 +1036,27 @@ contract WorldTest is Test, GasReporter { ISystemHook echoSystemHook = new EchoSystemHook(); world.registerSystemHook(systemId, echoSystemHook, BEFORE_CALL_SYSTEM | AFTER_CALL_SYSTEM); - bytes memory funcSelectorAndArgs = abi.encodeWithSelector(bytes4(keccak256("fallbackselector"))); + bytes memory callData = abi.encodeWithSelector(bytes4(keccak256("fallbackselector"))); // Expect calls to fail while the RevertSystemHook is registered vm.expectRevert(bytes("onBeforeCallSystem")); - world.call(systemId, funcSelectorAndArgs); + world.call(systemId, callData); // Unregister the RevertSystemHook world.unregisterSystemHook(systemId, revertSystemHook); // Expect the echo hooks to be called in correct order vm.expectEmit(true, true, true, true); - emit SystemHookCalled(abi.encode("before", address(this), systemId, funcSelectorAndArgs)); + emit SystemHookCalled(abi.encode("before", address(this), systemId, callData)); vm.expectEmit(true, true, true, true); emit WorldTestSystemLog("fallback"); vm.expectEmit(true, true, true, true); - emit SystemHookCalled(abi.encode("after", address(this), systemId, funcSelectorAndArgs)); + emit SystemHookCalled(abi.encode("after", address(this), systemId, callData)); // Call a system fallback function without arguments via the World - world.call(systemId, funcSelectorAndArgs); + world.call(systemId, callData); } function testWriteRootSystem() public { diff --git a/packages/world/test/WorldContext.t.sol b/packages/world/test/WorldContext.t.sol index 4ba6fb2454..174c90bfd3 100644 --- a/packages/world/test/WorldContext.t.sol +++ b/packages/world/test/WorldContext.t.sol @@ -18,10 +18,10 @@ contract WorldContextTest is Test, GasReporter { TestContextConsumer public consumer = new TestContextConsumer(); - function testFuzzAppendContext(bytes memory funcSelectorAndArgs, address msgSender, uint256 msgValue) public { + function testFuzzAppendContext(bytes memory callData, address msgSender, uint256 msgValue) public { assertEq( - keccak256(abi.encodePacked(funcSelectorAndArgs, msgSender, msgValue)), - keccak256(WorldContextProvider.appendContext(funcSelectorAndArgs, msgSender, msgValue)) + keccak256(abi.encodePacked(callData, msgSender, msgValue)), + keccak256(WorldContextProvider.appendContext(callData, msgSender, msgValue)) ); } @@ -34,7 +34,7 @@ contract WorldContextTest is Test, GasReporter { msgSender: msgSender, msgValue: msgValue, target: address(consumer), - funcSelectorAndArgs: abi.encodeWithSelector(TestContextConsumer.emitContext.selector, args) + callData: abi.encodeWithSelector(TestContextConsumer.emitContext.selector, args) }); } @@ -47,7 +47,7 @@ contract WorldContextTest is Test, GasReporter { msgSender: msgSender, msgValue: msgValue, target: address(consumer), - funcSelectorAndArgs: abi.encodeWithSelector(TestContextConsumer.emitContext.selector, args) + callData: abi.encodeWithSelector(TestContextConsumer.emitContext.selector, args) }); } }