Skip to content

Commit 36e1599

Browse files
committed
An initial of adding smart contracts
1 parent 7eb2495 commit 36e1599

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

Cross-function reentrancy.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ contract Vulnerable{
44
mapping (address => uint) private userBalances;
55
uint public totalbalance = 0;
66

7+
// deposit money
78
function deposit() payable{
89
userBalances[msg.sender] += msg.value;
910
totalbalance += msg.value;

Fallback_call_cycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void checkOwner() {
3434

3535
// withdraw asset
3636
void withdraw(uint256 amount) {
37-
checkAmount("checkAmount", amount); // input error or input empty
37+
checkAmount("checkAmount", amount); // input parameters are not matched
3838
address addr = GetSender();
3939
uint256 balance = accounts.value.balance;
4040
if (balance >= amount) {

Function_call_cycle.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ constructor $Dice() {
3333
totalGameCount = 0;
3434
}
3535

36-
void checkAmount(uint256 amount) { // check if the amount is enough
36+
// check if the amount is enough
37+
void checkAmount(uint256 amount) {
3738
Require(U256_Cmp(amount, U256(0) == 1), "amount must > 0");
3839
address from = GetSender();
3940
accounts.key = from;
@@ -45,6 +46,7 @@ void checkAmount(uint256 amount) { // check if the amount is enough
4546
GetAmount(amount);
4647
}
4748

49+
// withdraw money
4850
MUTABLE
4951
void Withdraw(uint256 amount) {
5052
checkAmount(amount);
@@ -57,15 +59,17 @@ void Withdraw(uint256 amount) {
5759
}
5860
}
5961

62+
// withdraw all money
6063
MUTABLE
61-
void WithdrawAll() { // withdraw all money
64+
void WithdrawAll() {
6265
accounts.key = GetSender();
6366
uint256 amount = accounts.value.balance;
6467
Withdraw(amount);
6568
}
6669

70+
// deposit money
6771
MUTABLE
68-
void $Deposit() { // deposit money
72+
void $Deposit() {
6973
uint256 amount = GetValue();
7074
address from = GetSender();
7175
accounts.key = from;
@@ -74,14 +78,16 @@ void $Deposit() { // deposit money
7478
EVENT_DEPOSIT(from, accounts.value.balance, amount);
7579
}
7680

81+
// get money from certain address
7782
UNMUTABLE
78-
uint256 GetAmountFromAddress(address addr) { // get money from certain address
83+
uint256 GetAmountFromAddress(address addr) {
7984
accounts.key = addr;
8085
return accounts.value.balance;
8186
}
8287

88+
// get money
8389
UNMUTABLE
84-
uint256 GetAmount(uint256 amount) { // get money
90+
uint256 GetAmount(uint256 amount) {
8591
checkAmount(amount);
8692
return GetAmountFromAddress(GetSender());
8793
}

While_cycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ uint256 while_loop2(uint32 amount) {
2525

2626
//...
2727

28-
_(){} // fallback function
28+
_() {} // fallback function

0 commit comments

Comments
 (0)