The get_secret view function is intended to allow a user to read their stored secret.
The function's implementation contains flawed logic that makes it impossible to use correctly. It first asserts that the caller is the contract owner (@owner), and then it attempts to borrow the Vault resource from the @owner's address. However, the set_secret function stores the Vault at the caller's address, not the owner's. This mismatch means no user can ever successfully retrieve a secret.
Likelihood:
Any non-owner calling get_secret will always have their transaction reverted by the assert! check.
The contract owner calling get_secret will cause an abort due to a "resource not found" error, unless the owner has also called set_secret for themselves. The function can never read another user's Vault.
Impact:
The function to read data is completely non-functional, breaking the core logic of the contract.
Users can store secrets but have no way to view them, rendering the contract useless.
The following test demonstrates that neither a user nor the owner can retrieve the user's secret.
A user creates a Vault by calling set_secret.
An attempt by the user to call get_secret will always fail the assert!(caller == @owner) check, as shown in the test_user_cannot_get_secret which expects a failure with error code 1 (NOT_OWNER).
An attempt by the owner to call get_secret to retrieve the user's secret will also fail, because the borrow_global<Vault>(@owner) call looks for a Vault at the owner's address, but it is stored at the user's address. This is shown in the test_owner_cannot_get_secret which will abort because the resource is missing.
The function should be redesigned to allow a user to view the secret stored in their own Vault. The access control should check that the caller is the owner of the Vault they are trying to access.
This is accomplished by removing the incorrect check against the contract @owner and instead borrowing the Vault from the caller's own address. This ensures that any user can view their own secret, restoring the function's intended behavior.
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.