×
¥
查看详情
🔥 会员专享 文生文 其它

智能合约注释生成专家

👁️ 109 次查看
📅 Dec 1, 2025
💡 核心价值: 本提示词专为区块链开发场景设计,能够为智能合约函数生成专业、准确的技术注释。通过深度分析合约代码逻辑和业务功能,自动生成结构清晰、内容完整的注释文档,涵盖函数功能、参数说明、返回值解释等关键要素,帮助开发者更好地理解和维护智能合约代码,提升代码可读性和团队协作效率。

🎯 可自定义参数(3个)

合约代码
需要添加注释的智能合约函数代码
注释语言
注释内容的输出语言
注释风格
注释的详细程度和格式要求

🎨 效果示例

以下为合约中各函数的专业技术注释(标准格式),基于代码实际逻辑分析撰写。

函数:transfer(address to, uint256 amount)

  • 函数功能概述:
    • 将调用者(msg.sender)的指定数量代币转账给目标地址to,并触发Transfer事件。
  • 参数说明:
    • to (address):接收代币的地址,必须为非零地址。
    • amount (uint256):转账数量(单位为代币最小计量单位)。
  • 返回值解释:
    • bool:恒为true,表示执行成功。
  • 业务逻辑:
    • 调用内部函数_transfer(msg.sender, to, amount)执行余额扣减与增加。
    • 不修改授权额度_allowances,也不影响totalSupply。
    • 成功后由内部函数触发Transfer事件。
  • 注意事项:
    • 若to为零地址则回退(错误信息:"zero address")。
    • 若调用者余额不足则回退(错误信息:"insufficient balance")。
    • 支持自转账(from == to),余额净效为0,但仍会发出Transfer事件。
    • 由于内部使用unchecked进行算术操作,加法存在理论溢出风险(见_transfer说明),应确保不会出现极端溢出情形。
    • 函数不包含手续费、黑名单、暂停等控制逻辑。

函数:approve(address spender, uint256 amount)

  • 函数功能概述:
    • 设置/覆盖调用者(msg.sender)授予spender的可用代币额度为amount,并触发Approval事件。
  • 参数说明:
    • spender (address):被授权可代扣代币的地址。
    • amount (uint256):授权额度。
  • 返回值解释:
    • bool:恒为true,表示执行成功。
  • 业务逻辑:
    • 直接写入_allowances[msg.sender][spender] = amount。
    • 触发Approval(msg.sender, spender, amount)事件。
  • 注意事项:
    • 未限制spender为零地址;对零地址授权通常无实际用途,但不会回退。
    • 存在经典的ERC20“非原子修改授权”前置交易风险:从非零额度直接修改为另一非零额度可能被前置交易利用。建议先将额度设为0,再设置新额度;或提供increase/decreaseAllowance(本合约未提供)。
    • 不校验当前余额,授权与实际余额无关。

函数:transferFrom(address from, address to, uint256 amount)

  • 函数功能概述:
    • 在授权机制下,由调用者(msg.sender)从from地址向to地址转账amount,成功后扣减调用者对from的授权额度。
  • 参数说明:
    • from (address):被代扣的地址(代币持有人)。
    • to (address):接收代币的地址,必须为非零地址。
    • amount (uint256):转账数量。
  • 返回值解释:
    • bool:恒为true,表示执行成功。
  • 业务逻辑:
    • 读取当前授权currentAllowance = _allowances[from][msg.sender]。
    • 要求currentAllowance >= amount,否则回退(错误信息:"allowance too low")。
    • 扣减授权:_allowances[from][msg.sender] = currentAllowance - amount(在require保证下安全)。
    • 调用内部函数_transfer(from, to, amount)进行余额变更与事件触发。
  • 注意事项:
    • 不触发授权变更(Approval)事件来同步扣减后的授权额度,这与部分实现(会在transferFrom中发Approval事件)不同,可能影响依赖事件追踪授权的索引服务。
    • 未实现“无限授权”(如type(uint256).max时不扣减)的优化逻辑,本实现会始终扣减额度。
    • 未限制from为零地址;若零地址存在余额且已授权,则可被转出(通常生产级ERC20会避免零地址持有余额)。
    • 受_transfer中unchecked算术的潜在溢出注意(见_transfer说明)。
    • to为零地址将回退("zero address");from余额不足将回退("insufficient balance")。

