Skip to content

Instantly share code, notes, and snippets.

@ajgara
ajgara / stone_prover_merkle_trees.py
Last active September 27, 2023 15:58
Stone prover merkle trees
from Crypto.Hash import keccak
p = 0x800000000000011000000000000000000000000000000000000000000000001
r = 2^256
# Example 1
# AIR: Fibonacci 2 columns
# Blow up factor = 2
# Queries = 1
@ajgara
ajgara / transcript_tests.cpp
Created September 22, 2023 15:49
Stone prover transcript tests
// Copyright 2023 StarkWare Industries Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.starkware.co/open-source-license/
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an "AS IS" BASIS,
@ajgara
ajgara / Dockerfile
Created September 20, 2023 19:46
Dockerfile to run sandstorm
FROM rustlang/rust:nightly as builder
# Compile the sandstorm prover.
COPY . ./app
WORKDIR /app
RUN cargo build --release
# Install Python3.9 and Cairo dependencies.
RUN apt-get update \
&& apt-get install -y python3.9 python3.9-venv python3.9-dev python3-pip libgmp3-dev \
extern crate sha3;
use sha3::{Digest, Keccak256};
use lambdaworks_math::{unsigned_integer::element::U256, traits::ByteConversion, field::{fields::fft_friendly::stark_252_prime_field::Stark252PrimeField, element::FieldElement}};
const MODULUS: U256 = U256::from_hex_unchecked("800000000000011000000000000000000000000000000000000000000000001");
const R_MONTGOMERY: U256 = U256::from_hex_unchecked("7fffffffffffdf0ffffffffffffffffffffffffffffffffffffffffffffffe1");
const MODULUS_MAX_MULTIPLE: U256 = U256::from_hex_unchecked("f80000000000020f00000000000000000000000000000000000000000000001f");
const R_INV: U256 = U256::from_hex_unchecked("0x40000000000001100000000000012100000000000000000000000000000000");
fn keccak_hash(data: &[u8]) -> Keccak256 {
@ajgara
ajgara / stone_prover_transcript.py
Created September 12, 2023 16:06
Stone prover transcript written in python
from Crypto.Hash import keccak
MODULUS = 0x800000000000011000000000000000000000000000000000000000000000001
R_MONTGOMERY = 0x7fffffffffffdf0ffffffffffffffffffffffffffffffffffffffffffffffe1
# This is the max multiple that enters in the big int representation, used for
# uniform sampling over the finite field.
MODULUS_MAX_MULTIPLE = 0xf80000000000020f00000000000000000000000000000000000000000000001f
def keccak_hash(data):