安全智能合约工具:端到端开发人员指南
// 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 和人民在一起 7943844
- 2 柯洁被判负 7945069
- 3 警惕!今年第一场大寒潮或波及全国 7850641
- 4 今天明天 都是小年 7718301
- 5 王菲时隔7年再上春晚 将唱这首歌 7687534
- 6 女子称因未婚生育被取消村集体分红 7530892
- 7 公务员省考:学历要求越来越高 7453990
- 8 59岁陈慧娴演唱会上出意外 7331582
- 9 尹锡悦穿10号囚服 狱警叫他10号 7244992
- 10 造谣“董明珠停职” 5人被行政处罚 7121394