Skip to content

Instantly share code, notes, and snippets.

@etotheipi
etotheipi / aoc2020_day18_p2_hack
Last active December 18, 2020 08:02
Abusing Python to solve AoC 2020, Day 18 part 2
class ModInt:
""" An int that adds when you * and multiplies when you + """
def __init__(self, val):
self.val = val
def __mul__(self, other):
return ModInt(self.val + other.val)
def __add__(self, other):
return ModInt(self.val * other.val)
@etotheipi
etotheipi / backup_P2SH_and_comments.md
Created May 2, 2012 00:32
Backing up critical-but-not-too-sensitive data

Motivation

Armory currently holds address & transaction comments/labels as data appended to the wallet file (zeroed out when replaced/deleted). While it would be nice to keep comments in a separately backup-able file, the data is typically not critical and has not justified the effort to add complexity to the application to accommodate separate backups (or at least a backup that doesn't also include your maybe-encrypted private keys).

P2SH changes this.

Most P2SH scripts will be recoverable if you have backed-up the relevant wallets (which is likely available for personal P2SH/two-factor-auth setups). However, multi-signature transactions executed with other parties, such as escrow or various contracts, is considered critical data. So is the contact information of the other parties in the transaction. Reconstructing your own wallet will not help you find P2SH/multi-sig transactions involving your wallet, and even if you could, it would not help you figure out who the other parties are. You s

@etotheipi
etotheipi / ckd_output.txt
Created April 27, 2012 21:19
Child Key Derivation Test Vector(s)
Following is the test code I used. Generate the same sequences in both
private key space and public key space, make sure they generate the same
addresses.
Extended Keys are a triplet of (Priv, Pub, Chain). For extended public
keys, Priv is empty. When Priv is populated, Pub is computed.
-----------------------------------------------------------------------------------------------
// Confirm endianness of integer-to-binary
@etotheipi
etotheipi / armory_escrow.md
Created April 4, 2012 21:52
Buyer-Seller Escrow, with or without third-party

Buyer-Seller Escrow, with or without third-party

  • Author: Alan Reiner (Armory)
  • Orig Date: 04 April, 2012 First Draft: Sorting out ideas, and event sequences, handling details like who signs what when and where change outputs and fees fit into the equation.

Example Transaction

Here's an example of Alice and Bob setting up the transaction. Bob posts an item on craigslist, knowing that unknown, untrusted Alice will try to buy it. In this case, Bob is the seller and will set the "Risk Deposit" (could also be "Escrow Deposit"). This can be negotiated by the buyer, but I expect that something like 15-25% would be standard and not a point of contention. Remember, buyer does not trust seller, and vice versa.

@etotheipi
etotheipi / gist:1421550
Created December 2, 2011 03:08
Testnet multi-sig stack state: debugging
Verify 2-of-2 tx from Testnet:
Testnet Tx: 1c9608650a912be7fa88eecec664e6fbfa4b676708697fa99c28b3370005f32d (LE)
Spent: Block 26670 Tx: 1
OP_PUSHDATA : 30450220
OP_PUSHDATA : 30450220 04e83c1d
OP_PUSHDATA : 30450220 04e83c1d 30460221
OP_PUSHDATA : 30450220 04e83c1d 30460221 047cf315
OP_2 : 30450220 04e83c1d 30460221 047cf315 2
OP_TOALTSTAC: 30450220 04e83c1d 30460221 047cf315
OP_0 : 30450220 04e83c1d 30460221 047cf315 0
@etotheipi
etotheipi / gist:1369006
Created November 16, 2011 01:46
ECDSA_sig2x_test
All hex values are definitely big-endian, except for Msg, which is *probably* BE.
#1
Msg: 9d80933fe66d99317bb9600f40136f843fb33732c4e0456feca748f1463a2baa
Sig1r: 6e6259bf19ef089929a64618ac505983f5e5f060ab1e7cec5a74b3ec1810fe83
Sig1s: 80cf29cbb1786a4a96f5b4b1b6d0fbbde5d9c64db9fc162ab5a8858c8dc293d4
Sig2r: 19a59bdef0406a2ac9bf798c5b3250e814e04d6caa71b0a434f6e2688a5c4b9d
Sig2s: d4779e4d445290e0e1fb2a568f8051dba1a8a520066797f78e375ad9983559ea
@etotheipi
etotheipi / privKeyTest.py
Created November 2, 2011 12:08
Playing with private-keys in PyBtcEngine
from pybtcengine import *
# Create new private key and get its address information
print 'Creating new address:'
newAddr = PyBtcAddress().generateNew()
newAddr.pprint()
print ' Private key (integer):', newAddr.privKeyInt
print ' Private key (hex, BE):', int_to_hex(newAddr.privKeyInt, widthBytes=32, endOut=BIGENDIAN)
privKeyBinary33 = '\x80' + int_to_binary(newAddr.privKeyInt, widthBytes=32, endOut=BIGENDIAN)
chksum = hash256(privKeyBinary33)
@etotheipi
etotheipi / nonstdscript.txt
Created November 1, 2011 03:22
Non-std scripts from testnet
=====
Finding all non-std tx
=====
Attempting to interpret script:
Block: 13139 Tx: 0
ThisOut: fb73d48b12d03053a03f5c01f18befcf7c8726532b274f4b8810eb169fcf4ddb, 0
Raw Script: 4704000a0342000443d955e20dac59a23ed7beea83a96667576853f6650a98e7afb11646c7d6599bd45946a3b4296aa2c6c04a78d2baf685d4a1fdd2729d2e90c1d1db1195adbd17ac
Raw Tx: 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff070428f21d1c010affffffff0100f2052a01000000494704000a0342000443d955e20dac59a23ed7beea83a96667576853f6650a98e7afb11646c7d6599bd45946a3b4296aa2c6c04a78d2baf685d4a1fdd2729d2e90c1d1db1195adbd17ac00000000
pprint:
@etotheipi
etotheipi / BIP_0010_etotheipi.md
Created October 28, 2011 02:53
BIP 0010 - Multi-signature tx exchange standard

BIP 0010 - Proposal for Standardized, Multi-Signature Transaction Execution

Author: Alan Reiner
Contact: etotheipi@gmail.com
Status: Draft
Orig Date: 28 Oct, 2011

Abstract: