Skip to content

Commit

Permalink
Merge pull request #13 from HerodotusDev/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
tiagofneto authored Dec 15, 2023
2 parents 7ccaa5f + 3c17595 commit b8fba4c
Show file tree
Hide file tree
Showing 54 changed files with 384 additions and 463 deletions.
13 changes: 13 additions & 0 deletions .github/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: CI
on:
push:
merge_group:
pull_request:
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
- run: scarb fmt --check
- run: scarb test
3 changes: 1 addition & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
scarb 2.3.1
starknet-foundry 0.11.0
scarb 2.4.0
7 changes: 0 additions & 7 deletions Cargo.lock

This file was deleted.

18 changes: 0 additions & 18 deletions Cargo.toml

This file was deleted.

8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
## Build
``` sh
scarb build
cargo build
```

## Test
``` sh
snforge test
cargo test
scarb test
```

## Format
``` sh
scarb fmt
cargo fmt
```

## Clean
``` sh
scarb clean
cargo clean
```
```
45 changes: 1 addition & 44 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,5 @@
version = 1

[[package]]
name = "cairo_blake2s"
name = "cairo_verifier"
version = "0.1.0"
source = "git+https://github.com/HerodotusDev/cairo-blake2s.git#7aea89a1a9fbdfb689faa6086c8dd68abae0b5cd"

[[package]]
name = "channel"
version = "0.1.0"
dependencies = [
"cairo_blake2s",
"common",
]

[[package]]
name = "channel_contract"
version = "0.1.0"
dependencies = [
"channel",
"openzeppelin",
"snforge_std",
]

[[package]]
name = "common"
version = "0.1.0"

[[package]]
name = "openzeppelin"
version = "0.8.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.8.0#c23e8e96de60e6e3159b1ff8591a1187269c0eb7"

[[package]]
name = "snforge_std"
version = "0.1.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.11.0#5465c41541c44a7804d16318fab45a2f0ccec9e7"

[[package]]
name = "structs"
version = "0.1.0"

[[package]]
name = "verifier"
version = "0.1.0"
dependencies = [
"structs",
]
27 changes: 1 addition & 26 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
[workspace]
members = [
"src/structs",
"src/verifier",
"src/channel",
"src/common",
"contract/channel_contract",
]
[package]
name = "cairo_verifier"
version = "0.1.0"

[workspace.dependencies]
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.8.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.11.0" }
cairo_blake2s = { git = "https://github.com/HerodotusDev/cairo-blake2s.git" }
starknet = "2.3.1"
structs = { path = "src/structs" }
verifier = { path = "src/verifier" }
channel = { path = "src/channel" }
common = { path = "src/common" }

[tool.snforge]
exit_first = true

# Default profile
[tool.sncast]
account = "cairo1_verifier"
url = "https://devnet.starknet.visoft.solutions"
13 changes: 0 additions & 13 deletions contract/channel_contract/Scarb.toml

This file was deleted.

17 changes: 0 additions & 17 deletions contract/channel_contract/src/lib.cairo

This file was deleted.

19 changes: 0 additions & 19 deletions contract/channel_contract/tests/test_contract.cairo

This file was deleted.

4 changes: 0 additions & 4 deletions rust-toolchain.toml

This file was deleted.

20 changes: 0 additions & 20 deletions rustfmt.toml

This file was deleted.

4 changes: 4 additions & 0 deletions src/channel.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod channel;

#[cfg(test)]
mod tests;
7 changes: 0 additions & 7 deletions src/channel/Scarb.toml

This file was deleted.

26 changes: 6 additions & 20 deletions src/channel/src/lib.cairo → src/channel/channel.cairo
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
use common::flip_endiannes::FlipEndiannessTrait;
use core::option::OptionTrait;
use core::traits::TryInto;
use core::array::ArrayTrait;
use core::traits::Into;
use common::to_array::ToArrayTrait;
use common::blake2s::blake2s;
use cairo_verifier::common::{
flip_endiannes::FlipEndiannessTrait, to_array::ToArrayTrait, blake2s::blake2s
};

const C_PRIME_AS_UINT256_LOW: u128 = 31;
const C_PRIME_AS_UINT256_HIGH: u128 =
329648542954659146201578277794459156480; // 31 * 0x8000000000000110000000000000000;
const STARK_PRIME: u256 =
3618502788666131213697322783095070105623107215331596699973092056135872020481;
const INVERSE_2_TO_256_MOD_STARK_PRIME: felt252 = 113078212145816603762751633895895194930089271709401121343797004406777446400;
const INVERSE_2_TO_256_MOD_STARK_PRIME: felt252 =
113078212145816603762751633895895194930089271709401121343797004406777446400;

#[derive(Drop)]
struct Channel {
digest: u256,
counter: u256,
}

trait ChannelTrait {
fn new(digest: u256) -> Channel;

// Generate randomness.
fn random_uint256_to_prover(ref self: Channel) -> u256;
fn random_felts_to_prover(ref self: Channel, n: felt252) -> Array<felt252>;
// // Reads a 64bit integer from the prover.
// fn read_uint256_from_prover(ref self: Channel) -> u256;
// // Reads a field elements from the prover
// fn read_felts_from_prover(ref self: Channel, n: felt252) -> Array<felt252>;
}

#[generate_trait]
impl ChannelImpl of ChannelTrait {
fn new(digest: u256) -> Channel {
Channel { digest: digest, counter: 0 }
Expand Down
1 change: 1 addition & 0 deletions src/channel/tests.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod test_channel;
33 changes: 33 additions & 0 deletions src/channel/tests/test_channel.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use cairo_verifier::channel::channel::ChannelTrait;

#[test]
#[available_gas(9999999999)]
fn test_random_felts_to_prover() {
let mut channel = ChannelTrait::new(
u256 { low: 0xf7685ebd40e852b164633a4acbd3244c, high: 0xe8e77626586f73b955364c7b4bbf0bb7 }
);
let random = channel.random_felts_to_prover(3);
assert(
*random[0] == 3199910790894706855027093840383592257502485581126271436027309705477370004002,
'invalid random felts[0]'
);
assert(
*random[1] == 2678311171676075552444787698918310126938416157877134200897080931937186268438,
'invalid random felts[1]'
);
assert(
*random[2] == 2409925148191156067407217062797240658947927224212800962983204460004996362724,
'invalid random felts[2]'
);
}

#[test]
#[available_gas(9999999999)]
fn test_random_uint256_to_prover() {
let mut channel = ChannelTrait::new(0);
let random = channel.random_uint256_to_prover();
assert(
random == 0xae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3,
'invalid random uint256'
);
}
2 changes: 0 additions & 2 deletions src/channel/tests/tests.cairo

This file was deleted.

14 changes: 0 additions & 14 deletions src/channel/tests/tests/random_felts_to_prover.cairo

This file was deleted.

10 changes: 0 additions & 10 deletions src/channel/tests/tests/random_uint256_to_prover.cairo

This file was deleted.

9 changes: 6 additions & 3 deletions src/common/src/lib.cairo → src/common.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mod blake2s;
mod flip_endiannes;
mod from_span;
mod horner_eval;
mod to_array;
mod from_span;
mod flip_endiannes;
mod blake2s;

#[cfg(test)]
mod tests;
6 changes: 0 additions & 6 deletions src/common/Scarb.lock

This file was deleted.

5 changes: 0 additions & 5 deletions src/common/Scarb.toml

This file was deleted.

Loading

0 comments on commit b8fba4c

Please sign in to comment.