Skip to content

Instantly share code, notes, and snippets.

Avatar

Oleg Andreev oleganza

View GitHub Profile
@oleganza
oleganza / async_swift_proposal.md
Last active Jan 21, 2021
Concrete proposal for async semantics in Swift
View async_swift_proposal.md

Async semantics proposal for Swift

Modern Cocoa development involves a lot of asynchronous programming using blocks and NSOperations. A lot of APIs are exposing blocks and they are more natural to write a lot of logic, so we'll only focus on block-based APIs.

Block-based APIs are hard to use when number of operations grows and dependencies between them become more complicated. In this paper I introduce asynchronous semantics and Promise type to Swift language (borrowing ideas from design of throw-try-catch and optionals). Functions can opt-in to become async, programmer can compose complex logic involving asynchronous operations while compiler produces necessary closures to implement that logic. This proposal does not propose new runtime model, nor "actors" or "coroutines".

Table of contents

View proving-gadgets-101.md

Proving gadgets

This is a collection of fun algebraic tricks to prove various boolean and arithmetic statements inside zero knowledge proofs.

We are going to use Bulletproofs interface, but won't go into detail how Bulletproofs actually work.

Bulletproofs interface

Bulletproofs is a framework to create arbitrary proofs using a "Rank-1 Constraint System" interface. In simple terms, "rank-1" means that in our system we can express statements where secret values ("variables") can be added and multiplied.

@oleganza
oleganza / NSData+OADataHelpers.m
Last active Jul 2, 2020
Creating NSString from NSData by fixing invalid UTF8 characters
View NSData+OADataHelpers.m
// Author: Oleg Andreev <oleganza@gmail.com>
// May 28, 2011
// Do What The Fuck You Want Public License <http://www.wtfpl.net>
#import "NSData+OADataHelpers.h"
#if !__has_feature(objc_arc)
#error ARC must be enabled!
#endif
View NSData+OADataHelpers.m
#import "NSData+OADataHelpers.h"
@implementation NSData (OADataHelpers)
- (NSString*) UTF8String
{
return [[[NSString alloc] initWithData:[self dataByHealingUTF8Stream] encoding:NSUTF8StringEncoding] autorelease];
}
// Replaces all broken sequences by � character and returns NSData with valid UTF-8 bytes.
@oleganza
oleganza / gist:8cc921e48f396515c6d6
Last active Feb 15, 2020
Proof that Proof-of-Work is the only solution to Byzantine Generals' problem
View gist:8cc921e48f396515c6d6

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

View cybershake.rs
//! ```ascii
//! ┌──────────────────────────────────────────────────────────────────────────────────────┐
//! │ _______ __ __ ______ _______ ______ _______ _ _ _______ _ _ _______ │
//! │ | \_/ |_____] |______ |_____/ |______ |_____| |_____| |____/ |______ │
//! │ |_____ | |_____] |______ | \_ ______| | | | | | \_ |______ │
//! │ │
//! └──────────────────────────────────────────────────────────────────────────────────────┘
//! ```
//!
//! # C Y B E R S H A K E
@oleganza
oleganza / ssss.rb
Last active Oct 9, 2019
128-bit Shamir's Secret Sharing Scheme (SSSS) Implementation in Ruby
View ssss.rb
#!/usr/bin/env ruby -rubygems
# Shamir's Secret Sharing Scheme with m-of-n rule for 128-bit numbers.
# Author: Oleg Andreev <oleganza@gmail.com>
#
# * Deterministic, extensible algorithm: every combination of secret and threshold produces exactly the same shares on each run. More shares can be generated without invalidating the first ones.
# * This algorithm splits and restores 128-bit secrets with up to 16 shares and up to 16 shares threshold.
# * Secret is a binary 16-byte string below ffffffffffffffffffffffffffffff61.
# * Shares are 17-byte binary strings with first byte indicating threshold and share index (these are necessary for recovery).
#
# See also: https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing
View rustscript.md

Rust Script

A scripting variant of the Rust language: syntactic sugar for runtime memory ownership rules and other dynamic features, with none of the static ones.

The goal is to have a good complimentary language that's easier to write and tinker with, while interoperating with Rust easily.

"Rust learned from Ruby. What if Ruby learned from Rust?"

File extension

@oleganza
oleganza / bulletproofs_battleships.md
Last active Oct 8, 2018
Bulletproofs Battleships
View bulletproofs_battleships.md

Bulletproofs battleships

Rules

  1. Each player has a board of 10x10 slots.
  2. Each player has to place 5 ships, sizes of 1, 2, 3, 4 and 5 slots.
  3. Ships can be oriented vertically or horizontally.
  4. Ships cannot overlap.

Goal

View Multisig Wallet vs Hot and Cold Wallets
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.