{"content":{"title":"OpenZeppelin  5.x 与 4.x 主要区别源码级解读","body":"OpenZeppelin  5.x 发布仅三周，目前网上除了官方之后没有详细的介绍，这篇文章是  OpenZeppelin 5.x  概览，可以帮助读者迅速的了解 5.x 和 4.x 的主要区别。\r\n     \r\n     根据官网文档，我们了解到 5.x 版本主要有这些点的改进\r\n    \r\n     ① 简化了设计\r\n     ② 删除了一些过时的用法\r\n     ③ 同时降低了 Gas 消耗\r\n     ④ 提升了存储安全性\r\n     ⑤ 重新定义的访问控制\r\n  \r\n  在 Beyond Compare 的源码对比上，可以清晰的看到这些差异点，以下是这些差异点的信息列举\r\n  \r\n\r\n1 取消了 ERC777 协议\r\n\r\n\r\n![8e3cfe45bb6b08fcd713cd92b2b1139.png](https://img.learnblockchain.cn/attachments/2023/10/nk1ho3Na65361ca16d6d6.png)\r\n\r\n2 取消了跨链协议\r\n\r\n\r\n![c5377d2f12e325eb72595bfdf2a894c.png](https://img.learnblockchain.cn/attachments/2023/10/CTLGI7z965361cbc0eb07.png)\r\n\r\n3 取消了安全模块 security，传统的合约攻击，比如重放，数值的攻击方式其实已经过时\r\n新版本的 EVM 在执行合约计算时发生这些错误矿工会自动终止而不是继续执行，导致错误传递\r\n\r\n\r\n![39b620cf0038245341d41fcc2af870d.png](https://img.learnblockchain.cn/attachments/2023/10/q49SAWak65361cf86d314.png)\r\n\r\n4 access 模块中新增了 extensions 操作接口\r\n\r\n\r\n![d8624303cf9416cbc49bf71b17d7d39.png](https://img.learnblockchain.cn/attachments/2023/10/MNhAJeHE65361d2db1a45.png)\r\n\r\n5 新增了 IRC5267，IERC5267，ERC5313，IERC5805，IERC6372 这些接口（图中紫色部分）\r\n\r\n\r\n![04005c868cabba8ef52633c33ad4f8c.png](https://img.learnblockchain.cn/attachments/2023/10/r3tGBDLO65361d430c87f.png)\r\n\r\nopenzeppelin 5.x 官方说明文档\r\n\r\nhttps://blog.openzeppelin.com/introducing-openzeppelin-contracts-5.0\r\n                                                                                                          \r\n                                                                                                             大灰 西安  \r\n                                                                                                             \r\n                                                                                                             2023年10月23日"},"author":{"user":"https://learnblockchain.cn/people/3936","address":null},"history":"QmbtmESmtzedMv7jX9iY4tizWW77DKdR2SoD8hkTTCZgNr","timestamp":1698047100,"version":1}