SafeTxShapeHelpers
Inherits: Assertion
Title: SafeTxShapeHelpers
Author: Phylax Systems
Shared decoding and policy helpers for Safe transaction-shape assertions.
Constants
OPERATION_CALL
uint8 internal constant OPERATION_CALL = 0
OPERATION_DELEGATECALL
uint8 internal constant OPERATION_DELEGATECALL = 1
APPROVAL_KIND_ERC20_APPROVE
uint8 public constant APPROVAL_KIND_ERC20_APPROVE = 1
APPROVAL_KIND_ERC20_INCREASE_ALLOWANCE
uint8 public constant APPROVAL_KIND_ERC20_INCREASE_ALLOWANCE = 2
APPROVAL_KIND_ERC721_APPROVE
uint8 public constant APPROVAL_KIND_ERC721_APPROVE = 3
APPROVAL_KIND_ERC721_SET_APPROVAL_FOR_ALL
uint8 public constant APPROVAL_KIND_ERC721_SET_APPROVAL_FOR_ALL = 4
APPROVAL_KIND_ERC1155_SET_APPROVAL_FOR_ALL
uint8 public constant APPROVAL_KIND_ERC1155_SET_APPROVAL_FOR_ALL = 5
EXEC_TRANSACTION_SELECTOR
bytes4 public constant EXEC_TRANSACTION_SELECTOR =
bytes4(keccak256("execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes)"))
EXEC_TRANSACTION_FROM_MODULE_SELECTOR
bytes4 public constant EXEC_TRANSACTION_FROM_MODULE_SELECTOR =
bytes4(keccak256("execTransactionFromModule(address,uint256,bytes,uint8)"))
EXEC_TRANSACTION_FROM_MODULE_RETURN_DATA_SELECTOR
bytes4 public constant EXEC_TRANSACTION_FROM_MODULE_RETURN_DATA_SELECTOR =
bytes4(keccak256("execTransactionFromModuleReturnData(address,uint256,bytes,uint8)"))
MULTISEND_SELECTOR
bytes4 public constant MULTISEND_SELECTOR = bytes4(keccak256("multiSend(bytes)"))
APPROVE_SELECTOR
bytes4 public constant APPROVE_SELECTOR = bytes4(keccak256("approve(address,uint256)"))
INCREASE_ALLOWANCE_SELECTOR
bytes4 public constant INCREASE_ALLOWANCE_SELECTOR = bytes4(keccak256("increaseAllowance(address,uint256)"))
SET_APPROVAL_FOR_ALL_SELECTOR
bytes4 public constant SET_APPROVAL_FOR_ALL_SELECTOR = bytes4(keccak256("setApprovalForAll(address,bool)"))
MULTISEND_HEADER_LENGTH
uint256 internal constant MULTISEND_HEADER_LENGTH = 85
ALLOWANCE_READ_GAS
uint64 internal constant ALLOWANCE_READ_GAS = 500_000
moduleExecutionEnabled
bool public immutable moduleExecutionEnabled
State Variables
targetPolicies
TargetPolicy[] public targetPolicies
selectorPolicies
SelectorPolicy[] public selectorPolicies
batchExecutorPolicies
BatchExecutorPolicy[] public batchExecutorPolicies
approvalPolicies
ApprovalPolicy[] public approvalPolicies
allowedModules
address[] public allowedModules
_targetPolicyIndexPlusOne
mapping(address target => uint256 indexPlusOne) internal _targetPolicyIndexPlusOne
_selectorPolicyIndexPlusOne
mapping(address target => mapping(bytes4 selector => uint256 indexPlusOne)) internal _selectorPolicyIndexPlusOne
_batchPolicyIndexPlusOne
mapping(address executor => mapping(bytes4 selector => uint256 indexPlusOne)) internal _batchPolicyIndexPlusOne
_approvalPolicyByKey
mapping(address token => mapping(address spender => mapping(uint8 kind => ApprovalPolicy))) internal
_approvalPolicyByKey
_approvalPolicyExists
mapping(address token => mapping(address spender => mapping(uint8 kind => bool))) internal _approvalPolicyExists
_tokenApprovalKindRegistered
mapping(address token => mapping(uint8 kind => bool)) internal _tokenApprovalKindRegistered
_allowedModule
mapping(address module => bool allowed) internal _allowedModule
Functions
constructor
constructor(
TargetPolicy[] memory targetPolicies_,
SelectorPolicy[] memory selectorPolicies_,
BatchExecutorPolicy[] memory batchExecutorPolicies_,
ApprovalPolicy[] memory approvalPolicies_,
bool moduleExecutionEnabled_,
address[] memory allowedModules_
) ;
targetPolicyCount
function targetPolicyCount() external view returns (uint256);
selectorPolicyCount
function selectorPolicyCount() external view returns (uint256);
batchExecutorPolicyCount
function batchExecutorPolicyCount() external view returns (uint256);
approvalPolicyCount
function approvalPolicyCount() external view returns (uint256);
allowedModuleCount
function allowedModuleCount() external view returns (uint256);
_triggeredAction
function _triggeredAction() internal view returns (Action memory action);
_validateInnerDelegateCallPolicy
function _validateInnerDelegateCallPolicy(Action memory action) internal pure;
_validateInnerTargetSelectorPolicy
function _validateInnerTargetSelectorPolicy(Action memory action) internal view;
_validateInnerApprovalPolicy
function _validateInnerApprovalPolicy(Action memory action) internal view;
_validateMultiSendDelegateCallPolicy
function _validateMultiSendDelegateCallPolicy(Action memory action, BatchExecutorPolicy storage batchPolicy)
internal
view;
_validateMultiSendTargetSelectorPolicy
function _validateMultiSendTargetSelectorPolicy(Action memory action, BatchExecutorPolicy storage batchPolicy)
internal
view;
_validateMultiSendBatchPolicy
function _validateMultiSendBatchPolicy(Action memory action, BatchExecutorPolicy storage batchPolicy)
internal
view;
_validateMultiSendApprovalPolicy
function _validateMultiSendApprovalPolicy(Action memory action, BatchExecutorPolicy storage batchPolicy)
internal
view;
_multiSendTransactions
function _multiSendTransactions(Action memory action, BatchExecutorPolicy storage batchPolicy)
internal
view
returns (uint256 transactionsOffset, uint256 transactionsLength);
_readMultiSendAction
function _readMultiSendAction(
Action memory parent,
uint256 transactionsOffset,
uint256 transactionsLength,
uint256 offset
) internal pure returns (Action memory innerAction, uint256 nextOffset);
_validateTargetAndSelector
function _validateTargetAndSelector(Action memory action) internal view returns (bytes4 selector);
_validateApproval
function _validateApproval(Action memory action, bytes4 selector) internal view;
_validateNumericApproval
function _validateNumericApproval(address token, address spender, uint8 kind, uint256 amount) internal view;
_validateIncreaseAllowanceFinalState
function _validateIncreaseAllowanceFinalState(address safe, address token, address spender) internal view;
_validateOperatorApproval
function _validateOperatorApproval(address token, address operator, uint8 kind) internal view;
_operatorApprovalAllowed
function _operatorApprovalAllowed(address token, address operator, uint8 kind) internal view returns (bool);
_validateModuleCaller
function _validateModuleCaller(address module) internal view;
_resolveTriggeredSafeCall
function _resolveTriggeredSafeCall() internal view returns (TriggeredSafeCall memory triggered);
_decodeOwnerTx
function _decodeOwnerTx(bytes memory input) internal pure returns (OwnerTx memory ownerTx);
_decodeModuleTx
function _decodeModuleTx(bytes memory input) internal pure returns (ModuleTx memory moduleTx);
_decodeOwnerAction
function _decodeOwnerAction(address safe, bytes memory input) internal pure returns (Action memory action);
_decodeModuleAction
function _decodeModuleAction(address safe, address module, bytes memory input)
internal
pure
returns (Action memory action);
_decodeSingleBytesArgument
function _decodeSingleBytesArgument(
bytes memory input,
uint256 inputOffset,
uint256 inputLength,
bytes4 expectedSelector
) internal pure returns (uint256 argumentOffset, uint256 argumentLength);
_batchPolicyForAction
function _batchPolicyForAction(address target, bytes memory data, uint256 dataOffset, uint256 dataLength)
internal
view
returns (bool found, uint256 index);
_isConfiguredBatchCall
function _isConfiguredBatchCall(address target, bytes memory data, uint256 dataOffset, uint256 dataLength)
internal
view
returns (bool);
_targetPolicyIndex
function _targetPolicyIndex(address target) internal view returns (bool found, uint256 index);
_selectorPolicyIndex
function _selectorPolicyIndex(address target, bytes4 selector) internal view returns (bool found, uint256 index);
_batchPolicyIndex
function _batchPolicyIndex(address executor, bytes4 selector) internal view returns (bool found, uint256 index);
_tokenHasApprovalKind
function _tokenHasApprovalKind(address token, uint8 kind) internal view returns (bool);
_storeTargetPolicies
function _storeTargetPolicies(TargetPolicy[] memory policies) private;
_storeSelectorPolicies
function _storeSelectorPolicies(SelectorPolicy[] memory policies) private;
_storeBatchExecutorPolicies
function _storeBatchExecutorPolicies(BatchExecutorPolicy[] memory policies) private;
_storeApprovalPolicies
function _storeApprovalPolicies(ApprovalPolicy[] memory policies) private;
_storeAllowedModules
function _storeAllowedModules(address[] memory modules) private;
_targetPolicyExistsInMemory
function _targetPolicyExistsInMemory(address target) private view returns (bool);
_isSupportedApprovalKind
function _isSupportedApprovalKind(uint8 kind) private pure returns (bool);
_registerReshiramSpec
function _registerReshiramSpec() internal;
_stripSelector
function _stripSelector(bytes memory input) internal pure returns (bytes memory args);
_selector
function _selector(bytes memory input) internal pure returns (bytes4 selector);
_selectorAt
function _selectorAt(bytes memory input, uint256 offset) internal pure returns (bytes4 selector);
_readAbiAddress
function _readAbiAddress(bytes memory data, uint256 offset) internal pure returns (address value);
_readAbiUint8
function _readAbiUint8(bytes memory data, uint256 offset) internal pure returns (uint8 value);
_readAbiBool
function _readAbiBool(bytes memory data, uint256 offset) internal pure returns (bool value);
_readDynamicBytes
function _readDynamicBytes(bytes memory data, uint256 headStart, uint256 relativeOffset)
internal
pure
returns (bytes memory value);
_dynamicBytesBounds
function _dynamicBytesBounds(bytes memory data, uint256 headStart, uint256 relativeOffset)
internal
pure
returns (uint256 valueOffset, uint256 valueLength);
_readPackedAddress
function _readPackedAddress(bytes memory data, uint256 offset) internal pure returns (address value);
_readUint256
function _readUint256(bytes memory data, uint256 offset) internal pure returns (uint256 value);
_slice
function _slice(bytes memory data, uint256 offset, uint256 length) internal pure returns (bytes memory out);
Errors
SafeTxShapeDuplicateTarget
error SafeTxShapeDuplicateTarget(address target);
SafeTxShapeDuplicateSelector
error SafeTxShapeDuplicateSelector(address target, bytes4 selector);
SafeTxShapeDuplicateBatchExecutor
error SafeTxShapeDuplicateBatchExecutor(address executor, bytes4 selector);
SafeTxShapeDuplicateApprovalPolicy
error SafeTxShapeDuplicateApprovalPolicy(address token, address spender, uint8 kind);
SafeTxShapeDuplicateModule
error SafeTxShapeDuplicateModule(address module);
SafeTxShapeInvalidPolicy
error SafeTxShapeInvalidPolicy();
SafeTxShapeTriggeredCallNotFound
error SafeTxShapeTriggeredCallNotFound(bytes4 selector, uint256 callStart);
SafeTxShapeUnsupportedEntrypoint
error SafeTxShapeUnsupportedEntrypoint(bytes4 selector);
SafeTxShapeModuleExecutionDisabled
error SafeTxShapeModuleExecutionDisabled(address module);
SafeTxShapeModuleNotAllowed
error SafeTxShapeModuleNotAllowed(address module);
SafeTxShapeUnknownOperation
error SafeTxShapeUnknownOperation(uint8 operation);
SafeTxShapeDelegateCallBlocked
error SafeTxShapeDelegateCallBlocked(address target);
SafeTxShapeInnerDelegateCallBlocked
error SafeTxShapeInnerDelegateCallBlocked(address target);
SafeTxShapeUnknownTarget
error SafeTxShapeUnknownTarget(address target);
SafeTxShapeSelectorNotAllowed
error SafeTxShapeSelectorNotAllowed(address target, bytes4 selector);
SafeTxShapeCalldataTooShort
error SafeTxShapeCalldataTooShort(address target, uint256 length);
SafeTxShapeEmptyCalldataBlocked
error SafeTxShapeEmptyCalldataBlocked(address target);
SafeTxShapeFallbackCalldataBlocked
error SafeTxShapeFallbackCalldataBlocked(address target, uint256 length);
SafeTxShapeNativeValueBlocked
error SafeTxShapeNativeValueBlocked(address target, bytes4 selector, uint256 value);
SafeTxShapeBatchDelegateCallNotAllowed
error SafeTxShapeBatchDelegateCallNotAllowed(address executor);
SafeTxShapeBatchPayloadMalformed
error SafeTxShapeBatchPayloadMalformed();
SafeTxShapeBatchTooManyActions
error SafeTxShapeBatchTooManyActions(uint256 maxActions);
SafeTxShapeNestedBatchBlocked
error SafeTxShapeNestedBatchBlocked(address executor);
SafeTxShapeApprovalMalformed
error SafeTxShapeApprovalMalformed(address token, bytes4 selector);
SafeTxShapeApprovalTokenUnconfigured
error SafeTxShapeApprovalTokenUnconfigured(address token, bytes4 selector);
SafeTxShapeApprovalSpenderNotAllowed
error SafeTxShapeApprovalSpenderNotAllowed(address token, address spender, uint8 kind);
SafeTxShapeApprovalUnlimitedBlocked
error SafeTxShapeApprovalUnlimitedBlocked(address token, address spender, uint8 kind);
SafeTxShapeApprovalAmountAboveCap
error SafeTxShapeApprovalAmountAboveCap(
address token, address spender, uint8 kind, uint256 amount, uint256 maxAmount
);
SafeTxShapeAllowanceReadFailed
error SafeTxShapeAllowanceReadFailed(address token, address spender);
Structs
TargetPolicy
struct TargetPolicy {
address target;
bool allowAnySelector;
bool allowEmptyCalldata;
bool allowFallbackCalldata;
bool allowNonzeroValue;
}
SelectorPolicy
struct SelectorPolicy {
address target;
bytes4 selector;
bool allowNonzeroValue;
}
BatchExecutorPolicy
struct BatchExecutorPolicy {
address executor;
bytes4 selector;
bool allowDelegateCall;
uint256 maxActions;
bool allowNested;
}
ApprovalPolicy
struct ApprovalPolicy {
address token;
address spender;
uint8 kind;
uint256 maxAmount;
bool allowUnlimited;
}
TriggeredSafeCall
struct TriggeredSafeCall {
bytes4 selector;
address caller;
bytes input;
uint256 callStart;
uint256 callEnd;
}
OwnerTx
struct OwnerTx {
address to;
uint256 value;
bytes data;
uint8 operation;
}
ModuleTx
struct ModuleTx {
address to;
uint256 value;
bytes data;
uint8 operation;
}
Action
struct Action {
address safe;
address module;
address target;
uint256 value;
bytes data;
uint256 dataOffset;
uint256 dataLength;
uint8 operation;
bool fromModule;
bool fromBatch;
}