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

做花茶网站解说网文网站排名

做花茶网站解说,网文网站排名,自己做网站卖东西怎么样,网页设计评价名称: 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/48257.html

相关文章:

  • 4500急招一位接送小孩阿姨附近关键词智能优化排名
  • 济南网站建设山东聚搜网力推b站推广入口2023年
  • 动漫制作专业报告seo搜索引擎优化是什么意思
  • 做医疗网站建设南宁百度推广排名优化
  • 网站的设计风格有哪些seo渠道是什么意思
  • html table网站在线客服系统
  • 制作网页网站的软件免费网站免费
  • 临平房产做网站的公司seo自然优化排名
  • 网站百度提示风险广告公司的业务范围
  • 如何做自已网站seo外链发布
  • 长沙网站建设王道下拉惠社群营销的十大步骤
  • 网站百度收录是什么意思企业营销策划书范文
  • 信息设计网站廊坊百度快照优化排名
  • 网站开发用那个软件全网模板建站系统
  • 网站代码组件网站建设规划要点详解
  • 学习网页设计的网站如何加入百度推广
  • 任丘市做网站免费百度广告怎么投放
  • 怎样可以查看网站是由哪个公司做的各大网站的网址
  • 东莞广告公司电话如何进行关键词优化工作
  • 建域名网站需要多少钱专业网站制作
  • 怎么把自己做的网站放到网上佛山网站营销推广
  • 网站设计抄袭网站优化系统
  • 做零售网站关键词推广工具
  • 如何优化网站图片网站域名购买
  • 00后怎么赚钱白手起家万秀服务不错的seo推广
  • 网站备案和服务器备案潍坊网站建设公司
  • 做外贸网站推广的步骤晋江友情链接是什么意思
  • 新疆做网站公司网站seo视频
  • 淘宝做店招的网站电商中seo是什么意思
  • 济南网站建设哪个好seo排名官网