Skip to content

Commit 137dd04

Browse files
committed
refactor: update delegatecall usage for safety and clarify function documentation
1 parent 0e656ee commit 137dd04

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

contracts/facets/IexecEscrowTokenFacet.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, FacetBase
148148
if (requestorder.requester != sender) revert("caller-must-be-requester");
149149

150150
// Call matchOrders on the IexecPoco1 facet through the diamond
151-
// Using delegatecall pattern via address(this)
152-
(bool success, bytes memory result) = address(this).call(
151+
// Using delegatecall for safety: preserves msg.sender context
152+
// Note: matchOrders doesn't use msg.sender, but delegatecall is safer
153+
// in case the implementation changes in the future
154+
(bool success, bytes memory result) = address(this).delegatecall(
153155
abi.encodeWithSelector(
154156
IexecPoco1.matchOrders.selector,
155157
apporder,

contracts/facets/IexecPoco1Facet.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ contract IexecPoco1Facet is
140140
/**
141141
* Match orders. The requester gets debited.
142142
*
143+
* @notice This function does not use `msg.sender` to determine who pays for the deal.
144+
* The sponsor is always set to `_requestorder.requester`, regardless of who calls this function.
145+
* This design allows the function to be safely called via delegatecall from other facets
146+
* (e.g., IexecEscrowTokenFacet.receiveApproval) without security concerns.
147+
*
143148
* @param _apporder The app order.
144149
* @param _datasetorder The dataset order.
145150
* @param _workerpoolorder The workerpool order.

0 commit comments

Comments
 (0)