函数:balanceOf(address account)

  • 函数功能概述:
    • 查询指定账户的当前代币余额。
  • 参数说明:
    • account (address):被查询的账户地址。
  • 返回值解释:
    • uint256:account地址的当前余额。
  • 业务逻辑:
    • 直接返回_balances[account],为视图函数,不修改状态。
  • 注意事项:
    • 支持查询任意地址(包括零地址)的余额。
    • 返回值未与totalSupply进行任何一致性校验(本合约片段未展示铸造/销毁等逻辑)。

函数:_transfer(address from, address to, uint256 amount) [internal]

  • 函数功能概述:
    • 执行内部转账的核心逻辑:校验、更新余额并触发Transfer事件。
  • 参数说明:
    • from (address):扣款地址。
    • to (address):收款地址,必须为非零地址。
    • amount (uint256):转账数量。
  • 返回值解释:
    • 无返回值。
  • 业务逻辑:
    • 校验to != address(0),否则回退("zero address")。
    • 读取from当前余额bal = _balances[from]。
    • 要求bal >= amount,否则回退("insufficient balance")。
    • 在unchecked块中执行:
      • _balances[from] = bal - amount;
      • _balances[to] += amount;
    • 触发Transfer(from, to, amount)事件。
  • 注意事项:
    • 算术在unchecked块中执行:在已校验余额充足的前提下,from侧不会下溢;但to侧的加法存在理论上溢出风险(若to余额接近uint256上限)。通常应通过总量不超过uint256上限且无异常铸造来保证安全,或避免对加法使用unchecked。
    • 未限制from为零地址;若零地址存在余额,则可被转出。
    • 允许自转账(from == to),净余额不变但仍会触发事件。
    • 不修改totalSupply,也未包含钩子(如before/after transfer)、暂停、黑名单等控制逻辑。

Function: deposit(uint64 lockSeconds) external payable returns (uint256 id)

  • Function Overview:

    • Accepts ETH and creates a time-locked deposit for the caller. The deposit is identified by a per-user index (id) and becomes withdrawable after the specified lock duration.
  • Parameters:

    • lockSeconds (uint64): Number of seconds to lock the deposited ETH. A value of 0 means the deposit is immediately withdrawable.
  • Return Values:

    • id (uint256): The zero-based index of this deposit within deposits[msg.sender]. It is unique per user but not globally unique.
  • Business Logic:

    • Validates that msg.value > 0; otherwise reverts with "no value".
    • Computes unlockAt = block.timestamp + lockSeconds and stores:
      • amount: uint128(msg.value)
      • unlockAt: uint64(block.timestamp + lockSeconds)
      • withdrawn: false
    • Appends the new record to deposits[msg.sender] and returns its index.
    • Emits Deposited(user=msg.sender, id, amount=msg.value, unlockAt).
  • Notes and Constraints:

    • The amount is stored as uint128. Extremely large deposits that do not fit into 128 bits would be truncated in Solidity; while practically unreachable on mainnet due to supply limits, callers should assume the system expects typical ETH-sized values.
    • unlockAt is stored as uint64. The sum block.timestamp + lockSeconds is cast to uint64; theoretical wrap-around would require astronomically large values.
    • The lock uses block.timestamp, which is subject to minor miner/validator manipulation; this is generally acceptable for timelocks but should be noted.
    • There is no upper bound or minimum on lockSeconds enforced by the contract; application-level validation can be added if needed.
    • The id is local to each user (deposits[msg.sender]); it is not a global counter.

Function: withdraw(uint256 id, address payable to) external nonReentrant

  • Function Overview:

    • Withdraws the caller’s matured deposit identified by id and sends the ETH to the specified recipient address.
  • Parameters:

    • id (uint256): Index of the caller’s deposit in deposits[msg.sender]. If out of bounds, the call reverts due to array indexing.
    • to (address payable): Recipient address for the withdrawn ETH. Can be any payable address.
  • Return Values:

    • None.
  • Business Logic:

    • Loads the deposit at deposits[msg.sender][id]; out-of-range indices revert automatically.
    • Requires the deposit has not been withdrawn; otherwise reverts with "already withdrawn".
    • Requires the current timestamp >= unlockAt; otherwise reverts with "still locked".
    • Marks the deposit as withdrawn and zeroes the stored amount (checks-effects-interactions).
    • Performs a low-level call to to with the withdrawn amount: (bool ok, ) = to.call{value: amount}("");
    • Reverts with "send failed" if the transfer fails (the state changes are rolled back on failure).
    • Emits Withdrawn(user=msg.sender, id, amount, to).
  • Notes and Constraints:

    • Reentrancy:
      • The function is protected by the nonReentrant modifier, and state is updated before the external call, adhering to CEI. This mitigates reentrancy even though .call forwards all remaining gas to the recipient.
    • Recipient address:
      • to can be any address, including contracts and address(0). Sending to address(0) is allowed and effectively burns the funds; callers should ensure the correctness of the recipient address.
    • Access control:
      • Only the depositor (msg.sender) can withdraw their own deposits; one cannot withdraw deposits belonging to other addresses.
    • Partial withdrawals:
      • Not supported. Each deposit is all-or-nothing; once withdrawn, it is marked as withdrawn and the amount is set to 0.
    • Error behavior:
      • If the external call fails, the entire transaction reverts and the deposit remains unchanged (not marked withdrawn, amount not zeroed) due to atomicity of state changes on revert.

