当前位置:网站首页>Smart Contract Security - Private Data Access
Smart Contract Security - Private Data Access
2022-07-30 14:59:00 【fingernft】
This time we will see how to access private data (private data) in the contract.Not much to say about the target contract, go directly to the code

This time our target contract is a contract deployed on Ropsten.
合约地址:0x3505a02BCDFbb225988161a95528bfDb279faD6b链接:https://ropsten.etherscan.io/address/0x3505a02BCDFbb225988161a95528bfDb279faD6b#code
Vulnerability Analysis From the above contract code, we can see that the Vault contract records sensitive data such as the user's username and password in the contract. We know that the keywords that modify the variables in the contract only limit its calling scope, which alsoThis indirectly proves that the data in the contract is public and can be read at will, and it is not safe to record sensitive data in the contract.
Read data
First, let's learn about solidity's storage storage method: 1) The data in storage is permanently stored.It is stored in the slot slot as a key-value pair.2) The data in the storage is arranged from right to left in the slot. When the space is insufficient, the current slot is packaged and the next slot is opened to store data; when storing a fixed-length array (fixed length), each data in the array occupies a slot.3) Storing variable-length arrays (the length changes with the number of elements) is special. When encountering variable-length arrays, a new slot slotA will be enabled to store the length of the array, and its data will be stored in another number ofslotV in the slot.SlotA represents the position where the variable-length array is declared, and also stores the length of the variable-length array: length = sload(slotA) uses slotV to represent the location of the variable-length array data storage (ie key), and index represents the index subscript corresponding to the value:slotV = keccak256(slotA) + index uses value to represent the value of a certain data in the variable-length array: value = sload(slotV) Next, we will take you to read the data in this contract.First, let's look at the data in slot0:
It can be seen from the contract that only one uint type of data is stored in slot0, let's read it out and take a look: I use Web3.py to get the data here, first write the program
Running result:

"7b" is a hexadecimal number, which is 123 when converted to a decimal number.Here we have successfully reached the uint type variable count=123 stored in the first slot slot0 in the contract, let's continue:
Three variables are stored in slot1: u16, isTrue, owner
Running result:
From right to left, owner = f36467c4e023c31f026066b8dc51456e7b791d99isTrue = 01 = trueu16 == 31
The private variable password is stored in slot2, let's read it
Running result:

Slots 3, 4, 5 store three elements in a fixed-length array
Running result:

Slot6 stores the length of the variable-length array
Running result:

The returned result shows that the length of the variable-length array is 3.We can see from the contract code that the user's id and password are stored in the form of key-value pairs. Let's read the id and password of two users: user1
Running result:

user2
Running result:
In this way, we successfully read all the data in the contract.It can be seen that the private data in the contract can also be read.In conclusion, as you can see, the private data in the contract can also be read, so be sure not to store any sensitive data in the contract.
If you want to know more about smart contracts and blockchain knowledge, welcome to the blockchain exchange community CHAINPIP community to communicate and learn together~Community address: https://www.chainpip.com/
边栏推荐
- How to use Databricks for data analysis on TiDB Cloud | TiDB Cloud User Guide
- Some thoughts on String
- A Small Case About Containers
- 学习 MySQL 需要知道的 28 个小技巧
- 接口自动化框架,lm-easytest内测版发布,赶紧用起来~
- 时序数据库在船舶风险管理领域的应用
- What should I do if the sql server installation fails (what should I do if the sql server cannot be installed)
- 一文读懂网络效应对Web3的重要意义
- 关于华为应用市场审核App无法启动的问题
- UPC2022 Summer Individual Training Game 19 (B, P)
猜你喜欢

Flask框架——Flask-Mail邮件

吃透Chisel语言.29.Chisel进阶之通信状态机(一)——通信状态机:以闪光灯为例

八年测试经验,为何惨遭领导痛批:你写的测试文档还不如刚来的应届生

3年软件测试经验面试要求月薪22K,明显感觉他背了很多面试题...

【回归预测-lssvm分类】基于最小二乘支持向量机lssvm实现数据分类代码

How awesome is the "12306" architecture?

去腾讯面试,直接让人出门左拐 :幂等性都不知道!

00后测试员摸爬滚打近一年,为是否要转行或去学软件测试的学弟们总结出了以下走心建议

以unity3d为例解读:游戏数据加密

43.【list的简单属性】
随机推荐
Androd 跳转到google应用市场
时间序列的数据分析(四):STL分解
canal抓取数据
3年软件测试经验面试要求月薪22K,明显感觉他背了很多面试题...
吃透Chisel语言.28.Chisel进阶之有限状态机(二)——Mealy状态机及与Moore状态机的对比
ECCV 2022 | Towards Data Efficient Transformer Object Detectors
Six-faced ant financial clothing, resisting the bombardment of the interviewer, came to interview for review
MongoDB启动报错 Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
SLF4J的使用
Before quitting, make yourself a roll king
VLAN实验
跳槽前,把自己弄成卷王
What is defect analysis?An article takes you to understand the necessary skills of test engineers
【回归预测-CNN预测】基于卷积神经网络CNN实现数据回归预测附matlab代码
Huawei's 7-year-experienced software testing director, gives some advice to all friends who want to change careers to learn software testing
CS内网横向移动 模拟渗透实操 超详细
[Advanced ROS] Lecture 11 Robot co-simulation based on Gazebo and Rviz (motion control and sensors)
ToDesk版本更新,引入RTC传输技术,是否早以替代向日葵远程控制?
A Small Case About Containers
ECCV 2022 | 通往数据高效的Transformer目标检测器