Closed sherlock-admin2 closed 7 months ago
1 comment(s) were left on this issue during the judging contest.
0xAadi commented:
Invalid:
_injectFees(order)
update the order, as the order utilizes the memory reference of the element within the struct arrayorders
.
turvec
high
Protocol will loss all fees due to injected fees not being reflected on trader orders
Summary
Protocol will loss all fees due to injected fees not being reflected on trader orders
Vulnerability Detail
https://github.com/sherlock-audit/2024-02-rubicon-finance/blob/main/gladius-contracts-internal/src/reactors/BaseGladiusReactor.sol#L213 In the code snipet provided above, the changes made to the order parameter within the _injectFees function will not reflect on the original orders array passed into the _prepare function. This is because the order parameter is passed by value to the _injectFees function, and any modifications made to it are only affecting the local copy, not the original array element.
In Solidity, parameters are always passed by value, and for complex types like structs and arrays, a new copy is made. Changes to the copy do not affect the original data unless you explicitly return the modified copy and reassign it to the original.
Proof Of Concept
Here's a breakdown of what happens in the code:
Impact
The modified copy is not automatically synced back to the original orders array causing protocol to loss all fees due to injected fees not being reflected on trader orders.
Code Snippet
https://github.com/sherlock-audit/2024-02-rubicon-finance/blob/main/gladius-contracts-internal/src/reactors/BaseGladiusReactor.sol#L213 https://github.com/sherlock-audit/2024-02-rubicon-finance/blob/main/gladius-contracts-internal/src/base/ProtocolFees.sol#L39 https://github.com/sherlock-audit/2024-02-rubicon-finance/blob/main/gladius-contracts-internal/src/base/ProtocolFees.sol#L104
Tool used
Manual Review
Recommendation
To ensure that the changes made to order in _injectFees are reflected in the original orders array, you would need to return the modified order from _injectFees and then reassign it to the corresponding element in the orders array. Here's how you could adjust the contract:
However for this to work, you have to modify the
_injectFees()
function in the ProtocolFees.sol contract as wellNotice that the _injectFees function now has a return type and returns the modified order. In the _prepare function, the returned order is reassigned to the local copy, ensuring that fee injected persist.
Duplicate of #76