Skip to content

Instantly share code, notes, and snippets.

View phunguyen19's full-sized avatar

Raymond Phu Nguyen phunguyen19

View GitHub Profile
@phunguyen19
phunguyen19 / cmd_web_handlers.go
Last active October 8, 2024 13:38
Go, Template, Helper Rendering
func snippetViewHandler(app *application) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(r.PathValue("id"))
if err != nil || id < 1 {
app.clientError(w, http.StatusNotFound)
return
}
s, err := app.snippets.Get(id)
@phunguyen19
phunguyen19 / 1-Wallet.sol
Created July 30, 2024 00:42
Snippet of Parity Multisig Wallet get hacked
contract Wallet is WalletEvents {
...
// METHODS
// gets called when no other function matches
function() payable {
// just being sent some cash?
if (msg.value > 0)
@phunguyen19
phunguyen19 / 1-FibonacciLib.sol
Created July 30, 2024 00:33
Example Ethereum Smart Contract delegatecall vulnerability
// library contract - calculates Fibonacci-like numbers
contract FibonacciLib {
// initializing the standard Fibonacci sequence
uint public start;
uint public calculatedFibNumber;
// modify the zeroth number in the sequence
function setStart(uint _start) public {
start = _start;
}
@phunguyen19
phunguyen19 / 1-EtherGame.sol
Created July 29, 2024 14:10
Example Ethereum Smart Contract Unexpected Ether vulnerability
contract EtherGame {
uint public payoutMileStone1 = 3 ether;
uint public mileStone1Reward = 2 ether;
uint public payoutMileStone2 = 5 ether;
uint public mileStone2Reward = 3 ether;
uint public finalMileStone = 10 ether;
uint public finalReward = 5 ether;
mapping(address => uint) redeemableEther;
@phunguyen19
phunguyen19 / 1-TimeLock.sol
Created July 29, 2024 01:54
Example Ethereum Smart Contract Arithmetic Over/Underflow attack
contract TimeLock {
mapping(address => uint) public balances;
mapping(address => uint) public lockTime;
function deposit() external payable {
balances[msg.sender] += msg.value;
lockTime[msg.sender] = now + 1 weeks;
}
@phunguyen19
phunguyen19 / 1-EtherStore.sol
Last active July 29, 2024 01:36
Example Ethereum Smart Contract Reentrancy attack
contract EtherStore {
uint256 public withdrawalLimit = 1 ether;
mapping(address => uint256) public lastWithdrawTime;
mapping(address => uint256) public balances;
function depositFunds() external payable {
balances[msg.sender] += msg.value;
}
@phunguyen19
phunguyen19 / note.md
Created July 21, 2024 04:19
Common NPM install package commedns
@phunguyen19
phunguyen19 / type-state.rs
Created June 29, 2024 10:43
Rust Type-State pattern
trait FileState {}
// We need this to define
// `close` method for multiple states
trait Closable {
fn close(self) -> File<ClosedFile>;
}
struct File<S: FileState> {
state: S,
@phunguyen19
phunguyen19 / lint-test.yaml
Last active June 29, 2024 02:20
Github Actions for Rust
name: Rust
on:
pull_request:
branches: [ "master" ]
env:
CARGO_TERM_COLOR: always
jobs: