The functions of the PasswordStore.sol contract are to manage a password that can be only set and read by the contract owner. But through examining the code as well as using some tricks exploiting the nature of Solidity, one can easily manage to crack this rule.
This is because this function
doesn't check whether the sender is owner or not.
This bug can be demonstrated through this test, here, we call the setPassword
function from a non-owner address and expect it to revert, but it fails.
We have many ways to read the password stored in the contract, 2 possible ways are:
Read the storage slot where the password variable is placed:
Trace the password value set by the owner in the past
The above codes can be found here
These bugs can cause severe consequences to the owner. If he use the given password to lock his assets or personal data, he will lose everything.
Foundry: to demonstrate the password manipulation bug
Hardhat: to read the on-chain password using ethers.js client
To restrict who can modify the password, we should add this requirement on top of the setPassword
function, so no one but the owner can call it
Basically, we shouldn't store anything that is meant to be private on-chain like password
Private functions and state variables are only visible for the contract they are defined in and not in derived contracts. In this case private doesn't mean secret/confidential
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.