Skip to content

Instantly share code, notes, and snippets.

View emo-eth's full-sized avatar

James emo-eth

View GitHub Profile
@emo-eth
emo-eth / Thermometer.t.sol
Last active August 28, 2023 22:07
Exploration in edge cases for account + storage warmness
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {Test} from "forge-std/Test.sol";
address constant callee = address(bytes20("call me maybe"));
interface Authorizer {
function allowed() external view returns (bool);
}
@emo-eth
emo-eth / find_optimizer_runs.sh
Last active April 10, 2023 18:19
Bash script to binary search on FOUNDRY_OPTIMIZER_RUNS for the optimal number of runs that results in bytecode smaller than the max
#!/bin/bash
# h/t @DrakeEvansV1 & ChatGPT
TARGET_SIZE=24.576
MIN_RUNS=1
# NOTE that at time of writing, Etherscan does not support verifying contracts
# that specify more than 10,000,000 optimizer runs.
# Higher numbers do not always result in different bytecode output. If a
# higher number of runs is used, it may be possible verify by spoofing with a
# number that results in the same bytecode output. This is not guaranteed.
@emo-eth
emo-eth / yul_ir_duplicate_function_detector.py
Created December 9, 2022 20:23
script to detect duplicate fn definitions in seaport IR out
from collections import defaultdict
from pprint import pprint
defs = []
with open("Seaport.sol") as f:
lines = f.readlines()
for line in lines:
line = line.strip()
if line.startswith("function fun_"):
@emo-eth
emo-eth / Findings.md
Created December 7, 2022 22:36
Seaport duplicated IR functions

Findings

  1. Most bifurcated definitions seem to be for reverting vs non-reverting codepaths - ie, normal fulfill vs fulfillAvailable. Introducing branching logic may add gas overhead.
    1. aggregateAvailable
    2. callAndCheckStatus (probably)
    3. fun_getGeneratedOrder (vs others, likely)
    4. fun_validateOrderAndUpdateStatus (vs others)
    5. fun_validateOrderAndPrepareToFulfill
    6. fun_verifyOrderStatus
  2. fun_verifyTime
@emo-eth
emo-eth / chain_funcs.sh
Last active June 22, 2023 14:43
Helper functions for interacting with chains and Foundry tests. Source from .zshrc etc
###########
# Imports #
###########
# the RPCs file should include RPC URLs and Etherscan API Keys for relevant networks
# (in a separate file so they don't get committed)
source "$(dirname "$0")/rpcs.sh"
# any useful addresses for various networks for easy reference
source "$(dirname "$0")/addresses.sh"
# any useful functions and definitions for interacting with Seaport
@emo-eth
emo-eth / list_function_signatures.py
Created May 8, 2022 16:45
calculate and list all function signatures based on a foundry project's out/ directory
import glob
import json
from typing import List
from web3 import Web3
def calculateSelector(sig):
result = Web3.keccak(text=sig)
selector = (Web3.toHex(result))[:10]
return selector
@emo-eth
emo-eth / opensea-1155-listing.ts
Last active July 18, 2022 07:13
example script to list an 1155 token on opensea
import * as fs from "fs";
import * as dotenv from "dotenv";
import { OpenSeaPort, Network } from "opensea-js";
dotenv.config();
const HDWalletProvider = require("@truffle/hdwallet-provider");
const mnemonic = fs.readFileSync(".mnemonic").toString().trim();
const ETH_RPC_URL = process.env.ETH_RPC_URL;
@emo-eth
emo-eth / roast.md
Last active March 8, 2022 02:14
Cabin Passport Roast

General

  • Try to use latest version of Solidity (0.8.12 at time of writing) for compiler optimizations, features, and bugfixes

Minor security:

  • Consider using a TwoStepOwnable implementation to mitigate the risk of unrecoverable ownership transfers due to user error

Minor optimizations:

  • Consider using custom errors instead of require statements, which can cut down on contract size and thus deploy gas cost
  • For token optimizations: consider inheriting from Solmate's (opinionated) token contracts over OpenZeppelin's
@emo-eth
emo-eth / rpi_setup.sh
Created October 15, 2017 16:41
Script to update & configure a Raspberry Pi for dev setup
#!/bin/sh
### update + upgrade packages first
sudo apt-get update
sudo apt-get upgrade -y
# sudo apt-get install mysql-server --fix-dependencies -y
sudo apt-get install tor git htop python3-dev screen libmysqlclient-dev libxml2-dev libxslt1-dev zlib1g-dev -y
# install miniconda 3.4.3
wget -O anaconda.sh http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-armv7l.sh
@emo-eth
emo-eth / .block
Last active September 14, 2016 03:32
Layered force-directed bubbles
license=Apache License, 2.0