安全智能合约工具:端到端开发人员指南
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 < 0.9.0;
/// @title A simulator for trees
/// @author Larry A. Gardner
/// @notice You can use this contract for only the most basic simulation
contract Tree {
/// @notice Calculate tree age in years, rounded up, for live trees
/// @dev The Alexandr N. Tetearing algorithm could increase precision
/// @param rings The number of rings from dendrochronological sample
/// @return Age in years, rounded up for partial years
function age(uint256 rings) external virtual pure returns (uint256) {
return rings + 1;
}
}
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.10;
import "ds-test/test.sol";
import "../StakeContract.sol";
import "./mocks/MockERC20.sol";
contract StakeContractTest is DSTest {
StakeContract public stakeContract;
MockERC20 public mockToken;
function setUp() public {
stakeContract = new StakeContract();
mockToken = new MockERC20();
}
/// @notice Test token staking with different amount
function test_staking_tokens() public {
uint256 amount = 10e18;
mockToken.approve(address(stakeContract), amount);
bool stakePassed = stakeContract.stake(amount, address(mockToken));
assertTrue(stakePassed);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
error TransferFailed();
contract StakeContract {
mapping(address => uint256) public s_balances;
/// #if_succeeds {:msg "Stake created successfully"} $result == true;
function stake(uint256 amount, address token) external returns (bool){
s_balances[msg.sender] += amount;
bool success = IERC20(token).transferFrom(msg.sender, address(this), amount);
if (!success) revert TransferFailed();
return success;
}
}
来自Diligence Fuzzing活动示例的报告
原文链接:
https://dzone.com/articles/secure-smart-contract-tools-an-end-to-end-develope

关注公众号:拾黑(shiheibook)了解更多
[广告]赞助链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/

随时掌握互联网精彩
赞助链接
排名
热点
搜索指数
- 1 守住耕地这个命根子 7992848
- 2 “全球第一网红”也想来中国 7935771
- 3 国防部回应网友许愿苏超决赛飞战机 7957011
- 4 六部门联合划重点、指方向 7971494
- 5 暴雨蓝色预警:多省份大到暴雨 7942499
- 6 雷军:未交付SU7都可改配YU7 7971468
- 7 网警公布打击谣言8起典型案例 7949933
- 8 小米YU7标准版定价25.35万 7992811
- 9 丁俊晖因称“球桌像屎一样”遭罚款 7942898
- 10 原来刘亦菲吃饭也是手机先吃 7964030