Skip to content

Instantly share code, notes, and snippets.

View spalladino's full-sized avatar
🔷

Santiago Palladino spalladino

🔷
View GitHub Profile
@spalladino
spalladino / revert.ts
Created September 11, 2020 22:38
Get the revert reason before sending an Ethereum transaction if the transaction would fail
export async function tryGetRevertReason(to: string, from: string, data: string): Promise<string | undefined> {
const provider = ethers.getDefaultProvider();
const tx = { to, from, data };
try {
await provider.estimateGas(tx);
} catch {
const value = await provider.call(tx);
return hexDataLength(value) % 32 === 4 && hexDataSlice(value, 0, 4) === '0x08c379a0'
? defaultAbiCoder.decode(['string'], hexDataSlice(value, 4))
: undefined;
@spalladino
spalladino / README.md
Created May 15, 2021 19:59
How to bypass BitGo's error when using a Ledger wallet

How to bypass BitGo's error when using a Ledger wallet

BitGo recently updated the version of its bitcoinjs-lib dependency, but failed to update the code that interacted with legacy wallets that relied on Ledger hardware wallets. This triggered a r.bufferutils.varIntSize is not a function error whenever trying to use the funds in the wallet. Following is a workaround you can use to manually patch the error, and get your funds out of BitGo.

Disclaimer: I set up this workaround to help a friend rescue their funds. I have no idea if it works for every instance of this error, and it may lead to loss of funds. I strongly suggest that you try it out with a small amount before you attempt to remove all your bitcoin from BitGo.

The problem

The problem seems to happen when interacting with a legacy wallet managed by a Ledger hardware wallet. You have a legacy wallet if BitGo displays the following notice when you open your wallet (fun fact: the link to the instructions to mi

@spalladino
spalladino / stats.py
Created January 5, 2014 16:31
Count number of lines of code per language per week in git repository using cloc
import csv
import os
import sys
from os.path import isfile
from datetime import date, timedelta
from subprocess import call, check_output
# Script expects that each project is in a folder with the same name in the working directory
PROJECTS = ['my-project', 'another-project']
@spalladino
spalladino / setup-relayer.md
Last active November 18, 2020 15:10
Manual script for setting up a GSNv1 relayer

Manual setup for a GSN relayer

⚠️ This setup is only good for GSNv1. Head over to https://docs.opengsn.org for the latest setup for GSNv2.

Install nginx and certbot

sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install nginx software-properties-common certbot python-certbot-nginx
@spalladino
spalladino / deploy-function.js
Created September 27, 2020 19:06
Deploy a subset of AWS SAM functions bypassing CloudFormation for a faster development cycle
#! /usr/bin/env node
const TEMPLATE_FILENAME = 'template.yaml';
const WEBPACK_CONFIG = './api/webpack.config.js';
const WEBPACK_CONTEXT = './api';
const STACKNAME = process.env.STACKNAME;
const { Lambda, CloudFormation } = require('aws-sdk');
const { yamlParse } = require('yaml-cfn');
const { readFileSync } = require('fs');
@spalladino
spalladino / assume-role.sh
Created August 25, 2020 19:44
Bash scripts for MFA sign in to AWS in the console
AWS_ACCOUNT_ID= # aws account
AWS_USER_PROFILE= # profile in aws/credentials to your access key
AWS_REGION= # default region
AWS_IAM_NAME= # your iam name in the aws account
ARN_OF_ROLE= # the role you want to assume
ARN_OF_MFA=arn:aws:iam::$AWS_ACCOUNT_ID:mfa/$AWS_IAM_NAME
MFA_TOKEN_CODE=$1
read AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN <<< \
@spalladino
spalladino / AdminUpgradeabilityProxy.abi.json
Created May 20, 2019 15:31
ABI for ZeppelinOS AdminUpgradeabilityProxy as of zos-lib@2.3.0
[
{
"constant": false,
"inputs": [
{
"name": "newImplementation",
"type": "address"
}
],
"name": "upgradeTo",
@spalladino
spalladino / count-repos.py
Last active February 21, 2020 06:40
Estimate number of repositories that match a code search
from http.client import HTTPSConnection
from base64 import b64encode
from json import loads
from sys import exit, argv, stderr
from time import sleep
import urllib3
# Settings
PRINT_REPOS = True
@spalladino
spalladino / guess.py
Created January 29, 2020 21:41
Guess solc settings used to compile a given contract
#!/usr/bin/env python3
import json
import subprocess
import sys
import re
VERSIONS = [f'0.5.{minor}' for minor in range(0,16)]
RUNS = [0, 100, 200, 300]
TARGETS = ['byzantium', 'constantinople', 'petersburg', 'istanbul']
@spalladino
spalladino / hash.py
Created October 21, 2017 23:50
Solution for Coursera Cryptography 1 course Week 3 programming assignment
from hashlib import sha256
from sys import argv
with open(argv[1], "rb") as f:
blocks = []
block = f.read(1024)
while block:
blocks.append(block)
block = f.read(1024)