Skip to content

Commit

Permalink
Merge next
Browse files Browse the repository at this point in the history
  • Loading branch information
phklive committed Mar 20, 2024
2 parents 210282c + b2e946a commit c4a99bc
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 163 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Runs documentation related jobs.

name: doc

on:
push:
branches: [main, next]
pull_request:
types: [opened, reopened, synchronize]

jobs:
doc:
name: doc stable on ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
- name: Install cargo make
run: cargo install cargo-make
- name: cargo make - doc
run: cargo make doc
51 changes: 5 additions & 46 deletions .github/workflows/ci.yml → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Runs the CI
# Runs linting related jobs.

name: CI
name: lint

on:
push:
branches:
- main
branches: [main, next]
pull_request:
types: [opened, reopened, synchronize]

Expand Down Expand Up @@ -35,8 +34,8 @@ jobs:
override: true
- name: Install cargo make
run: cargo install cargo-make
- name: cargo make - format
run: cargo make format
- name: cargo make - format-check
run: cargo make format-check

clippy:
name: clippy stable on ubuntu-latest
Expand All @@ -53,43 +52,3 @@ jobs:
run: cargo install cargo-make
- name: cargo make - clippy
run: cargo make clippy

doc:
name: doc stable on ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
- name: Doc
uses: actions-rs/cargo@v1
with:
command: doc
args:
- name: Check docs
uses: actions-rs/cargo@v1
env:
RUSTDOCFLAGS: -D warnings
with:
command: doc
args: --verbose --keep-going ${{matrix.args}}

test:
name: test stable on ubuntu-latest
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
- name: Install cargo make
run: cargo install cargo-make
- name: cargo make - format
run: cargo make test

26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Runs testing related jobs.

name: test

on:
push:
branches: [main, next]
pull_request:
types: [opened, reopened, synchronize]

jobs:
unit-and-integration:
name: test stable on ubuntu-latest
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
- name: Install cargo make
run: cargo install cargo-make
- name: cargo make - test
run: cargo make test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Miden node

<a href="https://github.com/0xPolygonMiden/miden-node/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
<a href="https://github.com/0xPolygonMiden/miden-node/actions/workflows/ci.yml"><img src="https://github.com/0xPolygonMiden/miden-node/actions/workflows/ci.yml/badge.svg?branch=main"></a>
<a href="https://github.com/0xPolygonMiden/miden-node/actions/workflows/test.yml"><img src="https://github.com/0xPolygonMiden/miden-node/actions/workflows/test.yml/badge.svg?branch=main"></a>
<a href="https://crates.io/crates/miden-node"><img src="https://img.shields.io/crates/v/miden-node"></a>

