气体需求有问题

发布于 2025-01-20 16:26:50 字数 1397 浏览 4 评论 0原文

我已经编写了一个智能合约,我正在尝试执行以下代码,但我遇到了这些问题: 1-“函数 EKM.register_PK 的 Gas 需求是无限的:如果函数的 Gas 需求高于区块 Gas 限制,则该函数无法执行。请避免在修改大面积存储的函数或操作中出现循环(这包括清除或复制存储中的数组) 时间:32:0:” 2-“如果您永远不希望 x 为假,则使用“assert(x)”,而不是在任何情况下(除了代码中的错误)。如果 x 可能为假,则使用“require(x)”,因为例如输入无效或外部组件发生故障。 更多的 位置:30:2:” 我的代码:

pragma solidity >=0.8.13;
//SPDX-License-Identifier:MIT
contract EKM{
    /**
 * @dev VTA is a state variable
 */
address public VTA;
 /**
   * @dev mapping address as key to struct user with mapping name users
   */
mapping (uint => user) public users;
/**
     * @dev assigning the contract deployer as the  VTA
     */
    constructor() {
       VTA =msg.sender;
       }
        
       
struct user {

string PKname;
string PKvehicle;
uint256 vP; 
bool status;                    
     }
     
  event addPK(string name, string PKv, uint256 VPv) ;  
function register_PK(uint ID_v, string memory PKname, string memory PKvehicle, uint256 vP) public returns(bool){
  require(users[ID_v].status == true,"register the public key of the user");
  if(msg.sender != VTA)
  {revert();}
    if(ID_v == 0)
    {return false;}
    else
    {
         ID_v++;
    users[ID_v]= user(PKname,PKvehicle,vP,true);
   
    //PKname=users[ID_v].PKname;
    //PKvehicle=users[ID_v].PKvehicle;
   // vP=users[ID_v].vP;
      emit addPK(PKname, PKvehicle, vP);
    return true;
    }
   }

}

我应该做什么?

I have been written a smart contract, I am trying to execute the following code but I have these problems:
1- "Gas requirement of function EKM.register_PK is infinite: If the gas requirement of a function is higher than the block gas limit, it cannot be executed. Please avoid loops in your functions or actions that modify large areas of storage (this includes clearing or copying arrays in storage)
Pos: 32:0:"
2- "Use "assert(x)" if you never ever want x to be false, not in any circumstance (apart from a bug in your code). Use "require(x)" if x can be false, due to e.g. invalid input or a failing external component.
more
Pos: 30:2:"
My code:

pragma solidity >=0.8.13;
//SPDX-License-Identifier:MIT
contract EKM{
    /**
 * @dev VTA is a state variable
 */
address public VTA;
 /**
   * @dev mapping address as key to struct user with mapping name users
   */
mapping (uint => user) public users;
/**
     * @dev assigning the contract deployer as the  VTA
     */
    constructor() {
       VTA =msg.sender;
       }
        
       
struct user {

string PKname;
string PKvehicle;
uint256 vP; 
bool status;                    
     }
     
  event addPK(string name, string PKv, uint256 VPv) ;  
function register_PK(uint ID_v, string memory PKname, string memory PKvehicle, uint256 vP) public returns(bool){
  require(users[ID_v].status == true,"register the public key of the user");
  if(msg.sender != VTA)
  {revert();}
    if(ID_v == 0)
    {return false;}
    else
    {
         ID_v++;
    users[ID_v]= user(PKname,PKvehicle,vP,true);
   
    //PKname=users[ID_v].PKname;
    //PKvehicle=users[ID_v].PKvehicle;
   // vP=users[ID_v].vP;
      emit addPK(PKname, PKvehicle, vP);
    return true;
    }
   }

}

what should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟燃烟灭 2025-01-27 16:26:50

进行坚固的静态分析,然后进行天然气和经济,除非除外。这是在本地呼叫上:
通过“ this”和Delete Dynamic Array调用本地功能:
使用/断言以确保删除。它将起作用

Go to solidity static analysis ,and then gas and economy , untick all options except. This on local calls:
Invocation of local functions via 'this' and Delete dynamic array:
Use require/assert to ensure complete deletion. it will work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文