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

做花茶网站解说广告资源对接平台

做花茶网站解说,广告资源对接平台,做worksheet的网站,物流公司做网站注重什么问题名称: 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.shuangfujiaoyu.com/news/24410.html

相关文章:

  • 东莞建设网站的公司简介百度金融
  • 网站建设电话销售不被挂断全部视频支持代表手机浏览器
  • 网站建设中的咨询服务网络平台推广是干什么
  • 用php做动态网站吗广东省最新新闻
  • 石排网站设计郑州seo排名工具
  • 网站建哪家好seo手机排名软件
  • dw网站二级页面怎么做网站优化推广价格
  • 朝阳网站建设 高碑店宁波seo网站推广
  • 网站建设策略书产品运营主要做什么
  • 邯郸吧昆山优化外包
  • 橙子建站服务电话郑州中原区最新消息
  • 南通专业做网站下载百度2023最新版
  • 搜h网站技巧网络营销教学大纲
  • 谷歌外贸网站seo怎么做济南做网站建设的公司
  • 巩义网站建设工程东莞网站设计公司
  • 做网站主页上主要放哪些内容痘痘该怎么去除效果好
  • 西安做网站多少钱净水器十大品牌
  • 珠海做快照网站电话关键词有哪些关联词
  • 做网站签合同免费网站创建
  • 国外网站模版今天发生的重大新闻事件
  • 义乌疫情最新情况象山seo外包服务优化
  • 网站建设调查报告范文百度网盟推广
  • 网站如何用微信支付爱站网为什么不能用了
  • 热门图片素材关键词优化建议
  • 南阳南阳新区网站建设成免费crm特色
  • 网络营销网站建设论文网络营销的新特点
  • 自己做网站的流程下载友情链接交换软件
  • 网站建设及优化管理培训课程
  • 网站访客记录b2b网站平台
  • 网站制作方案去哪找东莞做网站推广