Skip to content

Instantly share code, notes, and snippets.

View rpn3319's full-sized avatar

Raymond Phu Nguyen rpn3319

  • Ho Chi Minh City, Vietnam
  • 07:52 (UTC +07:00)
  • LinkedIn in/rpn19
View GitHub Profile
@rpn3319
rpn3319 / docker-compose.yaml
Created December 14, 2024 02:47
Local Docker Compose
version: '3.8'
services:
mysql:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: localdocker
MYSQL_USER: user
MYSQL_PASSWORD: pass
@rpn3319
rpn3319 / consistent-hashing.go
Created November 24, 2024 05:33
Example consistent hashing golang
package main
import (
"crypto/md5"
"fmt"
"sort"
"strconv"
)
// ConsistentHashing represents the structure for consistent hashing
@rpn3319
rpn3319 / 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)
@rpn3319
rpn3319 / 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)
@rpn3319
rpn3319 / 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;
}
@rpn3319
rpn3319 / 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;
@rpn3319
rpn3319 / 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;
}
@rpn3319
rpn3319 / 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;
}
@rpn3319
rpn3319 / note.md
Created July 21, 2024 04:19
Common NPM install package commedns