Skip to content

Instantly share code, notes, and snippets.

View mratsim's full-sized avatar
:shipit:

Mamy Ratsimbazafy mratsim

:shipit:
  • Paris
View GitHub Profile
@mratsim
mratsim / chaining.nim
Created May 24, 2017 23:26
Nim inline iterator chaining macro
## From https://forum.nim-lang.org/t/2856
import macros
macro chaining(code: untyped): untyped =
const chainIdent = "chain"
const combineIdent = "combine"
proc inspect(depth: int, n: NimNode): NimNode =
case(n.kind)
of nnkIdent, nnkStrLit:
@mratsim
mratsim / limbs_invmod.nim
Created February 6, 2022 14:32
Pornin bingcd
# Constantine
# Copyright (c) 2018-2019 Status Research & Development GmbH
# Copyright (c) 2020-Present Mamy André-Ratsimbazafy
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
../config/common,
@mratsim
mratsim / pointer_arithmetic_arraymancer.nim
Created April 17, 2017 21:14
Nim pointer arithmetic examples
# Deleted pointer arithmetic routines
# Original data structure with pointer:
type Tensor*[B: static[Backend]; T] = object
# Size of the datastructure is 32 bytes - perfect !
dimensions: seq[int]
strides: seq[int]
offset: ptr T
data: seq[T] # Perf note: seq are always deep copied on assignement.
@mratsim
mratsim / multipairing.nim
Created August 15, 2021 12:59
Testing BLS multipairing impl
# Constantine
# Copyright (c) 2018-2019 Status Research & Development GmbH
# Copyright (c) 2020-Present Mamy André-Ratsimbazafy
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
# Standard library
@mratsim
mratsim / chase_lev_deque.nim
Created June 28, 2021 13:22
Debugging chase_lev_deques
# Nim-Taskpools
# Copyright (c) 2021 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
# chase_lev_deques.nim
# --------------------
# This file implements a Chase-Lev deque
@mratsim
mratsim / makepkg.conf
Created January 29, 2017 12:08
Makepkg config for Archlinux
#
# /etc/makepkg.conf
#
#########################################################################
# SOURCE ACQUISITION
#########################################################################
#
#-- The download utilities that makepkg should use to acquire sources
# Format: 'protocol::agent'

Batching opportunities overviews

Recap

aggregate != batching

An aggregate is spec-defined, for a receiver:

  • the signature is received aggregated from the network
  • the attesters public key must be aggregated (on BLS G1)
  • only attestations are aggregated
@mratsim
mratsim / mcl with gmp_mont
Created February 10, 2021 15:31
GMP vs Assembly for ZKP
$ ./bin/bls12_test.exe -m gmp_mont
JIT 1
ctest:module=size
ctest:module=naive
i=0 curve=BLS12_381
G1
G2
GT
G1::mulCT 656.335Kclk
G1::mul 584.777Kclk
@mratsim
mratsim / README.md
Last active January 29, 2021 00:02
Stash constant-time decimal conversion for constantine

Algorithms

Continued fractions

Continued fractions are used to convert

size_in_bits <=> size_in_decimal

for constant-time buffer preallocation when converting to decimal.

import benchy, random, streams
import jsony, jason
import eminim
#import packedjson, packedjson/deserialiser
import json
import serialization
import json_serialization except Json, toJson
type Node = ref object
active: bool