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

Private Variable Misuse

Summary

This contract allows you to store a private password that others won't be able to see. It is possible to update the password at any time. The main problem in this contract is the misuse of a private variable to store a password.

Vulnerability Details

  1. The main vulnerability in this contract is the private variable s_password that is used to store the password. Private variables can only be read by the contract and are not accessible from an external contract. However, the information stored is public and can be retrieved from outside the blockchain.

The following example returns the storage value at an specific storage slot:

const storage = await web3.eth.getStorageAt(address, slot, block)
console.log(storage)

In this case the variable address is the contract address deployed, slot is the storage slot to retrieve information from and block the block number.

Impact

High impact.

Tools Used

  • Manual verification

  • Hardhat

  • Foundry

  • Solc Version: 0.8.1

Recommendations

  1. Consider to store the password encrypted as a hash value and using the bytes32 data type instead of a string data type.

  2. Add an access control mechanism to the function setPassword(). This is to prevent anyone but the owner can modify the password value.

Updates

Lead Judging Commences

inallhonesty Lead Judge almost 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.