Skip to content

Instantly share code, notes, and snippets.

View charles-cooper's full-sized avatar

Charles Cooper charles-cooper

View GitHub Profile
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
@charles-cooper
charles-cooper / output.ast_output.json
Last active October 21, 2021 01:19
Vyper Issue #2276
{"contract_name": "owned.vy", "ast": {"name": "owned.vy", "end_lineno": 7, "body": [{"end_lineno": 1, "annotation": {"end_lineno": 1, "func": {"end_lineno": 1, "src": "7:6:0", "end_col_offset": 13, "col_offset": 7, "ast_type": "Name", "node_id": 5, "id": "public", "lineno": 1}, "src": "7:15:0", "end_col_offset": 22, "col_offset": 7, "ast_type": "Call", "keywords": [], "node_id": 4, "args": [{"end_lineno": 1, "src": "14:7:0", "end_col_offset": 21, "col_offset": 14, "ast_type": "Name", "node_id": 7, "id": "address", "lineno": 1}], "lineno": 1, "keyword": null}, "value": null, "src": "0:22:0", "end_col_offset": 22, "col_offset": 0, "ast_type": "AnnAssign", "node_id": 1, "target": {"end_lineno": 1, "src": "0:5:0", "end_col_offset": 5, "col_offset": 0, "ast_type": "Name", "node_id": 2, "id": "owner", "lineno": 1}, "lineno": 1, "simple": 1}, {"name": "withdraw", "end_lineno": 7, "decorator_list": [{"end_lineno": 3, "src": "25:8:0", "end_col_offset": 9, "col_offset": 1, "ast_type": "Name", "node_id": 42, "id": "exte
@charles-cooper
charles-cooper / wc_naive.c
Last active June 13, 2021 19:57
Naive version of wc which is 5x faster than the real wc. (Doesn't handle locales, utf-8, etc., just counts ASCII words).
// Something I whipped up in half an hour.
// Depends on strcspn being super fast.
#define __USE_LARGEFILE64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#include <unistd.h>
#include <string.h>
#include <stdio.h>
@charles-cooper
charles-cooper / erc20.lll.py
Created September 13, 2019 23:23
Vyper ERC20 example
[seq,
[mstore, 32, 1461501637330902918203684832716283019655932542976],
[mstore, 64, 170141183460469231731687303715884105727],
[mstore, 96, -170141183460469231731687303715884105728],
[mstore, 128, 1701411834604692317316873037158841057270000000000],
[mstore, 160, -1701411834604692317316873037158841057280000000000],
# Line 26
[codecopy, 320, ~codelen, 128],
[assert, [iszero, callvalue]],
[codecopy, 448, [add, ~codelen, [codeload, ~codelen]], 96],
@charles-cooper
charles-cooper / foo.lll.py
Last active September 13, 2019 23:04
Vyper example for talk (filenames suffixed with .py to trigger syntax highlighter)
[seq,
[return,
0,
[lll,
[seq,
[mstore, 28, [calldataload, 0]],
[mstore, 32, 1461501637330902918203684832716283019655932542976],
[mstore, 64, 170141183460469231731687303715884105727],
[mstore, 96, -170141183460469231731687303715884105728],
[mstore, 128, 1701411834604692317316873037158841057270000000000],
@charles-cooper
charles-cooper / foo.ir
Last active April 6, 2019 03:22
Use solidity's assembler for fun and profit
$ cat foo.ir
IR:
/*******************************************************
* WARNING *
* Solidity to Yul compilation is still EXPERIMENTAL *
* It can result in LOSS OF FUNDS or worse *
* !USE AT YOUR OWN RISK! *
*******************************************************/
# https://ethstats.io/account/0x68cb858247ef5c4a0d0cde9d6f68dce93e49c02a
PUSH1 0x80
PUSH1 0x40
MSTORE
PUSH1 0x04
CALLDATASIZE
LT
PUSH2 0x005c
JUMPI
PUSH1 0x00
@charles-cooper
charles-cooper / reorg_listener.py
Last active February 7, 2019 18:17
web3 client which handles reorgs and does not require node filter state
#!/usr/bin/env python
import asyncio, json, sys, os
import pickle
import websockets
import datetime
import time
import web3
from web3 import Web3
@charles-cooper
charles-cooper / abi.json
Last active December 7, 2018 06:46
Return nested structs
[
{
"name": "returnB",
"outputs": {
"type": "tuple",
"name": "out",
"components": [
{
"type": "bytes",
"name": "b3"