The password stored in the PasswordStore
contract can be directly extracted through the contract's storage.
The password is stored in the s_password
variable at slot 1. Even if the s_password
is declared a private variable, we can extract its content easily off-chain.
https://github.com/Cyfrin/2023-10-PasswordStore/blob/856ed94bfcf1031bf9d13514cb21b591d88ed323/src/PasswordStore.sol#L14
The following presents the PoC code. The test_hack_PasswordStore()
was extended from the test_owner_can_set_password()
. Therefore, the expected password would be the same ("myNewPassword
").
Since "myNewPassword
" is a short string (its length <= 31 bytes), Solidity will store it in the same storage slot as the string length, placing it in the higher-order bytes (left aligned). That is the higher-order bytes of the storage slot 1.
Hence, the test_hack_PasswordStore()
will extract the password from slot 1 and then compare the extracted password to the expected password.
The password can be extracted from the PasswordStore
contract's storage even if it would be stored in a private state variable, s_password
.
Manual Review
Sensitive data like passwords should not be processed or stored on a public blockchain.
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.