Skip to content
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

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open

Z24028003 HW Review #3

wants to merge 49 commits into from

Conversation

alex0207s
Copy link
Collaborator

No description provided.

Copy link
Collaborator Author

@alex0207s alex0207s left a 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)) {
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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));
Copy link
Collaborator Author

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");
Copy link
Collaborator Author

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

Copy link
Collaborator Author

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` 這個函數來修改其他使用者的代表人。
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

變數宣告為 internal 並不是造成漏洞的原因!delegate 確保只有自己能修改自己的代理人,這符合設計的需求。漏洞關鍵在於投過票的 token 轉移給其他人後還能再次投票,造成一個 token 可以投多次票。

Copy link
Collaborator Author

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.

0xRory and others added 22 commits March 10, 2024 10:55
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants