Files
nexus/wiki/sources/engineering-solidity-smart-contract-engineer.md
2026-05-03 05:42:12 +08:00

58 lines
4.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Solidity Smart Contract Engineer Agent Personality"
type: source
tags: []
date: 2026-05-01
---
## Source File
- [[Agent/agency-agents/engineering/engineering-solidity-smart-contract-engineer.md]]
## Summary用中文描述
- 核心主题EVM 智能合约开发 Agent 人格定义,涵盖 Solidity 智能合约的安全开发、Gas 优化、可升级架构、DeFi 协议构建和代码审计标准
- 问题域EVM 兼容链(以太坊主网及 L2的智能合约架构设计与安全审计
- 方法/机制checks-effects-interactions 模式、UUPS 代理模式、OpenZeppelin 基础合约、Foundry 测试框架、Gas 优化模式存储打包、自定义错误、calldata 使用)
- 结论/价值:提供了一套完整的智能合约开发方法论,强调安全第一、最小化 Gas 消耗和完整的测试覆盖
## Key Claims用中文描述
- 开发者必须将每个合约视为面临无限资本攻击者阅读源代码的场景进行设计
- 遵循 checks-effects-interactions 模式和非 reentrancy guards 是防止外部调用重入攻击的根本保障
- Gas 优化应从设计阶段开始,包括存储打包、使用 calldata、优先使用 external 而非 public 函数
- 可升级合约架构UUPS/Transparent Proxy需从第一天就规划不能事后补救
- 每个协议必须配备 Foundry 测试套件,分支覆盖率 >95%,并包含 fuzz 和 invariant 测试
## Key Quotes
> "You treat every wei of gas as precious, every external call as a potential attack vector, and every storage slot as prime real estate." — 角色定位核心理念
> "Default requirement: Every contract must be written as if an adversary with unlimited capital is reading the source code right now" — 安全设计第一原则
> "Clever code is dangerous code and simple code ships safely" — 代码简洁性哲学
> "Never use `tx.origin` for authorization — it is always `msg.sender`" — 授权安全红线
> "Never use `transfer()` or `send()` — always use `call{value:}("")` with proper reentrancy guards" — 外部调用安全规范
## Key Concepts
- [[ChecksEffectsInteractions]]checks验证→ effects状态更新→ interactions外部调用的顺序执行模式是防止重入攻击的根本原则
- [[ReentrancyGuard]]:防止合约函数被递归调用的访问控制机制,通过 mutex 锁确保同一调用栈中不可重入
- [[UUPSUpgradeable]]通用可升级代理模式Universal Upgradeable Proxy Standard将升级逻辑放在实现合约中而非代理中降低部署成本
- [[GasOptimization]]:通过存储打包、使用 calldata、自定义错误、immutable/constant 等手段最小化 EVM 执行成本的技术集合
- [[StoragePacking]]:将多个小类型变量打包进同一 32 字节存储槽以节省 Gas 的模式
- [[FlashLoanAttack]]:通过在单笔交易中借出并归还大量资产来操纵价格或状态的攻击模式,涵盖 Mango Markets 等典型案例
- [[OpenZeppelin]]:最广泛使用的 Solidity 安全合约库,提供 ERC 标准实现、可升级代理、访问控制等经过审计的基础组件
## Key Entities
- The DAO2016 年以太坊经典重入攻击事件,开创了智能合约安全攻防研究的先河
- Parity Wallet2017 年 delegatecall 库调用漏洞导致钱包被锁死的安全事件
- Wormhole2022 年跨链桥攻击事件,攻击者利用签名验证漏洞窃取 3.2 亿美元
- Ronin Bridge2022 年验证节点被入侵导致 6.25 亿美元被盗的桥接攻击事件
- Euler Finance2023 年闪电贷操纵攻击事件,因合约缺少健康检查机制导致 1.97 亿美元损失
- OpenZeppelin最广泛使用的 Solidity 安全合约库,提供 ERC 标准、可升级代理、访问控制等审计过的合约
- Foundry最流行的 Solidity 开发框架,支持 Forge 测试、Fuzz 测试和 Invariant 测试
## Connections
- [[BlockchainSecurityAuditor]] ← 共享安全第一原则 ← [[SoliditySmartContractEngineer]]
- [[SoliditySmartContractEngineer]] ← 使用基础合约 ← [[OpenZeppelin]]
- [[SoliditySmartContractEngineer]] ← 使用测试框架 ← Foundry
- [[SoliditySmartContractEngineer]] ← 防御目标 ← FlashLoanAttack
## Contradictions
- 与 [[BlockchainSecurityAuditor]]:两者均强调安全,但 Smart Contract Engineer 更关注开发实现过程Gas 优化、可升级性),而 Security Auditor 专注于渗透测试和漏洞发现
- 与 [[SoftwareArchitect]]Software Architect 强调通用架构设计Smart Contract Engineer 则有独特的 EVM 约束Gas 模型、存储成本、外部调用风险),需要专门的安全和性能考量