Skip to content

Instantly share code, notes, and snippets.

View mratsim's full-sized avatar
:shipit:

Mamy Ratsimbazafy mratsim

:shipit:
  • Paris
View GitHub Profile
1. Agree: use OpenAPI (alternatives were SSZ and Protobuf)
Prysmatic comment: Protobuf can be easily switched to OopenAPI so no blocker here
—————
2. Agree: use versioning (issue to be opened on the versioning string)
—————
OpenAPI: Json, integer and byte format
- 53-bit or 64-bit integers?
@mratsim
mratsim / erase_from_memory.h
Created April 14, 2020 10:05 — forked from mimoo/erase_from_memory.h
Include this file to get the `erase_from_memory` function that zeros memory. See https://www.cryptologie.net/article/419/zeroing-memory-compiler-optimizations-and-memset_s/
#ifndef __ERASE_FROM_MEMORY_H__
#define __ERASE_FROM_MEMORY_H__ 1
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdlib.h>
#include <string.h>
void *erase_from_memory(void *pointer, size_t size_data, size_t size_to_remove) {
#ifdef __STDC_LIB_EXT1__
memset_s(pointer, size_data, 0, size_to_remove);
import ../beacon_chain/spec/digest # from NBC build directory
import stew/endians2
func fakeHash*(index: SomeInteger): Eth2Digest =
## Create fake hashes
## Those are just the value serialized in big-endian
## We add 16x16 to avoid having a zero hash are those are special cased
## We store them in the first 8 bytes
## as those are the one used in hash tables Table[Eth2Digest, T]
result.data[0 ..< 8] = (16*16+index).uint64.toBytesBE()
@mratsim
mratsim / proto_array_debug.nim
Created April 6, 2020 14:13
Fork choice with debug traces
# beacon_chain
# Copyright (c) 2018-2020 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://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
std/tables, std/options, std/typetraits,
"""
https://cryptosith.org/michael/data/talks/2013-08-01-SIAMAG13.pdf
https://www.issac-conference.org/2015/Slides/Schost.pdf
http://www.craigcostello.com.au/pairings/PairingsForBeginners.pdf
"""
fresh_compute = False # Perform expensive-(ish) computations for curve orders
field_modulus = 22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825577
desired_curve_order = 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177
@mratsim
mratsim / 2020-03-12 Eth Impl Call 35.txt
Created March 12, 2020 14:37
2020-03-12 Eth Impl Call #35
https://github.com/ethereum/eth2.0-pm/issues/132
——————
Nimbus
PM:
- Created targets for March sprint
- Interop
- Starting auditing
# Constant-time modular arithmetic with carry test
# Compile with Clang, GCC is really bad
import macros
func wordsRequired(totalBits, bitsPerWords: int): int {.compileTime.} =
## Compute the number of limbs required
# from the **announced** bit length
(totalBits + bitsPerWords - 1) div bitsPerWords
import blscurve, stew/byteutils
type KeyPairSig = tuple[pubkey: PublicKey, seckey: SecretKey, sig: Signature]
proc main() =
var alice, bob, eve, mallory: KeyPairSig
var aggSig: Signature
let message = hexToSeqByte"0x0CC94C98643AEA8DC16D91881A67FEDC306DF13A9C710CDE78C1021405A3D47E"
# doAssert aggSig.fromHex"0xa83c648423e410aa2dd900b45614bbd5f4071992fcebb5bf096978b60a05610b466ea9a0943afdba7ed56e2d548170ad1454d83c3d882e5fa6f107a450c50692171651cb809c84410d940fe2c9c22176a2dbeed9a618158351176fb89b4fa88e"
# Trying to isolate stack smashing bug
import blscurve, nimcrypto
proc main() =
for i in 0 ..< 100:
echo "iteration ", i, ":"
var ikm: array[32, byte]
@mratsim
mratsim / Eth2.0 Call 34
Created February 27, 2020 15:05
Eth2.0 Call 34
https://github.com/ethereum/eth2.0-pm/issues/129
Nimbus team (3 weeks)
- Core spec:
- Autodetect/Report on skipped tests (that were deactivating during implementation/refactoring)
- BLS signatures ready, we were waiting for EF vectors fixes but will go ahead to allow finishing honest validators spec
- WIP attestation aggregation
- WIP fork choice
- Bounty program restarted, 1st bounties: