Skip to content

Instantly share code, notes, and snippets.

View oleganza's full-sized avatar

Oleg Andreev oleganza

View GitHub Profile
@oleganza
oleganza / gist:bd14f60643395706efaa
Last active August 29, 2015 14:02
Reply on Ghash

A reader asked me over email recently:

Have you posted anything or had any thoughts on Ghash.IO situation?

Nothing on this. I think it's just early volatility in bitcoin space. Some company (CEX) got serious about making a private mining farm and made a whopping share. Others will follow soon.

The dirty little secret of the blockchain is that it's not secure until increasing the hashrate by even 1% is an enormous economic feat. Currently it's not impossibly expensive to build your own farm with significant share - therefore the network is not very theoretically secure. Even if every existing pool had no more than 10%, you can't be sure that some guy does not unleash enormous hashing power at once and reverts some transactions.

When more companies start building private farms (and they will, it's the only cost-efficient way to mine; individual miners will soon disappear), you'll see more even distribution of the hashrate, but most importantly, the growth of hashrate will get slower. Because the slo

@oleganza
oleganza / gist:9805d0c42172803253a7
Last active August 29, 2015 14:02
Replacement for ?: operator in Clang
// Replacement for Clang's (a ?: b) in Swift.
// Note: does not yet handle case when 'false' is supplied as Any? or AnyObject? type.
operator infix ||| { associativity left precedence 140 }
// Version for arbitrary optionals.
@infix func |||<A>(a:A?, b: @auto_closure ()->A?) -> A? {
if let x = a {
return a
}
// Y-combinator in Swift.
func Y<y,⒴>(𝖸:((y)->⒴)->((y)->⒴))->((y)->⒴){
var Y:((y)->⒴)!;Y=𝖸{Y($0)};return Y
}
// Couldn't find a way to avoid such explicitness.
// If types are defined in the inner function, compiler cannot infer type of 'f'.
let factorial = Y {(f:((Int)->Int)) -> ((Int)->Int) in
return {n in
@oleganza
oleganza / filter-api-diff.rb
Created June 5, 2014 06:10
Strip away "method->property" updates from iOS/OSX API diffs
# Oleg Andreev @oleganza
#
# This is a script that strips away all lines about converting methods to properties.
# Filtered file is easier to read to find what's new.
#
# 1. Save html file with API diff.
# 2. Run filter-api-diff.rb <name-of-the-file.html>
# 3. Open <name-of-the-file.html>-filtered.html in Safari.
#
# This script adds absolute URLs for stylesheets, no worries about them.
@oleganza
oleganza / gist:8cc921e48f396515c6d6
Last active January 30, 2022 00:06
Proof that Proof-of-Work is the only solution to Byzantine Generals' problem

In reply to "@Vlad_Roberto: No, not a programmer. I just know there's better ways to doing anything without massive energy consumption & Banks."

The problem of blockchain synchronization is the following:

Imagine you are sitting in a bunker. You have no idea what people are out there and what are their intentions. You only receive some incoming messages from strangers that may contain anything. They can be just random garbage or deliberately crafted messages to confuse you or lie to you. You never know. You cannot trust anyone.e

The problem of "money" or any other "social contract" is that everyone should be able to know what the majority agrees to without trusting some intermediaries (otherwise they can easily obuse their special position). If everyone votes for "X", then you sitting in a bunker must somehow independently figure out that all those other people indeed voted for "X" and not for "Y" or "Z". But remember: you cannot trust anyone's message and messages are the only thing you get from the outsi

@oleganza
oleganza / BIP-Fractional-Full-Node.md
Created April 30, 2014 12:07
BIP-Fractional-Full-Node

BIP Draft: Fractional Full Node

Abstract

We explore the way to make full Bitcoin nodes store only a fraction of data while being able to fully validate every incoming block and get information about any output or transaction.

Strategy

@oleganza
oleganza / BIP-Fractional-Storage-Identifier.md
Last active August 29, 2015 14:00
BIP: Fractional Storage Identifier

BIP: Fractional Storage Identifier

Abstract

In Bitcoin we might want to have fractional storage of blocks and transaction state so that many more nodes can fully validate incoming blocks without sacrificing a lot of disk space. We propose a scheme that allows nodes to advertise which fraction of the data set they can provide and enables uniform distribution of such fractions among nodes. The scheme also allows reducing individual fraction at no extra cost to scale with the gbrowth of the network.

Scheme

@oleganza
oleganza / gist:10458460
Created April 11, 2014 11:00
js password generator
// Based on oi.js by Dan Kaminsky https://gist.github.com/PaulCapestany/6148566
var base58alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
function millis() { return Date.now(); }
function flip_coin() { n=0; then = millis()+1; while(millis()<=then) { n=!n; } return n; }
function get_fair_bit() { while(1) { a=flip_coin(); if(a!=flip_coin()) { return(a); } } }
function get_random_6bit(){ n=0; bits=6; while(bits--){ n<<=1; n|=get_fair_bit(); } return n; }
function get_password(length) {
var password = "";
var offset = 0; // offset allows us to go through the infinite alphabet thus minimizing bias towards lower characters.
### Keybase proof
I hereby claim:
* I am oleganza on github.
* I am oleganza (https://keybase.io/oleganza) on keybase.
* I have a public key whose fingerprint is AB70 0EB4 91D6 3812 D5B0 AE40 6456 F1F5 C543 2530
To claim this, I am signing this object:
Exchanges and web wallets do not need "cold" and "hot" storage. They need 2-of-3 multisig lock.
1. User's funds are locked on 2-of-3 multisig transaction (P2SH or directly, does not matter).
2. Key A belongs to user (similarly to Blockchain.info, service may backup the encrypted key, but user loses key when forgets the password).
3. Key B is stored on web server, unencrypted.
4. Key C belongs to technical staff of the service. This key is encrypted by staff's password and only stored on personal computers of the staff.