-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Z24028003 HW Review #3
base: main
Are you sure you want to change the base?
Conversation
v1.7.6
v1.7.6
v1.7.6
* solidity ^0.8.20 * change ReentrancyGuard the openzeppelin url
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- DO NOT merge this branch to the main branch.
|
||
function mint(address to, uint256 amount) public { | ||
//Check that the calling account has the minter role | ||
if (!hasRole(DEPLOYER_ROLE, msg.sender)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can simply declare an owner variable and assign msg.sender
to it in constructor
vm.startBroadcast(); | ||
MyToken Mt = new MyToken(); | ||
vm.stopBroadcast(); | ||
return Mt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no necessity to return any value in the run()
function.
assertEq(myToken.balanceOf(user2), 11 ether); | ||
assertEq(myToken.balanceOf(user3), 11 ether); | ||
|
||
console2.log(myToken.balanceOf(deployer)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log some messages to describe the variables you log for easy understanding.
function mint(address to, uint256 amount) public { | ||
//Check that the calling account has the minter role | ||
if (!hasRole(DEPLOYER_ROLE, msg.sender)) { | ||
require(balanceOf(to) + amount <= 10 ether, "Exceeds limit"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- DON'T rely solely on the balanceOf to determine the number of tokens a user can mint. Depending solely on this could cause a vulnerability, especially when a user transfers out the minted tokens and continues to mint more tokens.
- use custom errors are more gas efficient than using require with a string
w2/script/Counter.s.sol
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused files.
### 合約漏洞 | ||
- 首先是 `mapping(address => address) internal _delegates;` | ||
這個變數的問題,這個變數是用來記錄使用者的代表人,但是這個變數是 `internal` 的,所以可以直接透過 `delegate` 這個函數來修改其他使用者的代表人。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
變數宣告為 internal
並不是造成漏洞的原因!delegate
確保只有自己能修改自己的代理人,這符合設計的需求。漏洞關鍵在於投過票的 token 轉移給其他人後還能再次投票,造成一個 token 可以投多次票。
w2/checkedTest.png
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unchecked
block is used for gas-saving purposes, but you must ensure that it cannot lead to underflow or overflow errors.
v1.8.1
# Conflicts: # .github/workflows/pull-request.yml # .gitmodules # README.md # w1/.gitignore # w1/README.md # w1/lib/openzeppelin-contracts # w1/src/MyToken.sol # w2/.gitignore # w2/README.md # w2/lib/openzeppelin-contracts # w2/src/DaoToken.sol # w3/.gitignore # w3/lib/forge-std # w3/lib/openzeppelin-contracts # w3/src/AmazingToken.sol # w3/src/LenderPool.sol # w3/src/ReceiverPool.sol # w3/test/Lender.t.sol # w4/.gitignore # w4/src/Game.sol # w4/test/Game.t.sol # w5/README.md
No description provided.