Skip to content

Conversation

@gfournierPro
Copy link
Contributor

@gfournierPro gfournierPro commented Nov 12, 2025

gas cost from 852719 -> 849967 = - 2 752

The comment on line 179-181 states 'We only need to check requestorder.requester', but this approach still decodes all four order structs (consuming gas for all of them). Consider adding a note about the gas trade-off or exploring if there's a more efficient way to decode only the request order if optimization is important.

when we will support sponsor MatchOrder the check won't be needed

Copilot AI review requested due to automatic review settings November 12, 2025 12:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the receiveApproval function to support a generalized operation execution pattern. Instead of being hardcoded to only handle order matching, it now uses function selectors to dispatch different operations, making the implementation more extensible.

Key changes:

  • Refactored receiveApproval to extract function selectors from calldata and dispatch to operation-specific validators
  • Updated encodeOrders to include the matchOrders function selector in the encoded data
  • Added validation logic separation with _validateMatchOrders and execution logic in _executeOperation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
utils/odb-tools.ts Updated encodeOrders to prepend the matchOrders function selector to encoded parameters
contracts/facets/IexecEscrowTokenFacet.sol Refactored receiveApproval to use generalized operation dispatch pattern with selector-based routing
test/byContract/IexecEscrow/IexecEscrowToken.receiveApproval.test.ts Updated test descriptions and added test for unsupported operation selector validation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const iface = new ethers.Interface([
`function matchOrders(${appOrderType} apporder, ${datasetOrderType} datasetorder, ${workerpoolOrderType} workerpoolorder, ${requestOrderType} requestorder)`,
]);
const matchOrdersSelector = iface.getFunction('matchOrders')!.selector;
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the non-null assertion operator (!) is unsafe here. If getFunction returns undefined (e.g., due to a typo in the function name), this will throw a runtime error. Consider adding an explicit null check or using optional chaining with a fallback error message.

Suggested change
const matchOrdersSelector = iface.getFunction('matchOrders')!.selector;
const matchOrdersFn = iface.getFunction('matchOrders');
if (!matchOrdersFn) {
throw new Error("Function 'matchOrders' not found in interface");
}
const matchOrdersSelector = matchOrdersFn.selector;

Copilot uses AI. Check for mistakes.
* @param sender The user who deposited (must be the requester)
* @param data ABI-encoded matchOrders call with orders
*/
function _validateMatchOrders(address sender, bytes calldata data) internal pure {
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is marked as pure but it performs abi.decode on calldata. While this is technically allowed in newer Solidity versions, the function should be marked as view for clarity and consistency, as it reads from calldata which is external data.

Suggested change
function _validateMatchOrders(address sender, bytes calldata data) internal pure {
function _validateMatchOrders(address sender, bytes calldata data) internal view {

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function state mutability can be restricted to puresolidity(2018)

Comment on lines +182 to +183
(, , , IexecLibOrders_v5.RequestOrder memory requestorder) = abi.decode(
data[4:],
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 179-181 states 'We only need to check requestorder.requester', but this approach still decodes all four order structs (consuming gas for all of them). Consider adding a note about the gas trade-off or exploring if there's a more efficient way to decode only the request order if optimization is important.

Copilot uses AI. Check for mistakes.
@gfournierPro gfournierPro self-assigned this Nov 12, 2025
@gfournierPro gfournierPro marked this pull request as ready for review November 12, 2025 12:57
@gfournierPro gfournierPro changed the title Feat: receive approval generic feat: receive approval generic Nov 12, 2025
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.37%. Comparing base (900c30e) to head (8f85fc3).
⚠️ Report is 1 commits behind head on chore/solidity-v8.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           chore/solidity-v8     #323      +/-   ##
=====================================================
+ Coverage              96.36%   96.37%   +0.01%     
=====================================================
  Files                     33       33              
  Lines                   1127     1132       +5     
  Branches                 227      228       +1     
=====================================================
+ Hits                    1086     1091       +5     
  Misses                    41       41              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@Le-Caignec Le-Caignec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Good job

@gfournierPro gfournierPro merged commit af281bf into chore/solidity-v8 Nov 12, 2025
5 checks passed
@gfournierPro gfournierPro deleted the feat/receiveApproval-generic branch November 12, 2025 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants