Everything stored on blockchain is visible to anyone and anytime. Internal or private variables do not change this fact. In PasswordStore.sol
contract, s_password
variable stores the password and it's visible to everyone.
According to Solidity docs :
...data is stored contiguously item after item starting with the first state variable, which is stored in slot
0
. For each variable, a size in bytes is determined according to its type. Multiple, contiguous items that need less than 32 bytes are packed into a single storage slot if possible, according to the following rules: ,
The first item in a storage slot is stored lower-order aligned.
Value types use only as many bytes as are necessary to store them.
s_password
variable is the 2nd variable after s_owner
. Its slot is 1
. In order to reveal the content of the slot we can use forge storage command: cast storage [options] address slot
Depending on the size of the string, slot number can change.
Assuming our deployed contract address is 0x5fbdb2315678afecb367f032d93f642f64180aa3
our command to reveal the password will be: cast storage 0x5fbdb2315678afecb367f032d93f642f64180aa3 1
The output of this command is: `0x6d7950617373776f726400000000000000000000000000000000000000000014
The first 32 bytes of this output is the hex value of the password and the 2nd 32 bytes is the length of the string which is stored in this slot 1
.
Stored password in hex: 6d7950617373776f7264000000000000
The length of the string stored in slot 1
: 00000000000000000000000000000014
To convert hex to text, forge command cast to-ascii
can be used: cast to-ascii 6d7950617373776f7264000000000000
The output will be: myPassword
Another method to prove it is to test it in foundry:
Manual audit
Foundry
Don't store password on chain. Depending on the expected logic access lists can be an alternative.
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.