The divideNft() function does not follow the Checks-Effects-Interactions (CEI) pattern correctly, leading to potential state inconsistencies and misleading event emissions.
External Calls Before State Updates
The function updates the state (e.g., token balances and mappings) before confirming that the final ERC20 token transfer to the caller succeeds. If the transfer fails, the transaction reverts, but the state update would have already occurred, causing inconsistencies.
Event Emission Before Final Confirmation
The NftDivided event is emitted before the function ensures that all operations, including the ERC20 transfer, are successful. This premature emission can mislead off-chain services and users into believing the operation succeeded when it did not.
State Inconsistencies: Partial updates to state if the function reverts after state changes but before the token transfer succeeds.
Misleading Event Logs: Incorrect event emissions, causing confusion for users and off-chain systems reliant on event data.
Manual code review.
Reorder the function to follow the CEI pattern strictly:
Perform all external interactions (e.g., NFT transfer and ERC20 token transfer) before any state updates.
Update the contract’s state only after confirming the success of all external calls.
Emit events last, only after the entire operation completes successfully.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.