Skip to content

fix(evm): prevent uint64→int64 overflow in transfer path - #1303

Merged
33cn merged 5 commits into
33cn:masterfrom
bysomeone:fix/evm-uint64-overflow-in-transfer
Jul 30, 2026
Merged

fix(evm): prevent uint64→int64 overflow in transfer path#1303
33cn merged 5 commits into
33cn:masterfrom
bysomeone:fix/evm-uint64-overflow-in-transfer

Conversation

@bysomeone

@bysomeone bysomeone commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

修复 EVM 层 uint64→int64 整数溢出漏洞,阻止攻击者绕过余额检查零成本铸造 WBTY。

Attack

攻击者通过 protobuf varint 编码在 RPC 入口绕过 EvmContractCallReq.Amount (int64) 的限制,传入接近 2^64 的值。该值在 MemoryStateDB.CanTransfer 中被转换为 int64 时溢出为负数,导致余额检查恒成立,同时 Transfer 返回值被丢弃,合约以原始 uint64 值执行。

结果:攻击者零成本铸造 ~1844 亿 WBTY,随后 withdraw 兑走真 BTY。

Fix

所有校验放在资产操作的边界上,通过 ForkEVMFixOverflow 分叉控制生效。

4 个 commit:

Commit 内容
fc8888f 核心修复 — statedb/evm/exec/token 增加分叉保护的溢出检查和返回值检查
c0fecdf 跨链修复 — evmxgo recv+= 溢出保护,cross2eth IsInt64 检查
bce0afc 测试 — fork gate 单测 + 多签名 Exec 级 WBTY 攻击集成测试
1aa9c7e 文档 — 完整攻击链路分析 + 修复方案 + 审计报告

分叉保护点

位置 分叉前 分叉后
CanTransfer balance >= int64(amount) 溢出恒真 amount > MaxInt64 直接拒绝
evm.Call/Create 不检查 Transfer 返回值 检查返回值,失败回滚
exec.innerExec 不检查 Transfer 返回值 检查返回值
token precompile amount.Int64() 无保护 IsInt64 前置检查

无需分叉

  • Transfer 本身 value < 0 → false 分叉前后一致
  • AssembleChain33Tx 有精度转换保护

🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com

@bysomeone bysomeone changed the title fix(evm): prevent uint64→int64 overflow in transfer path WIP fix(evm): prevent uint64→int64 overflow in transfer path Jul 30, 2026
@bysomeone
bysomeone force-pushed the fix/evm-uint64-overflow-in-transfer branch from edc0120 to 0c8f7ef Compare July 30, 2026 03:05
bysomeone and others added 4 commits July 30, 2026 14:31
…ction

- types: ForkEVMFixOverflow constant and registration
- statedb.go: MaxInt64 guard in CanTransfer
- evm.go: check Transfer return value in Call()/Create(), revert on failure
- exec.go: check Transfer return value in transfer-only path
- token.go: IsInt64() guard in precompile transfer

Co-Authored-By: Claude <noreply@anthropic.com>
- evmxgo/transwithdraw.go: recv += overflow check
- cross2eth/chain33.go: IsInt64() check before Int64() in bridge amounts

Co-Authored-By: Claude <noreply@anthropic.com>
- statedb_test.go: fork-gate overflow protection unit tests
- attack_integration_test.go: multi-signer Exec-level WBTY attack simulation

Co-Authored-By: Claude <noreply@anthropic.com>
Complete documentation covering attack chain, root cause, fork control,
cross-chain audit findings, and defense-in-depth fix rationale.

Co-Authored-By: Claude <noreply@anthropic.com>
@bysomeone
bysomeone force-pushed the fix/evm-uint64-overflow-in-transfer branch from f8d4206 to 1aa9c7e Compare July 30, 2026 06:34
- chain33.para.toml: used by paracross/rollup/rgbx CI
- chain33.fork.toml: fork config base
- ci2/chain33.proxyminer.toml: used by evm2 proxyminer CI (non-local)

Co-Authored-By: Claude <noreply@anthropic.com>
@bysomeone
bysomeone force-pushed the fix/evm-uint64-overflow-in-transfer branch from e30730d to dd58a96 Compare July 30, 2026 07:45
@bysomeone bysomeone changed the title WIP fix(evm): prevent uint64→int64 overflow in transfer path fix(evm): prevent uint64→int64 overflow in transfer path Jul 30, 2026
@33cn
33cn merged commit 32f39ab into 33cn:master Jul 30, 2026
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants