Skip to content

Instantly share code, notes, and snippets.

View charles-cooper's full-sized avatar

Charles Cooper charles-cooper

View GitHub Profile
2024-04-14T17:08:55.2635958Z Current runner version: '2.315.0'
2024-04-14T17:08:55.2663253Z ##[group]Operating System
2024-04-14T17:08:55.2663887Z Ubuntu
2024-04-14T17:08:55.2664206Z 22.04.4
2024-04-14T17:08:55.2664653Z LTS
2024-04-14T17:08:55.2664970Z ##[endgroup]
2024-04-14T17:08:55.2665360Z ##[group]Runner Image
2024-04-14T17:08:55.2665866Z Image: ubuntu-22.04
2024-04-14T17:08:55.2666266Z Version: 20240407.1.0
2024-04-14T17:08:55.2667230Z Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20240407.1/images/ubuntu/Ubuntu2204-Readme.md
@charles-cooper
charles-cooper / transient_benchmark.py
Created February 1, 2024 22:24
generate benchmarks for transient storage
#!/usr/bin/env python
with open("benchmark_control.easm", "w") as f:
print("PUSH1 251", file=f)
print("PUSH1 1", file=f)
for _ in range(10_000): # stay roughly within codesize limit, still large enough for benchmark
print("DUP2 MUL", file=f)
print("DUP1 DUP1 POP POP", file=f)
@charles-cooper
charles-cooper / module_example.vy
Last active January 13, 2024 15:11
more module examples
###
# access_control.vy
owner: address
def __init__():
self.owner = msg.sender
def check_owner():
assert msg.sender == self.owner
###
allowances: HashMap[address, HashMap[address, uint256]]
balanceOf: HashMap[address, uint256]
totalSupply: uint256
bundle: ERC20Bundle
def __init__():
... # do things with initializing and totalSupply
@external
@charles-cooper
charles-cooper / boa_asan.py
Last active January 16, 2024 14:36
address sanitizer
# usage:
# install asan fork of vyper 0.3.10 (`pip install git+https://github.com/charles-cooper/vyper@asan`)
# change `import boa` to `import boa; import boa_asan` in scripts
from eth.exceptions import VMError
import boa.environment
class MemoryAccessViolation(VMError):
pass
@charles-cooper
charles-cooper / defillama.py
Created April 9, 2023 17:42
defillama chatgpt plugin generated by chatgpt
import requests
from openai_plugin import Plugin
class DefiLlama(Plugin):
def __init__(self):
self.base_url = "https://api.llama.fi"
def fetch_data(self, endpoint):
try:
response = requests.get(f"{self.base_url}/{endpoint}")
@charles-cooper
charles-cooper / selector-master.py
Created October 25, 2022 03:38 — forked from Philogy/selector-master.py
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):
@charles-cooper
charles-cooper / output.evm
Last active August 29, 2023 16:55
transient storage example in vyper
0x6020610585600039600051630000055c5261055c61002963000000003961055c6020016300000000f3600436101561000d57610551565b60003560e01c34610557576307a1018e81186102f557600435600401610400813511610557578035806040526020820181816060375050506029b3156100c0576010610460527f4a65726b20626f7920752072206f75740000000000000000000000000000000061048052610460506104605180610480018182601f600182031916810190500336823750506308c379a06104205260206104405261046051601f6001820319168101905060440161043cfd5b336029b463ee9387f26104605260208061048052806104800160405180825260208201818183606060045afa9050505080518060208301018182601f600182031916810190500336823750508051602001601f60018203191681019050905081015050333b15610557576000600061044461047c6000335af1610148573d600060003e3d6000fd5b60006000b3600a81116105575780156102e757905b6004810260010180b36104605260018101b36104805260028101b36104a05260038101b36104c0525061048051610580526104a0516105a0526040610560526105608051602082012090506104e052610460516104c051602061055c60003960005180820282158284830414171561055757905090506127
DUP2 DUP2 GT PUSH2 _join JUMPI SWAP1 _join JUMPDEST POP
@charles-cooper
charles-cooper / lll_features.vy
Created October 25, 2021 20:31
demonstrate LLL features used by vyper
# example contract demonstrating LLL features
x: public(uint256)
y: public(Bytes[32])
z: public(int128)
w: public(bool)
@external
def __init__(x: uint256, y: Bytes[32], z: int128, w: bool):
self.x = x