diff --git a/packages/contracts/src/OnlyPluginUpgraderCondition.sol b/packages/contracts/src/OnlyPluginUpgraderCondition.sol index 443ef90..9446c20 100644 --- a/packages/contracts/src/OnlyPluginUpgraderCondition.sol +++ b/packages/contracts/src/OnlyPluginUpgraderCondition.sol @@ -101,12 +101,26 @@ contract OnlyPluginUpgraderCondition is PermissionCondition { function decodeApplyUpdateCalldata( bytes memory _data - ) public pure returns (bytes4 selector, address daoAddress) { + ) public pure returns (bytes4 selector, address daoAddress, address targetPluginAddress) { // Slicing is only supported for bytes calldata, not bytes memory // Bytes memory requires an assembly block assembly { - selector := mload(add(_data, 0x20)) // 32 - daoAddress := mload(add(_data, 0x24)) // 32 + 4 + selector := mload(add(_data, 0x20)) + + let _payloadStart := add(_data, 0x24) + daoAddress := mload(_payloadStart) + + let _paramsStructOffset := mload(add(_payloadStart, 0x20)) + + // Extracting the first field of the struct at offset 0 + // struct ApplyUpdateParams { + // address plugin; + // PluginSetupRef pluginSetupRef; + // bytes initData; + // PermissionLib.MultiTargetPermission[] permissions; + // bytes32 helpersHash; + // } + targetPluginAddress := mload(add(_payloadStart, _paramsStructOffset)) } } @@ -149,11 +163,13 @@ contract OnlyPluginUpgraderCondition is PermissionCondition { } function isValidApplyUpdateCalldata(bytes memory _data) private view returns (bool) { - (bytes4 _selector, address _dao) = decodeApplyUpdateCalldata(_data); + (bytes4 _selector, address _dao, address _targetPluginAddress) = decodeApplyUpdateCalldata( + _data + ); if (_selector != PluginSetupProcessor.applyUpdate.selector) return false; else if (_dao != dao) return false; - // else if (!allowedPluginAddresses[_applyParams.plugin]) return false; + else if (!allowedPluginAddresses[_targetPluginAddress]) return false; return true; } diff --git a/packages/contracts/test/unit-testing/only-plugin-upgrader-condition.ts b/packages/contracts/test/unit-testing/only-plugin-upgrader-condition.ts index 43512b8..611bbaf 100644 --- a/packages/contracts/test/unit-testing/only-plugin-upgrader-condition.ts +++ b/packages/contracts/test/unit-testing/only-plugin-upgrader-condition.ts @@ -1273,6 +1273,9 @@ describe('Only Plugin Upgrader Condition', function () { it('Should decode decodeApplyUpdateCalldata properly', async () => { applyUpdateParams.plugin = bob.address; + const applyUpdateParams2 = JSON.parse(JSON.stringify(applyUpdateParams)); + applyUpdateParams2.plugin = alice.address; + const calldataList = [ pspInterface.encodeFunctionData('applyUpdate', [ dao.address, @@ -1280,25 +1283,27 @@ describe('Only Plugin Upgrader Condition', function () { ]), pspInterface.encodeFunctionData('applyUpdate', [ ADDRESS_THREE, - applyUpdateParams, + applyUpdateParams2, ]), ]; // 1 - let [selector, decodedDaoAddress] = + let [selector, decodedDaoAddress, pluginAddress] = await onlyPluginUpgraderCondition.decodeApplyUpdateCalldata( calldataList[0] ); expect(selector).to.eq(calldataList[0].slice(0, 10)); expect(decodedDaoAddress).to.eq(dao.address); + expect(pluginAddress).to.eq(bob.address); // 2 - [selector, decodedDaoAddress] = + [selector, decodedDaoAddress, pluginAddress] = await onlyPluginUpgraderCondition.decodeApplyUpdateCalldata( calldataList[1] ); expect(selector).to.eq(calldataList[1].slice(0, 10)); expect(decodedDaoAddress).to.eq(ADDRESS_THREE); + expect(pluginAddress).to.eq(alice.address); }); }); });