Analise smart-contract
03.04.2024

具有暂停功能的智能合约

我们继续致力于描述智能合约中的欺诈方案系列文章。今天我们将分析具有暂停功能的智能合约。

具有暂停功能的智能合约提供了在合约内部暂时或永久停止某些操作或功能的能力。尽管暂停功能对安全性和维护有用,但如果被欺诈者利用,也会带来潜在风险。为了保护自己并识别潜在威胁,您需要了解风险、常见的欺诈方案以及如何在智能合约中识别它们。

具有暂停功能的智能合约的危险性:

  • 未经授权的暂停:欺诈者可以控制暂停功能并未经适当授权停止合约,这可能导致业务中断或财务损失。

  • 欺诈性延迟:恶意合约可能在临时维护或安全措施的名义下暂停关键交易,如提款或转账,目的是拒绝用户访问其资产。

  • 虚假紧急声明:欺诈者可能虚假宣称紧急情况或漏洞,以此来合理化暂停合约,并在暂停期间使用用户的资金。

  • 安全借口:恶意合约可能声称发现了安全漏洞,从而激活暂停功能。实际上,欺诈者可能意图利用这种情况。

  • 紧急方案:欺诈者可能使用恐吓性语言或场景,如声称“入侵企图”或“紧急情况”,以此来合理化暂停操作,在此期间他们可能进行非法行为。

您如何独立确定智能合约中是否存在这些威胁?

如果您希望自行确定智能合约中是否存在暂停功能,以下提示将有助于您实现这一目标。

  1. 检查合约的源代码,查看是否存在暂停功能。确保暂停机制有良好的文档记录并具有适当的访问控制。

  2. 查明谁控制暂停功能。未经授权或未经检查地拥有暂停功能可能会带来潜在问题。

  3. 阅读文档和项目规范,确保它们提供关于暂停功能、其目的及可能使用情况的清晰准确信息。

  4. 关注暂停功能的透明性使用。确保有明确的管理程序,并决定何时激活或停用暂停功能。

  5. 关注智能合约安全的外部审计,特别是暂停机制。审计人员应评估暂停功能的安全性和透明性。

  6. 观察合约的行为,并确保暂停功能仅在合理情况下激活,例如维护或安全原因。

  7. 参与项目社区和其他用户,了解他们对使用暂停功能的经验和关注点。

  8. 保持与我们社区(Telegram 频道)的最新发展和防欺诈最佳实践(我们的博客和YouTube频道)保持同步。

要检测暂停智能合约中的潜在恶意功能,您必须进行尽职调查,仔细审查项目的代码和文档。避免与行为可疑或在暂停功能使用方面缺乏透明度的合约交互。

Lotus Market 的安全扫描器在99.9%的时间内能够发现所有常见(包括隐藏的)暂停功能。使用我们的高级订阅,保护您的资金免受威胁。

接下来,我们将看一下 Lotus Market 平台成功发现的一些暂停功能的最常见示例。

independently determine

示例 1:基本暂停功能



    contract BasicPauseToken {
      address public owner;
      bool public paused;
  
      constructor() {
          owner = msg.sender;
          paused = false;
      }
  
      modifier whenNotPaused() {
          require(!paused, "Contract is paused");
          _;
      }
  
      function pause() public {
          require(msg.sender == owner, "Only the owner can pause");
          paused = true;
      }
  
      function unpause() public {
          require(msg.sender == owner, "Only the owner can unpause");
          paused = false;
      }
  
      function transfer(address to, uint256 amount) public whenNotPaused {
          // Transfer logic when the contract is not paused
      }
  }
    

识别提示: 查找具有暂停和取消暂停功能或类似功能的合约,可以切换暂停状态。

检查应用于某些函数的 whenNotPaused 类型修饰符,确保只有在合约未暂停时才能执行这些函数。

检查访问控制机制,只允许所有者或授权人员暂停和取消暂停合约。

示例 2:时间激活的暂停


    contract TimeActivatedPauseToken {
      address public owner;
      bool public paused;
      uint256 public pauseStartTime;
      uint256 public pauseDuration;
  
      constructor(uint256 _duration) {
          owner = msg.sender;
          paused = false;
          pauseStartTime = 0;
          pauseDuration = _duration;
      }
  
      modifier whenNotPaused() {
          require(!paused, "Contract is paused");
          _;
      }
  
      function pause() public {
          require(msg.sender == owner, "Only the owner can pause");
          paused = true;
          pauseStartTime = block.timestamp;
      }
  
      function unpause() public {
          require(msg.sender == owner, "Only the owner can unpause");
          require(block.timestamp >= pauseStartTime + pauseDuration, "Pause duration not over");
          paused = false;
      }
  
      function transfer(address to, uint256 amount) public whenNotPaused {
          // Transfer logic when the contract is not paused
      }
  }
  

识别提示: 查找具有时间激活暂停机制的合约,在此机制中,暂停和取消暂停具有特定的持续时间。

检查是否有应用于某些函数的 whenNotPaused 类型修饰符。确保合约执行暂停持续时间,并且只能在经过指定时间段后取消暂停。

在识别智能合约中的暂停功能时,审查代码、访问控制和暂停机制的目的至关重要。仔细查阅文档和合约管理模型,并与项目社区互动,评估合约的合法性和适用性。在进行涉及可暂停合约的任何交易或投资之前,务必谨慎行事,并进行尽职调查。

time-activated pause

