#36922 [SC-Insight] the function claim_collateral in borrowOperation have read only attribute while the invoked claim_collateral function have write attribute, this lead to compiler-time error
Submitted on Nov 19th 2024 at 18:44:45 UTC by @zeroK for IOP | Fluid Protocol
Report ID: #36922
Report Type: Smart Contract
Report severity: Insight
Target: https://github.com/Hydrogen-Labs/fluid-protocol/tree/main/contracts/trove-manager-contract/src/main.sw
Impacts:
Contract fails to deliver promised returns, but doesn't lose value
Description
Brief/Intro
the function borrowOperation#claim_collateral
is set to read only attribute, this mean that the function have read access to storage only, but the function invoke calls to the corSurplus#claim_collateral
function which have write storage attribute, this is issue according to fuel blockchain documents since impure functions which call another impure functions should have same storage attribute to avoid compiler-time error:
Impure functions which call other impure functions must have at least the same storage privileges or a superset of those for the function called. For example, to call a function with write access a caller must also have write access, or both read and write access. To call a function with read and write access the caller must also have both privileges
https://docs.fuel.network/docs/sway/blockchain-development/purity/#purity
Vulnerability Details
the borrowOperation#claim_collateral
implemented as below:
as shown above, the claim_collateral have read only attribute while the coll_surplus.claim_coll have write,read storage attribute which indeed access the storage and write data into it:
we talked with fuel team in similar issue in specific protocol and the approved that the docs is correct and impure functions should have same storage attribute to avoid any compiler errors.
Impact Details
claim_coll with read attribute should have write attribute similar to the function that get invoked inside it.
References
change the function to below:
Proof of Concept
Proof of Concept
create new project to run the function call below which reverts during compile time: