generated from FinTechIntro/2024-Spring-HW1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 826c989
Showing
16 changed files
with
1,093 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Foundry Testing | ||
run-name: Homework 1 Running by ${{ github.actor }} | ||
|
||
on: | ||
push: | ||
branches: | ||
- "**" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref_name }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
WORKFLOW_NAME: Foundry Test on ${{ github.ref_name }} | ||
|
||
jobs: | ||
check: | ||
strategy: | ||
fail-fast: true | ||
|
||
name: Foundry Testing | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Run Forge tests | ||
run: | | ||
cd hw1 | ||
forge test --mt test_check -vvv | ||
id: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "hw1/lib/forge-std"] | ||
path = hw1/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# 2024-Spring-HW1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Compiler files | ||
cache/ | ||
out/ | ||
|
||
# Ignores development broadcast logs | ||
!/broadcast | ||
/broadcast/*/31337/ | ||
/broadcast/**/dry-run/ | ||
|
||
# Docs | ||
docs/ | ||
|
||
# Dotenv file | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
## Foundry | ||
|
||
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** | ||
|
||
Foundry consists of: | ||
|
||
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). | ||
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. | ||
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. | ||
- **Chisel**: Fast, utilitarian, and verbose solidity REPL. | ||
|
||
## Documentation | ||
|
||
https://book.getfoundry.sh/ | ||
|
||
## Usage | ||
|
||
### Build | ||
|
||
```shell | ||
$ forge build | ||
``` | ||
|
||
### Test | ||
|
||
```shell | ||
$ forge test | ||
``` | ||
|
||
### Format | ||
|
||
```shell | ||
$ forge fmt | ||
``` | ||
|
||
### Gas Snapshots | ||
|
||
```shell | ||
$ forge snapshot | ||
``` | ||
|
||
### Anvil | ||
|
||
```shell | ||
$ anvil | ||
``` | ||
|
||
### Deploy | ||
|
||
```shell | ||
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> | ||
``` | ||
|
||
### Cast | ||
|
||
```shell | ||
$ cast <subcommand> | ||
``` | ||
|
||
### Help | ||
|
||
```shell | ||
$ forge --help | ||
$ anvil --help | ||
$ cast --help | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[profile.default] | ||
src = "src" | ||
out = "out" | ||
libs = ["lib"] | ||
|
||
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Script, console} from "forge-std/Script.sol"; | ||
|
||
contract CounterScript is Script { | ||
function setUp() public {} | ||
|
||
function run() public { | ||
vm.broadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
/* Problem 1 Interface & Contract */ | ||
contract StudentV1 { | ||
// Note: You can declare some state variable | ||
|
||
function register() external returns (uint256) { | ||
// TODO: please add your implementaiton here | ||
} | ||
} | ||
|
||
/* Problem 2 Interface & Contract */ | ||
interface IClassroomV2 { | ||
function isEnrolled() external view returns (bool); | ||
} | ||
|
||
contract StudentV2 { | ||
function register() external view returns (uint256) { | ||
// TODO: please add your implementaiton here | ||
} | ||
} | ||
|
||
/* Problem 3 Interface & Contract */ | ||
contract StudentV3 { | ||
function register() external view returns (uint256) { | ||
// TODO: please add your implementaiton here | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
interface ID31eg4t3 { | ||
function proxyCall(bytes calldata data) external returns (address); | ||
function changeResult() external; | ||
} | ||
|
||
contract Attack { | ||
address internal immutable victim; | ||
// TODO: Declare some variable here | ||
// Note: Checkout the storage layout in victim contract | ||
|
||
constructor(address addr) payable { | ||
victim = addr; | ||
} | ||
|
||
// NOTE: You might need some malicious function here | ||
|
||
function exploit() external { | ||
// TODO: Add your implementation here | ||
// Note: Make sure you know how delegatecall works | ||
// bytes memory data = ... | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
interface IERC20 { | ||
function totalSupply() external view returns (uint256); | ||
function balanceOf(address account) external view returns (uint256); | ||
function transfer(address to, uint256 amount) external returns (bool); | ||
function transferFrom(address from, address to, uint256 value) external returns (bool); | ||
function approve(address spender, uint256 amount) external returns (bool); | ||
function allowance(address owner, address spender) external view returns (uint256); | ||
|
||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
event Approval(address indexed owner, address indexed spender, uint256 value); | ||
} | ||
|
||
contract LiaoToken is IERC20 { | ||
// TODO: you might need to declare several state variable here | ||
mapping(address account => uint256) private _balances; | ||
mapping(address account => bool) isClaim; | ||
|
||
uint256 private _totalSupply; | ||
|
||
string private _name; | ||
string private _symbol; | ||
|
||
event Claim(address indexed user, uint256 indexed amount); | ||
|
||
constructor(string memory name_, string memory symbol_) payable { | ||
_name = name_; | ||
_symbol = symbol_; | ||
} | ||
|
||
function decimals() public pure returns (uint8) { | ||
return 18; | ||
} | ||
|
||
function name() public view returns (string memory) { | ||
return _name; | ||
} | ||
|
||
function symbol() public view returns (string memory) { | ||
return _symbol; | ||
} | ||
|
||
function totalSupply() external view returns (uint256) { | ||
return _totalSupply; | ||
} | ||
|
||
function balanceOf(address account) external view returns (uint256) { | ||
return _balances[account]; | ||
} | ||
|
||
function claim() external returns (bool) { | ||
if (isClaim[msg.sender]) revert(); | ||
_balances[msg.sender] += 1 ether; | ||
_totalSupply += 1 ether; | ||
emit Claim(msg.sender, 1 ether); | ||
return true; | ||
} | ||
|
||
function transfer(address to, uint256 amount) external returns (bool) { | ||
// TODO: please add your implementaiton here | ||
} | ||
|
||
function transferFrom(address from, address to, uint256 value) external returns (bool) { | ||
// TODO: please add your implementaiton here | ||
} | ||
|
||
function approve(address spender, uint256 amount) external returns (bool) { | ||
// TODO: please add your implementaiton here | ||
} | ||
|
||
function allowance(address owner, address spender) public view returns (uint256) { | ||
// TODO: please add your implementaiton here | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
interface IERC721 { | ||
function balanceOf(address owner) external view returns (uint256 balance); | ||
function ownerOf(uint256 tokenId) external view returns (address owner); | ||
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; | ||
function safeTransferFrom(address from, address to, uint256 tokenId) external; | ||
function transferFrom(address from, address to, uint256 tokenId) external; | ||
function approve(address to, uint256 tokenId) external; | ||
function setApprovalForAll(address operator, bool approved) external; | ||
function getApproved(uint256 tokenId) external view returns (address operator); | ||
function isApprovedForAll(address owner, address operator) external view returns (bool); | ||
|
||
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); | ||
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); | ||
event ApprovalForAll(address indexed owner, address indexed operator, bool approved); | ||
} | ||
|
||
interface IERC721TokenReceiver { | ||
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) | ||
external | ||
returns (bytes4); | ||
} | ||
|
||
contract NFinTech is IERC721 { | ||
// Note: I have declared all variables you need to complete this challenge | ||
string private _name; | ||
string private _symbol; | ||
|
||
uint256 private _tokenId; | ||
|
||
mapping(uint256 => address) private _owner; | ||
mapping(address => uint256) private _balances; | ||
mapping(uint256 => address) private _tokenApproval; | ||
mapping(address => bool) private isClaim; | ||
mapping(address => mapping(address => bool)) _operatorApproval; | ||
|
||
error ZeroAddress(); | ||
|
||
constructor(string memory name_, string memory symbol_) payable { | ||
_name = name_; | ||
_symbol = symbol_; | ||
} | ||
|
||
function claim() public { | ||
if (isClaim[msg.sender] == false) { | ||
uint256 id = _tokenId; | ||
_owner[id] = msg.sender; | ||
|
||
_balances[msg.sender] += 1; | ||
isClaim[msg.sender] = true; | ||
|
||
_tokenId += 1; | ||
} | ||
} | ||
|
||
function name() public view returns (string memory) { | ||
return _name; | ||
} | ||
|
||
function symbol() public view returns (string memory) { | ||
return _symbol; | ||
} | ||
|
||
function balanceOf(address owner) public view returns (uint256) { | ||
if (owner == address(0)) revert ZeroAddress(); | ||
return _balances[owner]; | ||
} | ||
|
||
function ownerOf(uint256 tokenId) public view returns (address) { | ||
address owner = _owner[tokenId]; | ||
if (owner == address(0)) revert ZeroAddress(); | ||
return owner; | ||
} | ||
|
||
function setApprovalForAll(address operator, bool approved) external { | ||
// TODO: please add your implementaiton here | ||
} | ||
|
||
function isApprovedForAll(address owner, address operator) public view returns (bool) { | ||
// TODO: please add your implementaiton here | ||
} | ||
|
||
function approve(address to, uint256 tokenId) external { | ||
// TODO: please add your implementaiton here | ||
} | ||
|
||
function getApproved(uint256 tokenId) public view returns (address operator) { | ||
// TODO: please add your implementaiton here | ||
} | ||
|
||
function transferFrom(address from, address to, uint256 tokenId) public { | ||
// TODO: please add your implementaiton here | ||
} | ||
|
||
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) public { | ||
// TODO: please add your implementaiton here | ||
} | ||
|
||
function safeTransferFrom(address from, address to, uint256 tokenId) public { | ||
// TODO: please add your implementaiton here | ||
} | ||
} |
Oops, something went wrong.