以下为合约中两个函数的专业技术注释(简洁格式):

函数:castVote(uint256 id, bool support, uint128 weight)

  • 函数功能概述:
    • 记录投票:根据调用者传入的支持/反对标志,将对应提案的赞成票或反对票权重累加。
  • 参数说明:
    • id (uint256):提案标识,对应 proposals 映射的键。若该 id 尚未初始化,将使用默认值 Proposal 结构(proposer=address(0)、startBlock=0、endBlock=0、票数为0)。
    • support (bool):投票倾向;true 为赞成票,false 为反对票。
    • weight (uint128):本次投票的权重,将直接累加到对应的票数字段。
  • 返回值解释:
    • 无返回值。
  • 业务逻辑:
    • 若 support 为 true,则将 weight 累加到 proposals[id].forVotes;否则累加到 proposals[id].againstVotes。
    • 不做任何权限、时间窗口或提案有效性检查。
  • 注意事项:
    • 无时间校验:未使用 Proposal 的 startBlock/endBlock,任何区块均可投票(包括投票期外)。
    • 无重复投票防护:未记录投票人或投票状态;同一地址可多次调用累积权重。
    • 权重来源未校验:weight 完全由外部传入,未与代币余额/快照/委托等机制绑定;需要上层逻辑确保权重的正确性与唯一性。
    • 溢出与回退:forVotes/againstVotes 为 uint128;Solidity 0.8+ 下若累加超过 uint128 上限将导致交易回退。
    • 提案存在性:对于未初始化的 id 也可累计票数,可能导致“空提案”被后续结算;需在外部流程中规范提案创建与校验。

函数:finalizeProposal(uint256 id)

  • 函数功能概述:
    • 结算提案:在投票结束后,根据总投票数与法定人数(quorum)判断提案是否通过,标记为已执行并触发事件。
  • 参数说明:
    • id (uint256):提案标识,对应 proposals 映射的键。
  • 返回值解释:
    • 无返回值。通过事件 Finalized(id, passed) 对外公布结算结果。
  • 业务逻辑:
    • 读取存储中的 Proposal p = proposals[id]。
    • 要求当前区块号大于 p.endBlock;要求 p.executed 为 false。
    • 计算 total = uint256(p.forVotes) + uint256(p.againstVotes)。
    • 计算法定人数是否达成:quorum = (total * 100) >= (totalVotingPower * quorumPercent)。
    • 判定是否通过:passed = quorum && (p.forVotes > p.againstVotes)。
    • 将 p.executed 置为 true。
    • 若通过,预留执行提案相关动作的位置(代码占位)。
    • 触发事件 Finalized(id, passed)。
  • 注意事项:
    • 起止时间校验不完整:仅检查结束块 endBlock,未检查 startBlock;配合 castVote 的“无时间限制”,可能出现未开始即投票或 endBlock=0 时可立即结算的情况。
    • 提案存在性:对未初始化的提案(默认值,endBlock=0)在区块号>0时可被结算;应在 finalize 前校验 proposer、元数据或专门的存在标记。
    • 法定人数参数约定:quorumPercent 视为百分比(建议范围 0–100),但合约未强制限制;若设置>100,将提高达标门槛;若 totalVotingPower=0,则 quorum 恒为真,可能导致任意票数即可达标。
    • 票数比较策略:使用严格大于号(forVotes > againstVotes),平票视为未通过。
    • 溢出与安全:forVotes/againstVotes 为 uint128,提升为 uint256 后参与运算;total*100 在当前票数范围内安全。若 totalVotingPower 与 quorumPercent 极端偏大,右侧乘法可能接近上限,建议在设置时施加范围约束或改用更稳健的比例计算。
    • 交互顺序与重入:先标记 executed 再执行外部动作(占位),遵循检查-效果-交互模式。实际接入外部调用时建议加入重入保护与失败处理策略。
    • 事件与可观测性:仅在 finalize 时触发事件;castVote 无事件,可能影响离线索引与审计。建议为投票行为增加事件以提升可追溯性。

