Skip to content

Commit

Permalink
feat(invoice-module): check for non-zero 'Container' code size and up…
Browse files Browse the repository at this point in the history
…date 'Errors'
  • Loading branch information
gabrielstoica committed Jul 8, 2024
1 parent 4b96426 commit 7d8d28b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/modules/invoice-module/InvoiceModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ contract InvoiceModule is IInvoiceModule {

/// @dev Allow only calls from contracts implementing the {IContainer} interface
modifier onlyContainer() {
// Checks: the sender is a valid non-zero code size contract
if (msg.sender.code.length == 0) {
revert Errors.ContainerZeroCodeSize();
}

// Checks: the sender implements the ERC-165 interface required by {IContainer}
bytes4 interfaceId = type(IContainer).interfaceId;
if (!IERC165(msg.sender).supportsInterface(interfaceId)) revert Errors.NotContainer();
if (!IERC165(msg.sender).supportsInterface(interfaceId)) revert Errors.ContainerUnsupportedInterface();
_;
}

Expand Down
3 changes: 2 additions & 1 deletion src/modules/invoice-module/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Types } from "./Types.sol";
/// @title Errors
/// @notice Library containing all custom errors the {InvoiceModule} may revert with
library Errors {
error NotContainer();
error ContainerZeroCodeSize();
error ContainerUnsupportedInterface();
error InvalidPayer();
error InvalidOrExpiredInvoice();
error EndTimeLowerThanCurrentTime();
Expand Down

0 comments on commit 7d8d28b

Please sign in to comment.