Skip to content

Commit

Permalink
Fix keccak256(abi.encodePacked(addr, index)) => keccak256(abi.encode(…
Browse files Browse the repository at this point in the history
…addr, index))
  • Loading branch information
Ling ye authored and Ling ye committed Sep 25, 2024
1 parent 6ce6c25 commit 2298960
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion 07_Mapping/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mapping(address => address) public swapPair; // 币对的映射,地址到地

- **原理1**: 映射不储存任何键(`Key`)的资讯,也没有length的资讯。

- **原理2**: 映射使用`keccak256(abi.encodePacked(key, slot))`当成offset存取value,其中`slot`是映射变量定义所在的插槽位置。
- **原理2**: 映射使用`keccak256(abi.encode(key, slot))`当成offset存取value,其中`slot`是映射变量定义所在的插槽位置。

- **原理3**: 因为Ethereum会定义所有未使用的空间为0,所以未赋值(`Value`)的键(`Key`)初始值都是各个type的默认值,如uint的默认值是0。

Expand Down

0 comments on commit 2298960

Please sign in to comment.