Skip to content

Commit

Permalink
merge main resolve conflits with TableUnsentCommitment
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Jan 15, 2024
2 parents 4eb4222 + c0b2fac commit 934ef74
Show file tree
Hide file tree
Showing 23 changed files with 337 additions and 181 deletions.
20 changes: 16 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.snfoundry_cache/
**/.venv
**/__pycache__

# Generated by Cargo
# will have compiled files and executables
**/debug/
**/target/
**/abi/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand All @@ -13,13 +15,23 @@
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
**/*.pdb

# Envs
**/.cargo/

# Scarb
**/Scarb.lock

# vscode
# StarkNet Foundry
**/.snfoundry_cache/

# IDEs and editors
**/.vscode/
**/.idea/

# Logs
**/log/

# Resources
runner/resources/
resources/
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scarb 2.4.1
scarb 2.4.3
16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[workspace]
resolver = "2"
members = ["runner"]

[workspace.package]
edition = "2021"
version = "0.1.0"

[workspace.dependencies]
anyhow = "1"
cairo-args-runner = "1.0"
clap = { version = "4", features = ["derive"] }
lalrpop = "0.20"
lalrpop-util = { version = "0.20", features = ["lexer", "unicode"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
49 changes: 38 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This document provides steps to build and run the Cairo Verifier.

## Building the Verifier
# Building the Verifier

To build the latest version of the verifier and create a Sierra file, follow these steps:

Expand All @@ -18,18 +18,45 @@ cd .
scarb build
```

## Running the Verifier
# Running the Verifier

After building the verifier, you can run it with the following steps:
## Getting the Parsed Proof

1. Navigate to the runner directory:
To obtain the parsed proof, follow these steps:

```bash
cd runner
```
### 1. Download Source Code

2. Run the verifier:
- Access the source code at [Cairo1 Parser Repository](https://github.com/neotheprogramist/cairo-lang/tree/parser).

```bash
cargo run --release -- ../target/dev/cairo_verifier.sierra < resources/parserin.txt
```
### 2. Install Dependencies

- Execute the command: `pipenv install`.

### 3. Activate Virtual Environment

- Activate the virtual environment with: `pipenv shell`.

### 4. Run the Parser

- Use the parser by running:
```
python src/main.py -l starknet_with_keccak < src/starkware/cairo/stark_verifier/air/example_proof.json > out.txt
```

### 5. Access Output File

- The output will be available in the `out.txt` file.

## Using the Parsed Proof

Once you have the parsed proof, you can use it as follows:

### 1. Copy Proof to Input File

- Copy the entire content or a consistent section of `out.txt` to `./resources/in.txt`.

### 3. Execute the Runner Script

- Run: `cargo run --release -- ./target/dev/cairo_verifier.sierra.json < ./resources/in.txt`

- Or run the script using: `./run.sh`.
6 changes: 0 additions & 6 deletions Scarb.lock

This file was deleted.

4 changes: 1 addition & 3 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env bash

scarb build && \
cd runner && \
cargo run --release -- ../target/dev/cairo_verifier.sierra.json < resources/parserin.txt
cargo run --release -- ./target/dev/cairo_verifier.sierra.json < ./resources/in.txt
18 changes: 9 additions & 9 deletions runner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
name = "runner"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.76"
cairo-args-runner = "1.0.0"
clap = { version = "4.4.11", features = ["derive"] }
lalrpop-util = { version = "0.20.0", features = ["lexer", "unicode"] }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
anyhow.workspace = true
cairo-args-runner.workspace = true
clap.workspace = true
lalrpop-util.workspace = true
serde.workspace = true
serde_json.workspace = true

[build-dependencies]
lalrpop = "0.20.0"
lalrpop.workspace = true
48 changes: 0 additions & 48 deletions runner/README.md

This file was deleted.

17 changes: 10 additions & 7 deletions src/air/traces.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use cairo_verifier::channel::channel::ChannelTrait;
use cairo_verifier::table_commitment::{
TableUnsentCommitment, TableCommitment, TableDecommitment, TableCommitmentWitness, table_commit,
table_decommit,
use cairo_verifier::table_commitment::table_commitment::{
TableCommitment, TableDecommitment, TableCommitmentWitness, table_commit, table_decommit,
};
use cairo_verifier::air::{public_input::PublicInput, traces_config::TracesConfig};
use cairo_verifier::channel::channel::Channel;
Expand All @@ -18,8 +17,8 @@ use cairo_verifier::channel::channel::Channel;
// values from the channel.
#[derive(Drop, Copy)]
struct TracesUnsentCommitment {
original: TableUnsentCommitment,
interaction: TableUnsentCommitment,
original: felt252,
interaction: felt252,
}

// Commitment for the Traces component.
Expand Down Expand Up @@ -62,11 +61,15 @@ fn traces_commit(
config: TracesConfig
) -> TracesCommitment {
// Read original commitment.
let original_commitment = table_commit(unsent_commitment.original, config.original);
let original_commitment = table_commit(
ref channel, unsent_commitment.original, config.original
);
// Generate interaction elements for the first interaction.
let interaction_elements = channel.random_felts_to_prover(n_interaction_elements);
// Read interaction commitment.
let interaction_commitment = table_commit(unsent_commitment.interaction, config.interaction);
let interaction_commitment = table_commit(
ref channel, unsent_commitment.interaction, config.interaction
);

TracesCommitment {
public_input: public_input,
Expand Down
4 changes: 3 additions & 1 deletion src/air/traces_config.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use cairo_verifier::vector_commitment::vector_commitment::VectorCommitmentConfigTrait;
use cairo_verifier::{common::asserts::assert_in_range, table_commitment::TableCommitmentConfig};
use cairo_verifier::{
common::asserts::assert_in_range, table_commitment::table_commitment::TableCommitmentConfig
};

const MAX_N_COLUMNS: felt252 = 128;
const AIR_LAYOUT_N_ORIGINAL_COLUMNS: felt252 = 12;
Expand Down
23 changes: 23 additions & 0 deletions src/common/array_append.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ impl ArrayU32AppendFelt of ArrayAppendTrait<u32, felt252> {
}
}

impl ArrayU32AppendFeltsSpan of ArrayAppendTrait<u32, Span<felt252>> {
fn append_little_endian(ref self: Array<u32>, element: Span<felt252>) {
let mut i = 0;
loop {
if i == element.len() {
break;
}
self.append_little_endian(*element[i]);
i += 1;
};
}
fn append_big_endian(ref self: Array<u32>, element: Span<felt252>) {
let mut i = 0;
loop {
if i == element.len() {
break;
}
self.append_big_endian(*element[i]);
i += 1;
};
}
}

impl ArrayU32AppendU128 of ArrayAppendTrait<u32, u128> {
fn append_little_endian(ref self: Array<u32>, mut element: u128) {
let mut i = 4;
Expand Down
6 changes: 3 additions & 3 deletions src/deserialization/fri.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cairo_verifier::{
fri::{fri_config::FriConfig, fri::{FriUnsentCommitment, FriWitness, FriLayerWitness}},
table_commitment::{TableCommitmentConfig, TableCommitmentWitness, TableUnsentCommitment},
table_commitment::table_commitment::{TableCommitmentConfig, TableCommitmentWitness},
vector_commitment::vector_commitment::{VectorCommitmentConfig, VectorCommitmentWitness},
};

Expand Down Expand Up @@ -56,13 +56,13 @@ struct FriUnsentCommitmentWithSerde {
}
impl IntoFriUnsentCommitment of Into<FriUnsentCommitmentWithSerde, FriUnsentCommitment> {
fn into(self: FriUnsentCommitmentWithSerde) -> FriUnsentCommitment {
let mut inner_layers = ArrayTrait::<TableUnsentCommitment>::new();
let mut inner_layers = ArrayTrait::<felt252>::new();
let mut i = 0;
loop {
if i == self.inner_layers.len() {
break;
}
inner_layers.append(TableUnsentCommitment { vector: *self.inner_layers[i] });
inner_layers.append(*self.inner_layers[i]);
i += 1;
};
FriUnsentCommitment {
Expand Down
10 changes: 5 additions & 5 deletions src/deserialization/table.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cairo_verifier::table_commitment::{
TableCommitmentConfig, TableCommitmentWitness, TableDecommitment, TableUnsentCommitment
use cairo_verifier::table_commitment::table_commitment::{
TableCommitmentConfig, TableCommitmentWitness, TableDecommitment
};
use cairo_verifier::deserialization::vector::{
VectorCommitmentConfigWithSerde, VectorCommitmentWitnessWithSerde
Expand Down Expand Up @@ -42,8 +42,8 @@ impl IntoTableCommitmentWitness of Into<TableCommitmentWitnessWithSerde, TableCo
struct TableUnsentCommitmentWithSerde {
vector: felt252,
}
impl IntoTableUnsentCommitment of Into<TableUnsentCommitmentWithSerde, TableUnsentCommitment> {
fn into(self: TableUnsentCommitmentWithSerde) -> TableUnsentCommitment {
TableUnsentCommitment { vector: self.vector }
impl IntoTableUnsentCommitment of Into<TableUnsentCommitmentWithSerde, felt252> {
fn into(self: TableUnsentCommitmentWithSerde) -> felt252 {
self.vector
}
}
11 changes: 6 additions & 5 deletions src/deserialization/traces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use cairo_verifier::{
TableCommitmentWitnessWithSerde, TableUnsentCommitmentWithSerde
}
},
table_commitment::table_commitment::{
TableCommitmentConfig, TableCommitmentWitness, TableDecommitment
},
};

#[derive(Drop, Serde)]
Expand All @@ -40,14 +43,12 @@ impl IntoTracesDecommitment of Into<TracesDecommitmentWithSerde, TracesDecommitm

#[derive(Drop, Serde)]
struct TracesUnsentCommitmentWithSerde {
original: TableUnsentCommitmentWithSerde,
interaction: TableUnsentCommitmentWithSerde,
original: felt252,
interaction: felt252,
}
impl IntoTracesUnsentCommitment of Into<TracesUnsentCommitmentWithSerde, TracesUnsentCommitment> {
fn into(self: TracesUnsentCommitmentWithSerde) -> TracesUnsentCommitment {
TracesUnsentCommitment {
original: self.original.into(), interaction: self.interaction.into(),
}
TracesUnsentCommitment { original: self.original, interaction: self.original, }
}
}

Expand Down
Loading

0 comments on commit 934ef74

Please sign in to comment.