Skip to content

Instantly share code, notes, and snippets.

@Philogy
Philogy / Duplicator.huff
Last active August 1, 2022 10:51
Cell Division - 24 bytes
#define constant CNSTR_CODE = 0x601834818180333cf3
#define constant CNSTR_CODE_SIZE = 0x9
#define constant CNSTR_CODE_OFFSET = 0x17 // 0x20 - [CNSTR_CODE_SIZE]
#define macro MAIN() = takes(0) returns(0) {
[CNSTR_CODE_SIZE] [CNSTR_CODE_OFFSET] // [cc_offset, cc_size]
returndatasize // [0, cc_offset, cc_size]
[CNSTR_CODE] dup2 mstore // [0, cc_offset, cc_size]
dup3 dup3 dup3 create // [addr1, 0, cc_offset, cc_size]
pop create // [addr2]
@Philogy
Philogy / ReturnBlock.huff
Created August 16, 2022 21:53
Huff Challenge #1
#define macro MAIN() = takes(0) returns(0) {
number returndatasize mstore
0x20 returndatasize return
}
@Philogy
Philogy / EvenOdd.huff
Created August 17, 2022 21:45
Huff Challenge #2
#define macro MAIN() = takes(0) returns(0) {
returndatasize calldataload // [x]
not // [~x]
0x1 and // [even]
returndatasize mstore // []
msize returndatasize return // []
}
@Philogy
Philogy / VRGDA.ipynb
Created September 14, 2022 18:35
Simple VRGDA simulator
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / 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) {
// 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 / 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 <[email protected]>
contract ReverseTest is Test {
address reversooor;
@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 / 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):