Skip to content

Instantly share code, notes, and snippets.

@Philogy
Philogy / headers.py
Created May 26, 2023 18:26
Extended Header Tool
#!/bin/python3
import pyperclip
import argparse
def check_width(args, base_width):
min_width = len(args.text) + base_width
if args.width < min_width:
raise ValueError(
f'Width of {args.width} cannot fit "{args.text}" (len: {len(args.text)} + {base_width})'
@Philogy
Philogy / llama-lend-get-history.py
Last active February 6, 2023 18:47
LLama Lend History Gettooor
import sys
import os
import dotenv
import requests
from collections import defaultdict
from decimal import Decimal as D
dotenv.load_dotenv()
# Instructions:
@Philogy
Philogy / String.t.sol
Last active October 28, 2022 11:21
Load dynamically sized string / byte-string from storage into memory
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import {Test} from "forge-std/Test.sol";
/// @author Philippe Dumonet <https://github.com/philogy>
contract StringTest is Test {
bytes str;
function testBytesLikeStorage(bytes memory _inputStr) public {
@Philogy
Philogy / selector-master.py
Last active October 25, 2022 03:38
Minimal Constant OP Selector Switch Generator
# @license MIT
# @author Philogy <https://github.com/Philogy>
from eth_utils.abi import function_signature_to_4byte_selector
from eth_utils.crypto import keccak
from math import ceil, log2
import pyperclip
def find_reselector_nonce(selectors, mask):
@Philogy
Philogy / OptimizedReverse.huff
Last active October 23, 2022 22:08
Huff Challenge #4 - Reverse
/*
Credit to karma (@0xkarmacoma) for the original code: twitter.com/0xkarmacoma/status/1584239664310779904
Credit to kaden.eth (@0xKaden) for suggesting the use of msize: twitter.com/0xKaden/status/1584280521089376256
*/
#define macro reverse_word() = takes(1) returns(1) {
// [x0]
0x00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff
dup2 dup2 and // [x1r, mask1, x0]
0x08 shl // [x1r', mask1, x0]
swap2 // [x1, mask1, x1r']
@Philogy
Philogy / Reverse.t.sol
Last active October 22, 2022 20:00
Efficiently reverse and return arbitrary calldata
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.15;
import {Test} from "forge-std/Test.sol";
import {HuffDeployer} from "foundry-huff/HuffDeployer.sol";
/// @author Philippe Dumonet <philippe@dumo.net>
contract ReverseTest is Test {
address reversooor;
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
// Used in the `name()` function
// "Yul Token"
bytes32 constant nameLength = 0x0000000000000000000000000000000000000000000000000000000000000009;
bytes32 constant nameData = 0x59756c20546f6b656e0000000000000000000000000000000000000000000000;
uint256 constant maxUint256 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
@Philogy
Philogy / ERC1967UUPS.huff
Last active October 15, 2022 22:11
Minimal EIP1967 UUPS Proxy
/**
===================================================
POTENTIALLY OUT-OF-DATE (last update: 2022-10-15).
PLEASE REFER TO THE FOLLOWING REPO: https://github.com/Philogy/concise-erc1967-proxies
===================================================
*/
#define constant IMPL_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
#define macro CONSTRUCTOR() = takes (0) returns (0) {
@Philogy
Philogy / headers.py
Created October 9, 2022 02:03
Transmission11s Style Headers In Python
#!/bin/python3
import sys
import pyperclip
def main():
args = sys.argv
if len(args) != 2:
raise ValueError(f'Invalid argument count {len(args)} expected 2')
word = args[1]
@Philogy
Philogy / VRGDA.ipynb
Created September 14, 2022 18:35
Simple VRGDA simulator
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.