Skip to content

Instantly share code, notes, and snippets.

View charles-cooper's full-sized avatar

Charles Cooper charles-cooper

View GitHub Profile
@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 / erc20.sol
Created October 15, 2021 21:40
compare erc20 in sol and vyper
/*
# @version 0.3.0
# @dev Implementation of ERC-20 token standard, vyper/examples/tokens/ERC20.vy at tag v0.3.0
# @author Takayuki Jimba (@yudetamago)
# https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
# compiled using `vyper -f bytecode_runtime`: 1579 bytes
from vyper.interfaces import ERC20
@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"
@charles-cooper
charles-cooper / sample.sql
Last active July 13, 2017 22:03
SQL style guide
WITH y AS ( -- WITH is not indented
SELECT -- subquery on its own line and indented one level
*
FROM schema2.table2
) -- closing paren flush with WITH
SELECT -- keywords in caps
z.*,
x.id, -- columns indented, on separate lines
y.foo, -- prefixed with the table name alias if there is a join