This repository holds the Miden node; that is, the software which processes transactions and creates blocks for the Miden rollup.
Expand Down
8 changes: 4 additions & 4 deletions block-producer/src/block_builder/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,22 +260,22 @@ impl BlockProver {
let new_account_root = execution_output
.stack_outputs()
.get_stack_word(ACCOUNT_ROOT_WORD_IDX)
.ok_or(BlockProverError::InvalidRootOutput("account".to_string()))?;
.ok_or(BlockProverError::InvalidRootOutput("account"))?;

let new_note_root = execution_output
.stack_outputs()
.get_stack_word(NOTE_ROOT_WORD_IDX)
.ok_or(BlockProverError::InvalidRootOutput("note".to_string()))?;
.ok_or(BlockProverError::InvalidRootOutput("note"))?;

let new_nullifier_root = execution_output
.stack_outputs()
.get_stack_word(NULLIFIER_ROOT_WORD_IDX)
.ok_or(BlockProverError::InvalidRootOutput("nullifier".to_string()))?;
.ok_or(BlockProverError::InvalidRootOutput("nullifier"))?;

let new_chain_mmr_root = execution_output
.stack_outputs()
.get_stack_word(CHAIN_MMR_ROOT_WORD_IDX)
.ok_or(BlockProverError::InvalidRootOutput("chain mmr".to_string()))?;
.ok_or(BlockProverError::InvalidRootOutput("chain mmr"))?;

Ok((
new_account_root.into(),
Expand Down
2 changes: 1 addition & 1 deletion block-producer/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub enum BlockProverError {
#[error("program execution failed")]
ProgramExecutionFailed(ExecutionError),
#[error("failed to retrieve {0} root from stack outputs")]
InvalidRootOutput(String),
InvalidRootOutput(&'static str),
}

// Block inputs errors
Expand Down
21 changes: 0 additions & 21 deletions miden-node.toml

This file was deleted.

4 changes: 2 additions & 2 deletions store/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Db {

/// Loads all the nullifiers from the DB.
#[instrument(target = "miden-store", skip_all, ret(level = "debug"), err)]
pub async fn select_nullifiers(&self) -> Result<Vec<(RpoDigest, BlockNumber)>> {
pub async fn select_nullifiers(&self) -> Result<Vec<(Nullifier, BlockNumber)>> {
self.pool.get().await?.interact(sql::select_nullifiers).await.map_err(|err| {
DatabaseError::InteractError(format!("Select nullifiers task failed: {err}"))
})?
Expand Down Expand Up @@ -242,7 +242,7 @@ impl Db {
acquire_done: oneshot::Receiver<()>,
block_header: BlockHeader,
notes: Vec<Note>,
nullifiers: Vec<RpoDigest>,
nullifiers: Vec<Nullifier>,
accounts: Vec<(AccountId, RpoDigest)>,
) -> Result<()> {
self.pool
Expand Down
11 changes: 6 additions & 5 deletions store/src/db/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::rc::Rc;

use miden_objects::{
crypto::hash::rpo::RpoDigest,
notes::Nullifier,
utils::serde::{Deserializable, Serializable},
BlockHeader,
};
Expand Down Expand Up @@ -152,7 +153,7 @@ pub fn upsert_accounts(
/// transaction.
pub fn insert_nullifiers_for_block(
transaction: &Transaction,
nullifiers: &[RpoDigest],
nullifiers: &[Nullifier],
block_num: BlockNumber,
) -> Result<usize> {
let mut stmt = transaction.prepare(
Expand All @@ -172,7 +173,7 @@ pub fn insert_nullifiers_for_block(
/// # Returns
///
/// A vector with nullifiers and the block height at which they were created, or an error.
pub fn select_nullifiers(conn: &mut Connection) -> Result<Vec<(RpoDigest, BlockNumber)>> {
pub fn select_nullifiers(conn: &mut Connection) -> Result<Vec<(Nullifier, BlockNumber)>> {
let mut stmt =
conn.prepare("SELECT nullifier, block_number FROM nullifiers ORDER BY block_number ASC;")?;
let mut rows = stmt.query([])?;
Expand Down Expand Up @@ -536,7 +537,7 @@ pub fn apply_block(
transaction: &Transaction,
block_header: &BlockHeader,
notes: &[Note],
nullifiers: &[RpoDigest],
nullifiers: &[Nullifier],
accounts: &[(AccountId, RpoDigest)],
) -> Result<usize> {
let mut count = 0;
Expand All @@ -556,8 +557,8 @@ fn deserialize<T: Deserializable>(data: &[u8]) -> Result<T, DatabaseError> {
}

/// Returns the high 16 bits of the provided nullifier.
pub(crate) fn get_nullifier_prefix(nullifier: &RpoDigest) -> u32 {
(nullifier[3].as_int() >> 48) as u32
pub(crate) fn get_nullifier_prefix(nullifier: &Nullifier) -> u32 {
(nullifier.most_significant_felt().as_int() >> 48) as u32
}

/// Converts a `u64` into a [Value].
Expand Down
26 changes: 15 additions & 11 deletions store/src/db/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use miden_objects::{
hash::rpo::RpoDigest,
merkle::{LeafIndex, MerklePath, SimpleSmt},
},
notes::NOTE_LEAF_DEPTH,
notes::{Nullifier, NOTE_LEAF_DEPTH},
BlockHeader, Felt, FieldElement,
};
use rusqlite::{vtab::array, Connection};
Expand All @@ -22,7 +22,7 @@ fn create_db() -> Connection {
fn test_sql_insert_nullifiers_for_block() {
let mut conn = create_db();

let nullifiers = [num_to_rpo_digest(1 << 48)];
let nullifiers = [num_to_nullifier(1 << 48)];
let block_num = 1;

// Insert a new nullifier succeeds
Expand Down Expand Up @@ -53,7 +53,7 @@ fn test_sql_insert_nullifiers_for_block() {

// test inserting multiple nullifiers
{
let nullifiers: Vec<_> = (0..10).map(num_to_rpo_digest).collect();
let nullifiers: Vec<_> = (0..10).map(num_to_nullifier).collect();
let block_num = 1;
let transaction = conn.transaction().unwrap();
let res = sql::insert_nullifiers_for_block(&transaction, &nullifiers, block_num);
Expand All @@ -74,7 +74,7 @@ fn test_sql_select_nullifiers() {
let block_num = 1;
let mut state = vec![];
for i in 0..10 {
let nullifier = num_to_rpo_digest(i);
let nullifier = num_to_nullifier(i);
state.push((nullifier, block_num));

let transaction = conn.transaction().unwrap();
Expand Down Expand Up @@ -157,7 +157,7 @@ fn test_sql_select_nullifiers_by_block_range() {
assert!(nullifiers.is_empty());

// test single item
let nullifier1 = num_to_rpo_digest(1 << 48);
let nullifier1 = num_to_nullifier(1 << 48);
let block_number1 = 1;

let transaction = conn.transaction().unwrap();
Expand All @@ -174,13 +174,13 @@ fn test_sql_select_nullifiers_by_block_range() {
assert_eq!(
nullifiers,
vec![NullifierInfo {
nullifier: nullifier1.into(),
nullifier: nullifier1,
block_num: block_number1
}]
);

// test two elements
let nullifier2 = num_to_rpo_digest(2 << 48);
let nullifier2 = num_to_nullifier(2 << 48);
let block_number2 = 2;

let transaction = conn.transaction().unwrap();
Expand All @@ -201,7 +201,7 @@ fn test_sql_select_nullifiers_by_block_range() {
assert_eq!(
nullifiers,
vec![NullifierInfo {
nullifier: nullifier1.into(),
nullifier: nullifier1,
block_num: block_number1
}]
);
Expand All @@ -215,7 +215,7 @@ fn test_sql_select_nullifiers_by_block_range() {
assert_eq!(
nullifiers,
vec![NullifierInfo {
nullifier: nullifier2.into(),
nullifier: nullifier2,
block_num: block_number2
}]
);
Expand All @@ -231,7 +231,7 @@ fn test_sql_select_nullifiers_by_block_range() {
assert_eq!(
nullifiers,
vec![NullifierInfo {
nullifier: nullifier1.into(),
nullifier: nullifier1,
block_num: block_number1
}]
);
Expand All @@ -247,7 +247,7 @@ fn test_sql_select_nullifiers_by_block_range() {
assert_eq!(
nullifiers,
vec![NullifierInfo {
nullifier: nullifier2.into(),
nullifier: nullifier2,
block_num: block_number2
}]
);
Expand Down Expand Up @@ -481,3 +481,7 @@ fn test_notes() {
fn num_to_rpo_digest(n: u64) -> RpoDigest {
RpoDigest::new([Felt::ZERO, Felt::ZERO, Felt::ZERO, Felt::new(n)])
}

fn num_to_nullifier(n: u64) -> Nullifier {
Nullifier::from(num_to_rpo_digest(n))
}
Loading

0 comments on commit c4a99bc

Please sign in to comment.