Skip to content

Instantly share code, notes, and snippets.

View DanielVF's full-sized avatar

Daniel Von Fange DanielVF

View GitHub Profile
@DanielVF
DanielVF / draw_contract.nim
Created March 30, 2022 16:26
Code to visualize contracts
import nimPNG
import std/[times, os, strutils]
var bytecode: string = parseHexStr("6080604052600436106100cb5760003560e01c80638da5cb5b11610074578063d79779b21161004e578063d79779b21461029c578063e33b7de3146102d2578063f2fde38b146102e757600080fd5b80638da5cb5b146102125780639852595c14610230578063ce7c2ac21461026657600080fd5b806348b75044116100a557806348b75044146101a5578063715018a6146101c55780638b83209b146101da57600080fd5b806319165587146101195780633a98ef391461013b578063406072a91461015f57600080fd5b36610114577f6ef95f06320e7a25a04a175ca677b7052bdd97131872c2192525a629f51be77033604080516001600160a01b0390921682523460208301520160405180910390a1005b600080fd5b34801561012557600080fd5b50610139610134366004610d0c565b610307565b005b34801561014757600080fd5b506001545b6040519081526020015b60405180910390f35b34801561016b57600080fd5b5061014c61017a366004610d29565b6001600160a01b03918216600090815260076020908152604080832093909416825291909152205490565b3480156101b157600080fd5b506101396101c0366004610d29565b6104c0565b3480156101d157600080fd5b50610139
@DanielVF
DanielVF / sample.md
Last active January 21, 2024 07:07
Sample Vulnerability Report

Impact

CRITICAL! Almost all USDC liquidity on the REKT/USDC uniswap pool can be stolen, due to an authorization issue with burnFrom() on the REKT token.

Background

Uniswap v2 pools get the prices for their swaps by comparing the relative amounts of each of the two tokens that they hold. If the pool holds very little of token A, and a lot of token B, then it only takes a little of token A to buy a lot of token B.

Currently REKT and USDC are fairly priced in the pool. If there were to suddenly be very little REKT in the pool, but the same amount of USDC, then very little REKT would be able to buy a lot of USDC.

@DanielVF
DanielVF / OusdKeeper.sol
Last active September 8, 2021 19:36
OusdKeeper Draft
pragma solidity 0.8.7;
interface KeeperCompatibleInterface {
function checkUpkeep(bytes calldata checkData)
external
returns (bool upkeepNeeded, bytes memory performData);
function performUpkeep(bytes calldata performData) external;
}
@DanielVF
DanielVF / _charts.ipynb
Last active February 2, 2021 19:08
Compound USDT change proposal
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@DanielVF
DanielVF / generate_random_airdrop.py
Created December 9, 2020 15:15
Generate random ethereum airdrop csv
import pandas as pd
import numpy as np
import secrets
num = 800
addresses = ['0x'+secrets.token_hex(20) for _ in range(0,num)]
amounts = np.power(1200000, np.random.rand(num)*np.random.rand(num))
df = pd.DataFrame({'address':addresses, 'amount':amounts})
df.to_csv('sample_amounts.csv')
pragma solidity ^0.6.0;
// Calling SafeERC20.safeTransfer and SafeERC20.safeTransferFrom can fail
// with a "SafeERC20: ERC20 operation did not succeed" message when the
// underlying cause is running out of gas inside the transfer
// This is because the low level call to the ERC20 is indeed reverted by
// running out of gas, but that revert is caught, and a different revert
// is raised by the safeTransfer method.
@DanielVF
DanielVF / traceprint.ts
Created September 9, 2019 17:01
Pretty print control flow of Etherium debug traces
const fs = require('fs')
const chalk = require('chalk')
const trace = JSON.parse(fs.readFileSync('2019_08_09_mike_fail.json'))
const logs = trace.result.structLogs as TraceLog[]
interface TraceLog {
depth: number
error: string
gas: number,
@DanielVF
DanielVF / live_reindex.sh
Created May 10, 2019 15:59
reindex elastic search listings with new mappings in two seconds
# If running against any data you care about, check the results of each command for success before running the next command.
# Create new index
curl -X PUT "localhost:9200/listings_two" -H 'Content-Type: application/json' -d'
{
"mappings":{"listing":{"properties":{"price.amount":{"type":"double"},"price.currency.id":{"type":"keyword"},"commission":{"type":"double"},"commissionPerUnit":{"type":"double"},"unitsTotal":{"type":"integer"},"language":{"type":"keyword"},"listingType":{"type":"keyword"},"status":{"type":"keyword"},"marketplacePublisher":{"type":"keyword"},"category":{"type":"keyword","copy_to":"all_text"},"subCategory":{"type":"keyword","copy_to":"all_text"},"description":{"type":"text","copy_to":"all_text"},"title":{"type":"text","copy_to":"all_text"},"all_text":{"type":"text"}}}}
}
'
# copy listings to new index
@DanielVF
DanielVF / atc.nim
Last active January 28, 2020 01:07
Nim engine, no documentation
import sets
import engine
import strutils
import math
# import log
type
Atc* = ref object of RootObj
available*: HashSet[Ship]
occupied*: seq[bool]
@DanielVF
DanielVF / header.py
Last active November 15, 2018 12:37
Jupyter notebook standard header
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import json
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
pd.options.mode.chained_assignment = None