示例详情

📖 如何使用

30秒出活:复制 → 粘贴 → 搞定
与其花几十分钟和AI聊天、试错,不如直接复制这些经过千人验证的模板,修改几个 {{变量}} 就能立刻获得专业级输出。省下来的时间,足够你轻松享受两杯咖啡!
加载中...
💬 不会填参数?让 AI 反过来问你
不确定变量该填什么?一键转为对话模式,AI 会像资深顾问一样逐步引导你,问几个问题就能自动生成完美匹配你需求的定制结果。零门槛,开口就行。
转为对话模式
🚀 告别复制粘贴,Chat 里直接调用
无需切换,输入 / 唤醒 8000+ 专家级提示词。 插件将全站提示词库深度集成于 Chat 输入框。基于当前对话语境,系统智能推荐最契合的 Prompt 并自动完成参数化,让海量资源触手可及,从此彻底告别"手动搬运"。
即将推出
🔌 接口一调,提示词自己会进化
手动跑一次还行,跑一百次呢?通过 API 接口动态注入变量,接入批量评价引擎,让程序自动迭代出更高质量的提示词方案。Prompt 会自己进化,你只管收结果。
发布 API
🤖 一键变成你的专属 Agent 应用
不想每次都配参数?把这条提示词直接发布成独立 Agent,内嵌图片生成、参数优化等工具,分享链接就能用。给团队或客户一个"开箱即用"的完整方案。
创建 Agent

✅ 特性总结

一键为合约函数生成结构化注释,覆盖功能概述、参数含义、返回解释,团队快速对齐理解
自动识别业务逻辑并用通俗表述展现流程,帮助新人上手与评审讨论更聚焦
内置安全注意提示,自动标注边界条件与潜在风险,减少上线事故与审计返工
支持多语言注释与风格定制,满足开源与内部代码库的不同规范需求
针对旧代码一键补文档,智能回溯变量与调用关系,提升维护与交接效率
生成可复制的标准段落模板,方便团队统一注释口径,降低跨协作沟通成本
适配主流Solidity写法与常见合约模式,自动补充必要说明,提升可读性
与代码审查流程结合,评审时即时补注释与风险点记录,提升合规透明度

🎯 解决的问题

把零散的智能合约代码,快速转化为“可读、可审、可协作”的专业注释。通过一条高质量提示词,让 AI 以合约注释专家的视角工作:自动识别函数意图、提炼业务逻辑、补充参数与返回值说明、标注安全与约束要点,并统一注释风格与语言。适用于新功能开发、遗留代码补文档、审计前梳理、开源仓库规范化与团队交接等场景,帮助团队在更短时间内产出更高质量的注释,提升代码评审效率、降低沟通成本,推动审计与上线进度。使用方式简单:粘贴合约代码,选择注释语言与风格,即刻生成可直接粘贴入库的标准化注释,预期节省大量文档人力并显著提升协作体验。

🕒 版本历史

当前版本
v2.1 2024-01-15
优化输出结构,增强情节连贯性
  • ✨ 新增章节节奏控制参数
  • 🔧 优化人物关系描述逻辑
  • 📝 改进主题深化引导语
  • 🎯 增强情节转折点设计
v2.0 2023-12-20
重构提示词架构,提升生成质量
  • 🚀 全新的提示词结构设计
  • 📊 增加输出格式化选项
  • 💡 优化角色塑造引导
v1.5 2023-11-10
修复已知问题,提升稳定性
  • 🐛 修复长文本处理bug
  • ⚡ 提升响应速度
v1.0 2023-10-01
首次发布
  • 🎉 初始版本上线
COMING SOON
版本历史追踪,即将启航
记录每一次提示词的进化与升级,敬请期待。

💬 用户评价

4.8
⭐⭐⭐⭐⭐
基于 28 条评价
5星
85%
4星
12%
3星
3%
👤
电商运营 - 张先生
⭐⭐⭐⭐⭐ 2025-01-15
双十一用这个提示词生成了20多张海报,效果非常好!点击率提升了35%,节省了大量设计时间。参数调整很灵活,能快速适配不同节日。
效果好 节省时间
👤
品牌设计师 - 李女士
⭐⭐⭐⭐⭐ 2025-01-10
作为设计师,这个提示词帮我快速生成创意方向,大大提升了工作效率。生成的海报氛围感很强,稍作调整就能直接使用。
创意好 专业
COMING SOON
用户评价与反馈系统,即将上线
倾听真实反馈,在这里留下您的使用心得,敬请期待。
加载中...
📋
提示词复制
在当前页面填写参数后直接复制: