TGViewer
Laisky's Notes Laisky's Notes @laiskynotes · 3.34K subscribers
Post #234 998
https://laisky.notion.site/Solidity-layout-and-access-of-storage-state-variables-simply-explained-6fb8c4eaca0d4004b361e4358257fa92?pvs=4

详细介绍了 solidity storage 的存储结构。每一个 smart contract 都有独立的 storage,由 2^{256}-1 个 slots 组成,每个 slot 的长度为 32 bytes。

在 solidity 中声明的 variables 都会在 slot 中从头开始逐一存放,它们存储的位置称为 slot index。

比较奇葩的是 dynamic variables,如 array、mapping 和长度超过 32 bytes 的 string。拿 array 来说,其 slot 内存放的只是其长度,它的成员数据实际上是连续存放在另外一组随机的 slots 里的,这组 slots 的首地址由 keccak256(slot index) 计算而来。

理论上,dynamic variables 是有可能和其他的数据的 slot 发生冲突的,但是考虑到 2^256 是一个足够巨大的空间,一般认为超过 2^100 就足够满足密码学的碰撞安全性要求了,ECC-256 的安全等级也就是 2^128,如果你不担心自己的私钥被别人碰撞出来,那么也不需要担心 dynamic variables 和其他 slot 碰撞。

#blockchain #evm
next: https://t.me/laiskynotes/245
laisky on Notion Solidity layout and access of storage state variables simply explained | Notion The Storage is like a key-value data structure that holds the state variables values of a Solidity smart contract.
  • 👍 3
  • 🤔 1
More from @laiskynotes
  1. Oct 6, 2026https://x.com/LaiskyCai/status/2107307813727060123?s=20 codex 最近有三个完全免费的工具,结合之后可以发挥非常强大能力:…
  2. Sep 15, 2026学习了一下 OpenAI 推出的 Agents API https://openai.com/index/introducing-the-agents-api/ 众所周知 Agen…
  3. Aug 28, 2026前阵子读了本很有趣的书,侯杨方的《这才是丝绸之路》。作者抛开抽象的文本溯源,而是采用实地考察的方式,重走了真实的丝绸之路。此书给我最大的感触就是:真实而且符合常理。 在我以前的想象…
  4. Jun 5, 2026读完 Mario Puzo 的《教父 The Godfather》三部曲小说,才意识到自己当年年轻时根本完全就没看懂电影《教父》。然后又去把电影重温了一遍,才发现原来电影里有很多细…
  5. May 22, 2026记录一下最近遇到的一个糟心事儿。 最近两个月开始又开始找工作机会,总的来说很不顺利,托朋友联系了两个内推也是石沉大海。(各位要是有远程工作的机会也请联系 job@laisky.co…
  6. May 14, 2026作为一个从业十多年的程序员,我已经半年没手写过一行代码了。上个月大概提交了 20 万行,这个月大概 4 万行。 昨天认真考虑了一下这个现象,我个人认为,虽然 AI 仍然存在显然的不…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →