Skip to content

Instantly share code, notes, and snippets.

View karmacoma-eth's full-sized avatar

karmacoma karmacoma-eth

View GitHub Profile
@karmacoma-eth
karmacoma-eth / sending-ether-cheat-sheet.md
Last active March 12, 2024 01:14
Sending Ether Cheat Sheet

Sending Ether Cheat Sheet

TLDR

🥇 Instead of sending Ether, use the withdrawal pattern

🥈 If you really need to send Ether, use a safe wrapper like OpenZeppelin's Address.sendValue(addr, amount)

🥉 If you really need to send Ether without dependencies, use (bool success, ) = addr.call{value: amount}("")

@karmacoma-eth
karmacoma-eth / fup.sh
Last active February 26, 2024 11:42
foundryup script
# from https://twitter.com/0xYYY_/status/1562091599731228672
# put this before `source $ZSH/oh-my-zsh.sh`
FOUNDRY_PLUGIN_DIR=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/foundry
fpath+=$FOUNDRY_PLUGIN_DIR
fup () {
if ! command -v foundryup &> /dev/null
then
echo "Install foundryup first: https://getfoundry.sh"
@karmacoma-eth
karmacoma-eth / linear-storage-poc.py
Created December 12, 2023 02:25
linear-storage-poc.py
from dataclasses import dataclass
from typing import Tuple
bytes32 = int
address = int
@dataclass
class Context:
context_address: address
@karmacoma-eth
karmacoma-eth / poc-enumerate.py
Last active October 16, 2023 22:09
enumerating possibles expression values with z3
from z3 import *
selector = BitVec('selector', 32)
expr = 107 + 4 * (selector % 16)
codesize = 128
s = Solver()
s.add(expr < codesize)
possible_jump_table_values = set([])
@karmacoma-eth
karmacoma-eth / parallel-wait.py
Last active May 30, 2023 15:34
starts n processes with some random amount of work, and they exit whenever the first one is finished
import os
import random
import time
from multiprocessing import Pool, Event
def init_pool_processes(the_shutdown_event):
'''
Initialize each process with the global shutdown event
@karmacoma-eth
karmacoma-eth / kekorigin.huff
Created April 15, 2023 23:14
curta puzzle 7 solution in huff
#define macro MAIN() = takes(0) returns(0) {
// sol.stop
__VERBATIM(0x01)
// sol.ctxSetting
__VERBATIM(0x00)
// store origin at memory location 0
origin push0 mstore
@karmacoma-eth
karmacoma-eth / quine.etk
Last active March 18, 2023 18:28
EVM quine
# quine.etk
# ⬜ => ⬜
# A quine is a computer program which takes no input and produces a copy of its own source code as its only output.
# 0x80...f3 is the compiled code excluding the push16 instruction (from dup1 to return)
push16 0x8060801b17606f5953600152602136f3
# --- stack ---
dup1 # code code
push1 128 # 128 code code
@karmacoma-eth
karmacoma-eth / rev-calldata-chunks.huff
Created February 23, 2023 18:35
reverse calldata in chunks of 32 bytes
// Reverse bytes received in calldata (abcd -> dcba)
// https://twitter.com/huff_language/status/1583894073487654913
// code length 206
/// @author Philippe Dumonet <philippe@dumo.net> -- https://twitter.com/real_philogy/status/1584304102418223104
/// @author karma (@0xkarmacoma) -- https://twitter.com/0xkarmacoma/status/1584239664310779904
/// @author kaden.eth (@0xKaden) -- https://twitter.com/0xKaden/status/1584280521089376256/
#define macro reverse_word() = takes(1) returns(1) {
// [x0]
0x00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff
@karmacoma-eth
karmacoma-eth / xor-decoder.huff
Created December 19, 2022 00:31
A little EVM program that decodes and returns XOR-encoded data (fits in a tweet)
// compiles to the following bin-runtime: 7f2a447b3991925d0aa0728f5e78315948d6cb14530bc6ae127f114971abe35db87f452f5b4ef4b2336fc516af2a17113e27f69f612162a8c9321c7e2401c78629dd18600052596000f3
// (run with e.g. `evm --code <bin-runtime> run | cast --to-ascii`)
#define macro MAIN() = takes(0) returns(0) {
0x2a447b3991925d0aa0728f5e78315948d6cb14530bc6ae127f114971abe35db8 // ciphertext
0x452f5b4ef4b2336fc516af2a17113e27f69f612162a8c9321c7e2401c78629dd // key (which happens to be the keccak hash of the message)
xor
0x00 mstore
// returns 0x6F6B207765206E65656420746F20676F20547572696E6720636F6D706C657465
@karmacoma-eth
karmacoma-eth / TestJson.sol
Last active December 6, 2022 18:14
solidity-json-testing
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {Test} from "forge-std/Test.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {console2} from "forge-std/console2.sol";
contract TestJson is Test {
/// @dev fields need to be sorted alphabetically (see docs of vm.parseJson())
struct ContractURISchema {