Skip to content

Commit 6286e36

Browse files
authored
Merge pull request #786 from LingYe-WEB3/fix/07_Mapping
Fix keccak256(abi.encodePacked(addr, index)) => keccak256(abi.encode(…
2 parents 481c5af + e325347 commit 6286e36

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

07_Mapping/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ mapping(address => address) public swapPair; // 币对的映射,地址到地
6161
6262
- **原理1**: 映射不储存任何键(`Key`)的资讯,也没有length的资讯。
6363
64-
- **原理2**: 映射使用`keccak256(abi.encodePacked(key, slot))`当成offset存取value,其中`slot`是映射变量定义所在的插槽位置。
64+
- **原理2**: 对于映射使用`keccak256(h(key) . slot)`计算存取value的位置。感兴趣的可以去阅读 [WTF Solidity 内部规则: 映射存储布局](https://github.com/WTFAcademy/WTF-Solidity-Internals/tree/master/tutorials/02_MappingStorage)
6565
6666
- **原理3**: 因为Ethereum会定义所有未使用的空间为0,所以未赋值(`Value`)的键(`Key`)初始值都是各个type的默认值,如uint的默认值是0。
6767

0 commit comments

Comments
 (0)