diff --git a/docs/SigningUtils.md b/docs/SigningUtils.md index 4e02294..b2930a5 100644 --- a/docs/SigningUtils.md +++ b/docs/SigningUtils.md @@ -24,44 +24,4 @@ struct Transaction { bytes signatures; } ``` -### _hashTypedDataV4 - -```solidity -function _hashTypedDataV4(bytes32 domainSeparator, bytes32 structHash) internal view virtual returns (bytes32) -``` - -_Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this -function returns the hash of the fully encoded EIP712 message for this domain. - -This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: - -```solidity -bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( - keccak256("Mail(address to,string contents)"), - mailTo, - keccak256(bytes(mailContents)) -))); -address signer = ECDSA.recover(digest, signature); -```_ - -### createDigestExecTx - -```solidity -function createDigestExecTx(bytes32 domainSeparatorSafe, struct SigningUtils.Transaction safeTx) public view returns (bytes32) -``` - -_Given a transaction, it creates a hash of the transaction that can be signed_ - -#### Parameters - -| Name | Type | Description | -| ---- | ---- | ----------- | -| domainSeparatorSafe | bytes32 | Hash of the Safe domain separator | -| safeTx | struct SigningUtils.Transaction | Safe transaction | - -#### Return Values - -| Name | Type | Description | -| ---- | ---- | ----------- | -| [0] | bytes32 | Hash of the transaction | diff --git a/src/DenyHelper.sol b/src/DenyHelper.sol index d9d3d40..9cf6ffd 100644 --- a/src/DenyHelper.sol +++ b/src/DenyHelper.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: LGPL-3.0-only pragma solidity 0.8.23; -import {GnosisSafeMath} from "@safe-contracts/external/GnosisSafeMath.sol"; import {Address} from "@openzeppelin/utils/Address.sol"; import {Context} from "@openzeppelin/utils/Context.sol"; import {Constants} from "./libraries/Constants.sol"; @@ -27,7 +26,6 @@ abstract contract ValidAddress is Context { /// @notice Deny Helpers Methods for the Palmera module /// @dev RDeny Helper Palmera Modules abstract contract DenyHelper is ValidAddress { - using GnosisSafeMath for uint256; using Address for address; /// @dev Deny/Allowlist Flags by Org diff --git a/src/Helpers.sol b/src/Helpers.sol index c3c2fba..4ae368f 100644 --- a/src/Helpers.sol +++ b/src/Helpers.sol @@ -8,7 +8,6 @@ import { DenyHelper, Address, Context, - GnosisSafeMath, Constants, DataTypes, Errors, @@ -24,7 +23,6 @@ import {ReentrancyGuard} from "@openzeppelin/security/ReentrancyGuard.sol"; /// @notice This contract is a helper contract for the Palmera Module /// @dev Helper Methods for the Palmera module abstract contract Helpers is DenyHelper, SignatureDecoder, ReentrancyGuard { - using GnosisSafeMath for uint256; using Address for address; /// @dev Modifier for Validate if the address is a Safe Smart Account Wallet @@ -43,7 +41,9 @@ abstract contract Helpers is DenyHelper, SignatureDecoder, ReentrancyGuard { /// @return Hash of the domain separator function domainSeparator() public view returns (bytes32) { return keccak256( - abi.encode(Constants.DOMAIN_SEPARATOR_TYPEHASH, getChainId(), this) + abi.encode( + Constants.DOMAIN_SEPARATOR_TYPEHASH, getChainId(), address(this) + ) ); } diff --git a/src/PalmeraModule.sol b/src/PalmeraModule.sol index 099d9c1..ac5035f 100644 --- a/src/PalmeraModule.sol +++ b/src/PalmeraModule.sol @@ -11,7 +11,6 @@ import { DataTypes, Events, Address, - GnosisSafeMath, Enum, ISafe } from "./Helpers.sol"; @@ -19,7 +18,6 @@ import { /// @title Palmera Module /// @custom:security-contact general@palmeradao.xyz contract PalmeraModule is Auth, Helpers { - using GnosisSafeMath for uint256; using Address for address; /// @dev Definition of Safe Palmera Module @@ -334,8 +332,6 @@ contract PalmeraModule is Auth, Helpers { bytes32 org = getOrgHashBySafe(caller); uint256 newIndex = indexId; safeId = _createOrgOrRoot(name, caller, newRootSafe); - // Setting level by default - depthTreeLimit[org] = 8; emit Events.RootSafeCreated(org, newIndex, caller, newRootSafe, name); } @@ -384,7 +380,7 @@ contract PalmeraModule is Auth, Helpers { !_authority.doesUserHaveRole( superSafeOrgSafe.safe, uint8(DataTypes.Role.SUPER_SAFE) ) - ) && (superSafeOrgSafe.child.length > 0) + ) && (superSafeOrgSafe.child.length != 0) ) { _authority.setUserRole( superSafeOrgSafe.safe, uint8(DataTypes.Role.SUPER_SAFE), true @@ -423,7 +419,7 @@ contract PalmeraModule is Auth, Helpers { // Check if the safe is Root Safe and has child if ( ((_safe.tier == DataTypes.Tier.ROOT) || (_safe.superSafe == 0)) - && (_safe.child.length > 0) + && (_safe.child.length != 0) ) { revert Errors.CannotRemoveSafeBeforeRemoveChild(_safe.child.length); } @@ -727,7 +723,7 @@ contract PalmeraModule is Auth, Helpers { address prevUser = getPrevUser(org, user); listed[org][prevUser] = listed[org][user]; listed[org][user] = address(0); - listCount[org] = listCount[org] > 1 ? listCount[org].sub(1) : 0; + listCount[org] = listCount[org] > 1 ? (listCount[org] - 1) : 0; emit Events.DroppedFromList(user); } @@ -967,9 +963,10 @@ contract PalmeraModule is Auth, Helpers { revert Errors.OrgNotRegistered(org); } /// Check if the Safe address is into an Safe mapping - for (uint256 i; i < indexSafe[org].length;) { - if (safes[org][indexSafe[org][i]].safe == safe) { - return indexSafe[org][i]; + uint256[] memory indexSafeOrg = indexSafe[org]; + for (uint256 i; i < indexSafeOrg.length;) { + if (safes[org][indexSafeOrg[i]].safe == safe) { + return indexSafeOrg[i]; } unchecked { ++i; @@ -1118,10 +1115,11 @@ contract PalmeraModule is Auth, Helpers { /// @param org ID's of the organisation /// @param safeId uint256 of the safe function removeIndexSafe(bytes32 org, uint256 safeId) private { - for (uint256 i; i < indexSafe[org].length;) { - if (indexSafe[org][i] == safeId) { - indexSafe[org][i] = indexSafe[org][indexSafe[org].length - 1]; - indexSafe[org].pop(); + uint256[] storage indexSafeOrg = indexSafe[org]; + for (uint256 i; i < indexSafeOrg.length;) { + if (indexSafeOrg[i] == safeId) { + indexSafeOrg[i] = indexSafeOrg[indexSafeOrg.length - 1]; + indexSafeOrg.pop(); break; } unchecked { diff --git a/src/SigningUtils.sol b/src/SigningUtils.sol index ff2380d..003afc1 100644 --- a/src/SigningUtils.sol +++ b/src/SigningUtils.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: LGPL-3.0-only pragma solidity 0.8.23; -import {ECDSA} from "@openzeppelin/utils/cryptography/ECDSA.sol"; import {Enum} from "@safe-contracts/base/Executor.sol"; /// @title SigningUtils @@ -20,62 +19,4 @@ abstract contract SigningUtils { address refundReceiver; bytes signatures; } - - /** - * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this - * function returns the hash of the fully encoded EIP712 message for this domain. - * - * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: - * - * ```solidity - * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( - * keccak256("Mail(address to,string contents)"), - * mailTo, - * keccak256(bytes(mailContents)) - * ))); - * address signer = ECDSA.recover(digest, signature); - * ``` - */ - function _hashTypedDataV4(bytes32 domainSeparator, bytes32 structHash) - internal - view - virtual - returns (bytes32) - { - return ECDSA.toTypedDataHash(domainSeparator, structHash); - } - - /** - * @dev Given a transaction, it creates a hash of the transaction that can be signed - * @param domainSeparatorSafe Hash of the Safe domain separator - * @param safeTx Safe transaction - * @return Hash of the transaction - */ - function createDigestExecTx( - bytes32 domainSeparatorSafe, - Transaction memory safeTx - ) public view returns (bytes32) { - bytes32 digest = _hashTypedDataV4( - domainSeparatorSafe, - keccak256( - abi.encode( - keccak256( - "execTransaction(address to,uint256 value,bytes data,Enum.Operation operation,uint256 safeTxGas,uint256 baseGas,uint256 gasPrice,address gasToken,address refundReceiver,bytes signatures)" - ), - safeTx.to, - safeTx.value, - safeTx.data, - safeTx.operation, - safeTx.safeTxGas, - safeTx.baseGas, - safeTx.gasPrice, - safeTx.gasToken, - safeTx.refundReceiver, - safeTx.signatures - ) - ) - ); - - return digest; - } }