当前位置: 首页 > news >正文

公务员做网站优化大师怎么强力卸载

公务员做网站,优化大师怎么强力卸载,设计本推荐,logo设计免费在线生成名称: memory滥用 https://github.com/XuHugo/solidityproject/tree/master/vulnerable-defi 描述: 在合约函数中滥用storage和memory。 memory是一个关键字,用于临时存储执行合约所需的数据。它保存函数的参数数据,并在执行后…

 名称:

memory滥用

https://github.com/XuHugo/solidityproject/tree/master/vulnerable-defi
描述:

在合约函数中滥用storage和memory。

memory是一个关键字,用于临时存储执行合约所需的数据。它保存函数的参数数据,并在执行后清除。
storage可以看作是默认的数据存储。它持久地保存数据,消耗更多的gas

函数updaterewardDebt的功能是,更新UserInfo结构体的rewardDebt值。为了节约gas,我们将变量用关键字memory声明了,这样会导致的问题是,在函数执行结束之后,rewardDebt的值并不会保存下来。因为一旦函数完成执行,内存就会被清除,所做的更改也会丢失。

参考:

Cover protocol hack analysis: Infinite Cover tokens minted via an exploit - Mudit Gupta's Blog

解决方法:

https://mudit.blog/cover-protocol-hack-analysis-tokens-minted-exploit/

proxy合约:

contract Array is Test {mapping(address => UserInfo) public userInfo; // storagestruct UserInfo {uint256 amount; // How many tokens got staked by user.uint256 rewardDebt; // Reward debt. See Explanation below.}function updaterewardDebt(uint amount) public {UserInfo memory user = userInfo[msg.sender]; // memory, vulnerable pointuser.rewardDebt = amount;}function fixedupdaterewardDebt(uint amount) public {UserInfo storage user = userInfo[msg.sender]; // storageuser.rewardDebt = amount;}
}

foundry测试合约;

// A function to demonstrate the difference between memory and storage data locations in Solidity.
function testDataLocation() public {// Simulate dealing 1 ether to Alice and Bob.address alice = vm.addr(1);address bob = vm.addr(2);vm.deal(address(alice), 1 ether);vm.deal(address(bob), 1 ether);// Create a new instance of the Array contract.ArrayContract = new Array();// Update the rewardDebt storage variable in the Array contract to 100.ArrayContract.updaterewardDebt(100); // Retrieve the userInfo struct for the contract's address and print the rewardDebt variable.// Note that the rewardDebt should still be the initial value, as updaterewardDebt operates on a memory variable, not the storage one.(uint amount, uint rewardDebt) = ArrayContract.userInfo(address(this));console.log("Non-updated rewardDebt", rewardDebt);// Print a message.console.log("Update rewardDebt with storage");// Now use the fixedupdaterewardDebt function, which correctly updates the storage variable.ArrayContract.fixedupdaterewardDebt(100);// Retrieve the userInfo struct again, and print the rewardDebt variable.// This time the rewardDebt should be updated to 100.(uint newamount, uint newrewardDebt) = ArrayContract.userInfo(address(this));console.log("Updated rewardDebt", newrewardDebt);
}

http://www.wangmingla.cn/news/129704.html

相关文章:

  • 国外对企业网站开发的研究一站式媒体发稿平台
  • 新疆炒菜哥李健教做新疆菜网站百度账号一键登录
  • 成都建设网站价格推广引流怎么做
  • 小型行业网站建设维护成本app优化建议
  • 找黄岩做网站企业跨境电商网站
  • 襄阳谷城网站开发备案域名购买
  • 江阴网站建设宁波seo网络推广报价
  • 建设银行网站的特点网站制作的流程
  • 为什么不建议做运维百合seo培训
  • 老外做牛排的视频网站农产品网络营销推广方案
  • 菜鸟学做网站的步骤游戏优化大师手机版
  • 用rp怎样做网站百度贴吧首页
  • 政府网站建设讲话seo零基础培训
  • 网站排名软件下载北京百度推广投诉电话
  • 网站建设报价明细沈阳关键词seo排名
  • 成都网站建设 培训班凡科建站
  • 杭州市区网站制作单位百度统计数据
  • 网站建设与维护设计报告百度网盘资源搜索引擎入口
  • 如何做网站好看计算机培训班培训费用
  • 网络科技有限公司靠谱吗网络优化的内容包括哪些
  • 电影网站模板html发布推广信息的网站
  • 网站运行时错误如何做深圳企业黄页网
  • 网站建设报什么专业谷歌推广怎么做
  • 公司网站建设付款分录优化seo可以从以下几个方面进行
  • 百度提交入口网站网址软文推广发布
  • 三网获客大数据获客营销软件seo是什么意思知乎
  • 做房产抵押网站需要什么手续推广方案是什么
  • 上海门户网站制作世界最新新闻
  • 服装印花图案网站推广普通话内容
  • it培训四个月骗局宁德seo培训