Skip to content

Instantly share code, notes, and snippets.

View jorpic's full-sized avatar

Max Taldykin jorpic

  • Formal Methods
  • In transit
View GitHub Profile
@jorpic
jorpic / numbers.py
Last active August 13, 2022 09:23
Calculate funny sums of cubes
# 166**3 + 500**3 + 333**3 = 166 500 333
# 296**3 + 584**3 + 415**3 = 296 584 415
# 710**3 + 656**3 + 413**3 = 710 656 413
# 828**3 + 538**3 + 472**3 = 828 538 472
# Executed in 18.47 mins
def f1():
for i in range(100, 1000):
for j in range(100, 1000):
for k in range(100, 1000):
@jorpic
jorpic / Commitment.kt
Last active June 21, 2022 14:45
Pedersen commitment in ed25519-java
package kz.cbdc.crypto.commitment
import java.util.Random
import java.math.BigInteger
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import net.i2p.crypto.eddsa.Utils
import net.i2p.crypto.eddsa.math.FieldElement
import net.i2p.crypto.eddsa.math.bigint.BigIntegerLittleEndianEncoding
@jorpic
jorpic / q.sql
Last active July 3, 2020 12:48
Пользователи, которые работают когда не в статусе Busy.
with
states_and_events as (
select userid, ctime, state, null as patch from "UserState"
union all
select userid, ctime, null, patch
from "Event"
where patch::text <> '{"id":' || modelid || '}'
),
state_groups as (
select s.*, count(state) over (partition by userid order by ctime) as state_grp
@jorpic
jorpic / README.md
Created September 24, 2019 12:45
Кратко об алгоритмах консенсуса

pBFT = Practical Byzantine Fault Tolerant

  • Требуется n = 3f + 1 узлов, чтобы противостоять сговору и злонамеренным действиям f участников.
  • 1999 Barbara Liskov et al.
  • Для достижения консенсуса участники обмениваются сообщениями в три этапа.
    • на двух этапах каждый участник отправляет сообщения всем остальным. Каждое из них нужно отдельно подписать.
      • для консенсуса между 7 участниками нужно отправить 71 сообщение
  • для консенсуса между 10 участниками нужно отправить 142 сообщения
@jorpic
jorpic / README.md
Last active December 13, 2017 12:51
Run parity in docker
$ docker pull parity/parity:v1.8.4

Создаём директорию, в которой будут храниться аккаунты и блокчейн:

$ mkdir ~/parity-data
@jorpic
jorpic / README.md
Last active July 9, 2017 02:08
SONM contracts

Check compiler version:

$ solc-0.4.11 --version
solc, the solidity compiler commandline interface
Version: 0.4.11+commit.68ef5810.Linux.g++

Compile from standard JSON

[
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
],
"name": "owners",
@jorpic
jorpic / arrays.sol
Created March 24, 2017 20:04
Generate tree of hashes from seed
// This one (with nested arrays) has a bit cleaner code but less gas-efficient.
pragma solidity ^0.4.8;
contract salttree {
// "0x98fe01c92ff2a2fa282b3aba5f8aead0", 28
// Gas usage: ~42k
@jorpic
jorpic / index.html
Created March 12, 2017 17:36
wings talk
<!DOCTYPE html>
<html>
<head>
<title>Intro to Ethereum's smart contracts</title>
<meta charset="utf-8">
<style>
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
@jorpic
jorpic / get_recent_transactions.js
Created February 24, 2017 14:11
Web3.js get all recent transactions and total value
const Web3 = require('web3');
const web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
const date = new Date();
const minTimestamp = date.setHours(date.getHours() - 1) / 1000;
console.log('Retreiving all transactions from', date);