Skip to content

Commit

Permalink
working deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
neotheprogramist committed Feb 14, 2024
1 parent aaff471 commit ebac2d9
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 6 deletions.
2 changes: 1 addition & 1 deletion fact_registry/scripts/3-deploy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

sncast --profile testnet --wait deploy --class-hash 0x3eff97e91fce62babd596c1a34430ce9541ab70325cbdad5d41eb355d74b407
sncast --profile testnet --wait deploy --class-hash 0x03f536515a407d546d806777a64326302d8758b9c8aff8f70d51e26a1d535a70
2 changes: 1 addition & 1 deletion fact_registry/scripts/4-is-valid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
sncast --profile testnet \
--wait \
call \
--contract-address 0x58272d465628862ccae526250cd3385b26f6a5ea14636d48e507a9e89171ef6 \
--contract-address 0x3ba45c52dfa67d8c85f75001706f9fd5e34ab582b87d7f536f347ce35584ffc \
--function "is_valid" \
--calldata 0
4 changes: 2 additions & 2 deletions fact_registry/scripts/5-verify-proof.sh

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions out.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ fn main() -> anyhow::Result<()> {
let function = "main";
let args: VecFelt252 = serde_json::from_str(&result)?;

println!("{args:?}");

let sierra_program =
serde_json::from_str::<VersionedProgram>(&fs::read_to_string(target)?)?.into_v1()?;

Expand Down
118 changes: 118 additions & 0 deletions runner/src/vec252.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
use std::{ops::Deref, str::FromStr};

use cairo_felt::Felt252;
use serde::{de::Visitor, Deserialize};
use serde_json::Value;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum VecFelt252Error {
#[error("failed to parse number: {0}")]
NumberParseError(#[from] std::num::ParseIntError),
#[error("failed to parse bigint: {0}")]
BigIntParseError(#[from] num_bigint::ParseBigIntError),
#[error("number out of range")]
NumberOutOfRange,
}

/// `VecFelt252` is a wrapper around a vector of `Arg`.
///
/// It provides convenience methods for working with a vector of `Arg` and implements
/// `Deref` to allow it to be treated like a vector of `Arg`.
#[derive(Debug, Clone)]
pub struct VecFelt252(Vec<Felt252>);

impl VecFelt252 {
/// Creates a new `VecFelt252` from a vector of `Arg`.
///
/// # Arguments
///
/// * `args` - A vector of `Arg`.
///
/// # Returns
///
/// * `VecFelt252` - A new `VecFelt252` instance.
#[must_use]
pub fn new(args: Vec<Felt252>) -> Self {
Self(args)
}
}

impl Deref for VecFelt252 {
type Target = Vec<Felt252>;
fn deref(&self) -> &Self::Target {
&self.0
}
}

impl From<VecFelt252> for Vec<Felt252> {
fn from(args: VecFelt252) -> Self {
args.0
}
}

impl From<Vec<Felt252>> for VecFelt252 {
fn from(args: Vec<Felt252>) -> Self {
Self(args)
}
}

impl VecFelt252 {
fn visit_seq_helper(seq: &[Value]) -> Result<Self, VecFelt252Error> {
let iterator = seq.iter();
let mut args = Vec::new();

for arg in iterator {
match arg {
Value::Number(n) => {
let n = n.as_u64().ok_or(VecFelt252Error::NumberOutOfRange)?;
args.push(Felt252::from(n));
}
Value::String(n) => {
let n = num_bigint::BigUint::from_str(n)?;
args.push(Felt252::from_bytes_be(&n.to_bytes_be()));
}
Value::Array(a) => {
args.push(Felt252::from(a.len()));
let result = Self::visit_seq_helper(a)?;
args.extend(result.0);
}
_ => (),
}
}

Ok(Self::new(args))
}
}

impl<'de> Visitor<'de> for VecFelt252 {
type Value = VecFelt252;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("a list of arguments")
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: serde::de::SeqAccess<'de>,
{
let mut args = Vec::new();
while let Some(arg) = seq.next_element()? {
match arg {
Value::Number(n) => args.push(Value::Number(n)),
Value::String(n) => args.push(Value::String(n)),
Value::Array(a) => args.push(Value::Array(a)),
_ => return Err(serde::de::Error::custom("Invalid type")),
}
}

Self::visit_seq_helper(&args).map_err(|e| serde::de::Error::custom(e.to_string()))
}
}

impl<'de> Deserialize<'de> for VecFelt252 {
fn deserialize<D>(deserializer: D) -> Result<VecFelt252, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_seq(VecFelt252(Vec::new()))
}
}
4 changes: 2 additions & 2 deletions src/stark.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ struct StarkProof {
impl StarkProofImpl of StarkProofTrait {
fn verify(self: @StarkProof) -> (felt252, felt252) {
// Validate config.
// self.config.validate(SECURITY_BITS);
self.config.validate(SECURITY_BITS);

// Validate the public input.
let stark_domains = StarkDomainsImpl::new(
*self.config.log_trace_domain_size, *self.config.log_n_cosets
);
// self.public_input.validate(@stark_domains);
self.public_input.validate(@stark_domains);
let (program_hash, output_hash) = self.public_input.verify();

// Compute the initial hash seed for the Fiat-Shamir channel.
Expand Down

0 comments on commit ebac2d9

Please sign in to comment.