示例 3:条件暂停功能


    contract ConditionalPauseToken {
      address public owner;
      bool public paused;
  
      constructor() {
          owner = msg.sender;
          paused = false;
      }
  
      modifier whenNotPaused() {
          require(!paused || msg.sender == owner, "Contract is paused");
          _;
      }
  
      function pause() public {
          require(msg.sender == owner, "Only the owner can pause");
          paused = true;
      }
  
      function unpause() public {
          require(msg.sender == owner, "Only the owner can unpause");
          paused = false;
      }
  
      function transfer(address to, uint256 amount) public whenNotPaused {
          // Transfer logic when the contract is not paused, except for the owner
      }
  }
  

识别提示: 查找具有条件暂停机制的合约,允许所有者即使在合约暂停时执行某些交易。

检查是否有应用于需要合约处于非暂停状态的函数的 whenNotPaused 类型修饰符。

示例 4:紧急暂停功能


    contract EmergencyPauseToken {
      address public owner;
      bool public paused;
  
      constructor() {
          owner = msg.sender;
          paused = false;
      }
  
      modifier whenNotPaused() {
          require(!paused || msg.sender == owner, "Contract is paused");
          _;
      }
  
      function pause() public {
          require(msg.sender == owner, "Only the owner can pause");
          paused = true;
      }
  
      function emergencyPause() public {
          require(msg.sender == owner, "Only the owner can initiate emergency pause");
          paused = true;
      }
  
      function unpause() public {
          require(msg.sender == owner, "Only the owner can unpause");
          paused = false;
      }
  
      function transfer(address to, uint256 amount) public whenNotPaused {
          // Transfer logic when the contract is not paused, except for the owner
      }
  }
  

识别提示: 查找具有紧急暂停功能的合约,允许所有者即使在没有标准暂停程序的情况下立即暂停合约。

检查是否有应用于需要合约处于非暂停状态的函数的 whenNotPaused 类型修饰符。

关注合约的紧急暂停功能,并确保其使用受到严格控制和良好记录。

将合约的暂停功能与其治理模型和决策过程相匹配,以激活和停用暂停功能。

示例 5:有时间限制的所有者控制暂停


    contract TimedPauseToken {
      address public owner;
      bool public paused;
      uint256 public pauseStartTime;
      uint256 public pauseDuration;
  
      constructor(uint256 _duration) {
          owner = msg.sender;
          paused = false;
          pauseStartTime = 0;
          pauseDuration = _duration;
      }
  
      modifier whenNotPaused() {
          require(!paused, "Contract is paused");
          _;
      }
  
      function pause() public {
          require(msg.sender == owner, "Only the owner can pause");
          paused = true;
          pauseStartTime = block.timestamp;
      }
  
      function unpause() public {
          require(msg.sender == owner, "Only the owner can unpause");
          require(block.timestamp >= pauseStartTime + pauseDuration, "Pause duration not over");
          paused = false;
      }
  
      function transfer(address to, uint256 amount) public whenNotPaused {
          // Transfer logic when the contract is not paused
      }
  }
  

识别提示: 查找具有所有者控制的暂停功能的合约,包括具有特定暂停和取消暂停的持续时间。

检查是否有应用于适当函数的 whenNotPaused 类型修饰符,以限制在合约暂停时的操作。

owner-controlled pause with time limit

示例 6:带有时间限制的第三方暂停功能


    contract ThirdPartyTimedPauseToken {
      address public owner;
      address public thirdParty;
      bool public paused;
      uint256 public pauseStartTime;
      uint256 public pauseDuration;
  
      constructor(address _thirdParty, uint256 _duration) {
          owner = msg.sender;
          thirdParty = _thirdParty;
          paused = false;
          pauseStartTime = 0;
          pauseDuration = _duration;
      }
  
      modifier whenNotPaused() {
          require(!paused || msg.sender == owner || msg.sender == thirdParty, "Contract is paused");
          _;
      }
  
      function pause() public {
          require(msg.sender == thirdParty, "Only the third party can pause");
          paused = true;
          pauseStartTime = block.timestamp;
      }
  
      function unpause() public {
          require(msg.sender == thirdParty, "Only the third party can unpause");
          require(block.timestamp >= pauseStartTime + pauseDuration, "Pause duration not over");
          paused = false;
      }
  
      function transfer(address to, uint256 amount) public whenNotPaused {
          // Transfer logic when the contract is not paused, except for the owner and the third party
      }
  }
  

识别提示: 查找具有第三方管理的暂停机制的合约,其中第三方可以在设置的持续时间内暂停和解除合约。

检查是否有应用于合约暂停时限制操作的 whenNotPaused 类型修饰符。

确保合约中用于暂停功能的访问控制机制,无论是所有者拥有、社区管理还是第三方管理,都是透明且设计良好的。

一旦在智能合约中发现暂停功能,应进行彻底的代码分析,测试访问控制,并理解暂停机制的目的和控制模型。进行尽职调查并与项目社区互动,评估合约的合法性和是否适合特定用途至关重要。在进入提供暂停选项的合约之前,务必谨慎行事并进行适当的研究,以减少潜在风险。

 

希望这些示例能帮助您更好地理解智能合约中的暂停功能原理。

 

 

由于区块链上的所有信息都是公开的(当然,前提是合约的源代码已经经过验证),凭借这些知识,您可以独立研究智能合约并识别各种欺诈方案。

 

不过,我们已经为您做好了一切!注册高级订阅,获取智能合约功能和最新分析的独家过滤器访问权限。提高您成功投资有利可图代币的机会。

祝好,Lotus Market团队。

All posts

Connect to a wallet

Metamask