The password can be extracted by any person familiar with the storage layout of the EVM.
High, compromising the functionality of the protocol
Tools from the smart contract framework foundry (cast, anvil)
By analyzing the storage for the example deploy script:
We can see that our password is 'myPassword', if we deploy the contract following the README of the project:
Start a local node
Deploy
This will default to your local node. You need to have it running in another terminal in order for it to deploy.
If the smart contract code is public in etherscan, we can analyze the code:
The two first storage variables are the address (20 bytes) that occupies the first slot (0), the second is the string variable is located in the second slot (1), strings and bytes are stored in different ways as other data types in the EVM.
Reference to the solidity documentation about the storage layout of those datatypes:
The storage slot where the data of a string is stored is determined by simple rules, and thus predictable.
In the case that we have in our script above, the way we can extract the data is the following:
In my case the command was this:
And we get this result from the command:
The data is encoded in bytes, but we can easily decoded with this command:
And gives us the output:
In the case of the password being longer, in the storage slot would only be the length of the string, following the Solidity documentation, we can calculate how many storage slots will the string be, and calculate the starting storage slot, with the keccak hash of the storage position.
Do not pursue deploying in Ethereum for private data, the structure of the blockchain is not designed for this kind of data, I'll recommend if the project needs a decentralized computing environment and interactions with smart contracts, to investigate Oasis Network and their blockchain Sapphire, a EVM compatible blockchain able to store private data, impossible to retrieve if the developer desires.
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.