Skip to content

Z24028005 HW Review#5

Open
alex0207s wants to merge 17 commits intomainfrom
Z24028005
Open

Z24028005 HW Review#5
alex0207s wants to merge 17 commits intomainfrom
Z24028005

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.
  • You haven't reproduced the test scenario on the sepolia testing chain.
  • Either rename MyToken.sol to SammiToken.sol or delete MyToken.sol, along with the corresponding test contract and script contract. Do not leave an empty contract.


_mint(to, amount * 10 ** uint256(decimals()));

console.log(startGas - gasleft());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • gasleft() is not a good way to measure gas cost.
  • We generally avoid logging within the contract itself, preferring to do so in test contracts or script contracts instead.

revert OnlyDeployerCanMintOver10();
}

_mint(to, amount * 10 ** uint256(decimals()));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you don't override the decimals() function, you can use the ether keyword directly.


uint256 notDeployerLimit = 10;

if (deployer != to && balanceOf(to) + amount > notDeployerLimit) {
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.

}

function test_mint_user() public {
uint256 eth = 10 ** uint256(sammiToken.decimals());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you don't override the decimals() function, you can use the ether keyword directly.

address public _deployer;

function setUp() public {
sammiToken = new SammiToken();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Utilize startPrank(deployer) to simulate the deployer role for deploying the SammiToken.


function test_mint_deployer() public {
sammiToken.mint(_deployer, 100);
assertEq(sammiToken.balanceOf(_deployer), 100 * 10 ** 18);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

repalce ether with 10**18

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

empty :(


//hacker以 bob 的private-key操作
vm.startPrank(bob);
daoToken.delegate(hacker);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

use formatter or execute forge fmt before push

alex0207s and others added 9 commits March 24, 2024 20:35
# Conflicts:
#	w1/README.md
#	w1/script/MyToken.s.sol
#	w1/src/MyToken.sol
#	w1/test/MyToken.t.sol
#	w2/README.md
#	w2/test/DaoToken.t.sol
#	w3/.gitignore
#	w3/src/AmazingToken.sol
#	w3/src/LenderPool.sol
#	w3/src/ReceiverPool.sol
#	w3/test/Lender.t.sol
# Conflicts:
#	.gitmodules
#	w1/README.md
#	w1/script/MyToken.s.sol
#	w1/src/MyToken.sol
#	w1/test/MyToken.t.sol
#	w2/README.md
#	w2/test/DaoToken.t.sol
(cherry picked from commit 0b05ec2)
(cherry picked from commit 747517a)
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