跳到主要内容

20 篇文档带有标签「Security」

查看所有标签

ERC20 转账问题

ERC20 转账问题是智能合约中常见的漏洞来源。 这些问题源于 ERC20 标准实现的不一致性,特别是不同代币如何处理转账函数的返回值。

Flashloan Governance Attacks

闪电贷是一种强大的去中心化金融(DeFi)功能,允许用户在无需抵押的情况下借入资产,前提是他们在同一交易中归还借入的金额。 This feature has enabled unique financial strategies, but it also poses significant risks for governance systems.

msg.value in Loops

在开发智能合约时,安全性是最关键的考虑因素之一。 本教程将深入探讨一个常见但危险的模式:在循环中使用msg.value。 We'll explain why this is dangerous and provide some best practices to avoid related vulnerabilities.

Selector Collision Attack

The selector collision attack was one of the key reasons behind the hacking of the Poly Network cross-chain bridge.

Tx Origin Attacks

A transaction origin attack is form of phising attack that can drain a contract of all funds.In Solidity, tx.origin retrieves the address of the transaction originator, distinguishing it from msg.sender.

不当的输入验证

如果访问控制是关于控制谁调用函数,那么输入验证就是要控制他们用什么参数来调用合约。 这一般归结为忘记放置恰当的require语句。

价格操纵

Price manipulation poses a significant risk to smart contracts that utilize decentralized exchanges (DEXs) like Uniswap, where asset prices are influenced by the liquidity within trading pools. These pools are vulnerable to manipulation by well-resourced entities capable of altering market balances to artificially influence prices. Such manipulative actions can severely undermine the functionality and security of financial applications that rely on this pricing data for essential operations.

余额核算

Smart contracts often maintain state variables that track balances. However, direct transfers not mediated by contract functions (like direct Ether sends to a contract address or transfer calls for ERC20 tokens that bypass the contract's logic) can create discrepancies between the actual balance held by the contract and the balance recorded in the contract’s internal state variables.

安全的向下转换

在 Solidity 中,安全地将较大的整数类型向下转换为较小的类型可能会带来风险,尤其是在 0.8.0 之前的版本中,因为这些版本缺乏自动溢出检查。 本文将解释向下转换的风险,提供一个在旧版本 Solidity 中有问题的函数示例,并介绍如何使用诸如 SafeCast 之类的库来确保操作安全。 尽管 Solidity 0.8.0 及以后的版本已经内置了溢出检查,但使用 SafeCast 仍然可以提高代码的清晰度和安全性。

拒绝服务攻击

2022年4月,一家名为Akutar的热门NFT项目成功地进行了一次 荷兰式拍卖筹集了11,539.5个ETH。 However, when processing refunds for previous community pass holders, a flaw in their smart contract prevented operations, locking all funds within the contract due to a DoS vulnerability.

整数溢出

2018年4月,BeautyChain(BEC)代币上发生了一起涉及整数溢出漏洞的重大事件。 该漏洞使攻击者能够凭空生成大量的BEC代币,导致了巨额财务损失,并削弱了该代币的价值。

智能合约安全

确保智能合约的安全至关重要,因为它们涉及财产的直接处理与存储,并且一旦合约被部署在区块链上,就很难修改。 为了保护你的智能合约,遵循以下关键步骤和最优的实践方法:

未经检查的低级调用

未经检查的低级调用在智能合约开发中是常见的漏洞来源。 这些调用包括call(),delegatecall(),staticcall()和 send(),当它们失败时不会回滚交易,而是返回布尔值false。 未检查这些返回值可能导致严重的安全问题。

私有变量安全性

When developing smart contracts, it's crucial to understand that marking variables as private does not make them confidential. This tutorial explains why private variables are still accessible and provides best practices for handling sensitive information in smart contracts.

绕过智能合约检测

许多免费铸造的项目使用 isContract() 方法限制对外部账户(EOAs)的访问以及限制智能合约的交互。 此方法使用 extcodesize 来决定地址运行时 bytecode 长度。 如果大于零,则被视为智能合约;否则,它被视为EOA。

访问控制漏洞

智能合约的访问控制漏洞是导致 Poly Network 跨链桥黑客攻击(损失 6.11 亿美元)的主要因素之一,并且也导致了在币安智能链(BSC)上的 ShadowFi DeFi 项目遭受 30 万美元的黑客攻击。

过多的函数限制

智能合约中过度的函数限制可能导致严重的问题,例如资金被锁定,甚至在必要情况下也无法正确访问。 一个著名的例子是Akutars NFT事件,由于为了保证安全而采用了过度限制的合约机制,导致3400万美元的以太坊被困。

重入攻击

重入攻击是针对智能合约最常见的攻击类型之一,攻击者利用合约的漏洞递归调用合约,使其能够从合约中转移资产或者铸造大量的代币。