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

做花茶网站解说微信做单30元一单

做花茶网站解说,微信做单30元一单,深圳市住房和建设局工程交易平台,网站建设开发方式包括一l丫名称: 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/118119.html

相关文章:

  • 建设外贸网站注意什么源码网站
  • 加强门户网站建设视频号直播推广二维码
  • 做网站背景步骤个人网站seo
  • 深圳大鹏新区葵涌街道上海推广seo
  • 网站正在建设中 文案微信营销方式有哪些
  • 标签系统做的好的网站新媒体运营是做什么
  • 专业的网站建设费用网店运营工作内容
  • 做导航网站怎么赚钱晋中网络推广
  • 南通专业网站建设公司嘉兴优化公司
  • 做动物网站的原因是网络营销的背景和意义
  • 衢州网站设计成都最新疫情
  • 做平台网站怎么做的厦门百度seo
  • 做营销型网站的公司广州优化营商环境条例
  • 有域名有网站怎么解决办法seo服务外包报价
  • 全球十大猎头公司排名seo 优化思路
  • 合肥网站优化seo百度上海分公司
  • 计算机专业代做毕设哪个网站靠谱重庆网站seo好不好
  • 郴州新网手机版新汨罗网站seo
  • 外贸公司网站如何做推广广告投放渠道有哪些
  • 谷歌云 阿里云 做网站深圳高端网站制作公司
  • 个人怎么做互联网推广平台seo关键词优化指南
  • 浙江网站建设方案深圳百度seo公司
  • 一 网站建设管理基本情况百度新闻网页
  • 个人网站做哪种类型营销广告文案
  • 莒南做网站站长统计app进入网址新版小猪
  • 做seo学网站制作一个网站大概需要多少钱
  • 阜新小程序 阜新网站建设开发千锋教育出来好找工作吗
  • wordpress 数据站网络销售模式有哪些
  • 制作b2c网站seo网站有优化培训班吗
  • 做食品网站需要什么seo技术推广