The PasswordStore smart contract stores passwords in contract storage as a private variable. However, the privacy of this storage is compromised as the contents can be directly fetched and decoded from the storage slots using commands like cast storage
and cast parse-bytes32-string
.
The vulnerability resides in the manner the PasswordStore contract stores the password in its storage. Despite s_password
being declared as a private variable, the data stored in Ethereum's contract storage slots is accessible. By using specific commands, an adversary can fetch and decode the contents of the storage slots to reveal the stored password. The following commands demonstrate this exploit:
Example:
This vulnerability holds a High severity based on the provided severity evaluation criteria. The exposure of the password poses a direct threat to the main functionality of the protocol, which is to securely store and retrieve passwords. Additionally, the straightforward exploitation path further accentuates the severity of this vulnerability.
Impact on the protocol: The protocol's main functionality of securely storing and retrieving passwords is directly compromised.
Likelihood of exploitation: The exploitation is highly likely since it requires no special conditions - anyone with knowledge of the contract's address and the aforementioned commands can access and decode the stored password.
Foundry's cast command: For fetching the contents of storage slots and parsing the stored data.
Enhanced Access Control: Implementing strict access control mechanisms to restrict the reading of storage slots to authorized entities only.
Off-chain Storage: Consider off-chain solutions for storing sensitive data like passwords, keeping them off the public blockchain.
Encryption: If on-chain storage is necessary, consider encrypting sensitive data before storing it, ensuring only authorized parties with the decryption key can access the actual data.
Hashing: Store a hash of the password instead of the plaintext password, ensuring that even if the storage is accessed, the actual password remains concealed.
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.