The balance returned by getContractBalance
may not align with the NatSpec expectation of reflecting the contract's actual balance (i.e., pot plus platform fees, accounting for any pending payouts), as the contract's receive function allows it to accept direct Ether transfers unrelated to game play, potentially causing discrepancies.
The getContractBalance
function is documented via NatSpec to return the contract's current balance, which should reflect the sum of the pot and platform fees, accounting for any pending payouts:
However, the contract includes an explicitly receive
function, which allows it to accept direct Ether transfers. If funds are sent directly to the contract (i.e., outside the intended gameplay flow), they will be included in address(this).balance
, inflating the reported balance. As a result, returning address(this).balance
may not accurately represent the game play related funds, making the implementation inconsistent with the NatSpec comment.
Likelihood:
Given that the receive
function is implemented and the contract can accept unsolicited Ether transfers, it is likely that at some point, funds unrelated to gameplay will be sent to the contract. This can happen unintentionally (e.g., mistaken transfers) or through manual interactions with the contract, especially if the address is known.
Impact:
If external Ether is sent directly to the contract via the receive
function, the balance returned by getContractBalance
will include funds unrelated to gameplay.
This can lead to:
Misleading balance reporting, where the returned value does not accurately reflect the pot and platform fees as expected.
Incorrect assumptions by users, especially if external systems/front-end UI rely on getContractBalance
for decision-making on game state.
Potential issues in audits or accounting, as untracked or unexpected funds inflate the balance, creating confusion or mismatches in financial reports.
In test/Game.t.sol
, add the following test:
In terminal, run forge test --match-test test_audit_contractBalanceMismatch -vvv
will generate the following results:
The test showed that the enquired game contract balance was not tally to the manual track game balance, indicating that the getContractBalance
function doesn't not reflect the rightful actual game play related fund.
To ensure the accuracy of getContractBalance
and align it with the NatSpec expectation (i.e., pot plus platform fees, excluding unrelated funds), consider the followings:
amend the return output
2.remove receive
function to avoid any unexpected transfers
3.log the direct deposits separately for auditing purpose
There is no reason for a user to directly send ETH or anything to this contract. Basic user mistake, info, invalid according to CH Docs.
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.