Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Valid

It is not safe to save secrets on the blockchain

Summary

It is not safe to store secrets on the blockchain.

Vulnerability Details

If it is on a blockchain, all the data are supposed to be public and there is no way you can store any kind of secret in plain text. The secret will be like announced publicly to the world if there is a dev with minial skills who can check the so-called "private" state variables.

after run the $ make anvil and $make deploy command we run the POC as below:

$ export CADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3
# read the storate slots
$ cast storage $CADDRESS 0
0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266
$ cast storage $CADDRESS 1
0x6d7950617373776f726400000000000000000000000000000000000000000014
# decode the string
# the first one is: "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
# the seconde one is: "myPassword"

Impact

The main function of this smart contract fails.

Tools Used

Foundry - anvil, cast, forge

Recommendations

never store the password in plain text on chain. This will fail.
Store the information off-chain and you can store the hashed value of the password on-chain.
Even though people can see the hashed value, they will not know your secret value behind the scene.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-anyone-can-read-storage

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

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.