Skip to content

Instantly share code, notes, and snippets.

View richardkiss's full-sized avatar

Richard Kiss richardkiss

View GitHub Profile
@richardkiss
richardkiss / chia-db.md
Created December 21, 2023 21:06
Benchmarking `chia-blockchain` DB

This is a report on the chia-blockchain sqlite3 DB. The concern is that some operations are slow, and get slower over time. The symptom is the conversion from v1 of the DB to v2 never finishes and seems to get slower asymptotically as time goes on. This may affect performance during regular day-to-day operation, since DB conversion is not wholy different from DB operations performed on a day-to-day basis.

Summary

There are six tables and eight indices.

@richardkiss
richardkiss / ffi.py
Last active December 17, 2023 08:02
Using ctypes in python to call a mojo function (mojo 0.6)
from ctypes import CFUNCTYPE, c_int
Ft = CFUNCTYPE(c_int, c_int, c_int)
def entry_point(ptr_to_function):
function_pointer = Ft(ptr_to_function)
result = function_pointer(5000, 2)
return result
@richardkiss
richardkiss / chialisp_distribution.md
Created July 13, 2023 01:09
Overview of wheels for chialisp distribution

The load_clvm method has been duplicated in multiple places, each version with slightly different semantics and bugs. We present here a set of tiny python wheels that solve many problems with chialisp contracts including:

  • distribution of libraries
  • distribution of compiled .hex files
  • automatic dynamic builds in development mode
  • dependency analysis (on library include files)

runtime_builder

@richardkiss
richardkiss / deal.py
Created April 25, 2023 17:44
Hand permutations to index and vice versa
from math import comb
from typing import List
Hand = List[int]
def hand_from_index(index: int, deck_indices: List[int], hand_size: int) -> Hand:
hand = []
deck_size = len(deck_indices)
(mod V0 ;; V0 should be 0
(include *standard-cl-21*)
;; projective point: ((X . Y) . Z)
(defun-inline x-for-p (POINT) (f (f POINT)))
(defun-inline y-for-p (POINT) (r (f POINT)))
(defun-inline z-for-p (POINT) (r POINT))
@richardkiss
richardkiss / nvidia-proxmox-kernel.md
Last active February 27, 2024 03:23
Minimal install of nvidia kernel drivers on proxmox host
@richardkiss
richardkiss / copy-protection.cl
Created August 31, 2022 18:09
A generator blob that check parameters
(mod arguments
; this generator blob will fail if the correct run-time parameters are not included
(defun sha256tree
(TREE)
(if (l TREE)
(sha256 2 (sha256tree (f TREE)) (sha256tree (r TREE)))
(sha256 1 TREE)
)
@richardkiss
richardkiss / block-compression.md
Created August 23, 2022 20:00
Block Compression: serialization with back-references

Block Generators

Block generators in Chia are clvm programs that, when run with particular arguments, produce a list of coin spends. This provides opportunity to do compression by recognizing patterns and encoding.

CLVM Serialization

The standard serialization mechanism of clvm is defined here.

If you review this specification, you'll see that deserialization begins by inspecting the first byte. If the byte is 0xff, the object is a pair. If the byte is 0x00 to 0xfb, the object is an atom whose length is partially or fully encoded by this first byte.

@richardkiss
richardkiss / comp-test.py
Last active December 23, 2021 03:35
offer-zlib-compression
import zlib
from chia.wallet.puzzles.load_clvm import load_clvm
from chia.wallet.puzzles import p2_delegated_puzzle_or_hidden_puzzle as standard_puzzle
from chia.wallet.puzzles.cc_loader import CC_MOD
OFFER_MOD = load_clvm("settlement_payments.clvm")
puzzle_dict = bytes(OFFER_MOD) + bytes(standard_puzzle.MOD) + bytes(CC_MOD)
@richardkiss
richardkiss / settlement_payments.md
Last active November 5, 2023 09:40
Ideas about Offers on Chia

We introduce a new puzzle, "settlement_payments", which pays out coins and make an announcement for each new coin created.

settlement_payments.cl:

(mod (coins_paid)
  ;; `coins_paid` is a list of notarized coin payments
  ;; a notarized coin payment is `(nonce puzzle_hash amount ...)`
  ;; Each notarized coin payment creates a `(CREATE_COIN puzzle_hash amount)` payment