diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d320426e7..2238ee7d43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changes + +- Remove ocaml-interop dependency, fix + [#1235](https://github.com/o1-labs/mina-rust/issues/1235) +([#1646](https://github.com/o1-labs/mina-rust/pull/1646)) + ## [0.18.0] - 2025-11-04 ### OCaml node diff --git a/Cargo.lock b/Cargo.lock index 31144fe37a..7ee3029c66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2072,12 +2072,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "cty" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" - [[package]] name = "curve25519-dalek" version = "4.1.2" @@ -5325,7 +5319,6 @@ dependencies = [ "mina-signer", "num-bigint", "o1-utils", - "ocaml-interop", "once_cell", "poly-commitment", "poseidon", @@ -5957,34 +5950,6 @@ dependencies = [ "ruzstd", ] -[[package]] -name = "ocaml-boxroot-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5186393bfbee4ce2bc5bbb82beafb77e85c1d0a557e3cfc8c8a0d63d7845fed5" -dependencies = [ - "cc", -] - -[[package]] -name = "ocaml-interop" -version = "0.8.8" -source = "git+https://github.com/sebastiencs/ocaml-interop.git?branch=closure-values#f9ecf016e725589a402f3d61e120d96b8284d506" -dependencies = [ - "ocaml-boxroot-sys", - "ocaml-sys", - "static_assertions", -] - -[[package]] -name = "ocaml-sys" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73ec6ca7d41458442627435afb8f4671e83fd642e8a560171d671a1f679aa3cf" -dependencies = [ - "cty", -] - [[package]] name = "oid-registry" version = "0.6.1" diff --git a/Cargo.toml b/Cargo.toml index 54c76dc7ca..01d01ca66a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -160,7 +160,6 @@ num_cpus = "1.0" num_enum = "0.5.7" o1-utils = { git = "https://github.com/o1-labs/proof-systems", rev = "0b0fd5fe73964d2a3628c788e40ead819a8a806d" } object = "0.37.1" -ocaml-interop = { git = "https://github.com/sebastiencs/ocaml-interop.git", branch = "closure-values" } once_cell = "1" p256 = { version = "0.13", features = ["default", "ecdh", "ecdsa"] } p384 = "0.13" diff --git a/Makefile b/Makefile index 34c1d0cc7d..c8236cea7f 100644 --- a/Makefile +++ b/Makefile @@ -295,7 +295,7 @@ setup-taplo: ## Install taplo TOML formatter @if taplo --version 2>/dev/null | grep -q ${TAPLO_CLI_VERSION}; then \ echo "taplo ${TAPLO_CLI_VERSION} already installed"; \ else \ - cargo install taplo-cli --version ${TAPLO_CLI_VERSION} --force; \ + cargo +nightly install taplo-cli --version ${TAPLO_CLI_VERSION} --force; \ fi .PHONY: setup diff --git a/core/src/block/genesis.rs b/core/src/block/genesis.rs index 1d69c5b429..547cb290bd 100644 --- a/core/src/block/genesis.rs +++ b/core/src/block/genesis.rs @@ -1,10 +1,9 @@ +use crate::constants::{constraint_constants, slots_per_window}; use mina_p2p_messages::{ bigint::InvalidBigInt, v2::{self, StateHash}, }; -use crate::constants::{constraint_constants, slots_per_window}; - #[allow(clippy::too_many_arguments)] pub fn genesis_and_negative_one_protocol_states( constants: v2::MinaBaseProtocolConstantsCheckedValueStableV1, diff --git a/core/src/block/mod.rs b/core/src/block/mod.rs index d490ed1de8..8ce99d549a 100644 --- a/core/src/block/mod.rs +++ b/core/src/block/mod.rs @@ -1,18 +1,14 @@ -mod block_with_hash; -pub use block_with_hash::{BlockHeaderWithHash, BlockWithHash}; - mod applied_block; -pub use applied_block::AppliedBlock; - -pub mod prevalidate; - +mod block_with_hash; pub mod genesis; +pub mod prevalidate; -use std::sync::Arc; - +pub use applied_block::AppliedBlock; +pub use block_with_hash::{BlockHeaderWithHash, BlockWithHash}; pub use mina_p2p_messages::v2::{ MinaBlockBlockStableV2 as Block, MinaBlockHeaderStableV2 as BlockHeader, StateHash as BlockHash, }; +use std::sync::Arc; pub type ArcBlock = Arc; pub type ArcBlockWithHash = BlockWithHash>; diff --git a/core/src/block/prevalidate.rs b/core/src/block/prevalidate.rs index 432c76e7a5..edf9b19116 100644 --- a/core/src/block/prevalidate.rs +++ b/core/src/block/prevalidate.rs @@ -1,7 +1,6 @@ -use serde::{Deserialize, Serialize}; - use super::ArcBlockWithHash; use crate::constants::PROTOCOL_VERSION; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone)] pub enum BlockPrevalidationError { diff --git a/ledger/Cargo.toml b/ledger/Cargo.toml index bad1823a5c..e353ca8633 100644 --- a/ledger/Cargo.toml +++ b/ledger/Cargo.toml @@ -68,7 +68,6 @@ wasm-bindgen-futures = { workspace = true } [target.'cfg(not(target_family = "wasm"))'.dependencies] zstd = { workspace = true, optional = true } -ocaml-interop = { workspace = true, optional = true } reqwest = { workspace = true, features = ["blocking"] } [dev-dependencies] diff --git a/ledger/dune b/ledger/dune deleted file mode 100644 index c4e721cd2d..0000000000 --- a/ledger/dune +++ /dev/null @@ -1,23 +0,0 @@ -(dirs :standard \ target) -(rule - (targets libmina_tree.a libmina_tree.so) - (deps (source_tree .)) - (action - (no-infer - (progn - (run sh -c "cargo build --release --features ocaml-interop") - (run sh -c - "cp target/release/libmina_tree.so ./libmina_tree.so 2> /dev/null || \ - cp target/release/libmina_tree.dylib ./libmina_tree.so") - (run cp target/release/libmina_tree.a ./libmina_tree.a) - )))) - -(library - (name mina_tree) - (libraries - core_kernel - core - ) - (public_name mina_tree) - (c_library_flags -lpthread -lc -lm) - (foreign_archives mina_tree)) diff --git a/ledger/mina_tree.ml b/ledger/mina_tree.ml deleted file mode 100644 index 01988a58a3..0000000000 --- a/ledger/mina_tree.ml +++ /dev/null @@ -1,152 +0,0 @@ - -type ondisk_database -type ondisk_batch -type database -type mask - -type addr = string -type account = bytes -type token_id = bytes -type account_id = bytes -type pubkey = bytes - -type ondisk_key = Core.Bigstring.t -type ondisk_value = Core.Bigstring.t - -type 'a ondisk_result = ('a, string) result - -type rust_dberror = - | Account_location_not_found - | Out_of_leaves - | Malformed_database - -type rust_path = [ `Left of bytes | `Right of bytes ] - -type rust_grandchildren = [ `Check | `Recursive | `I_promise_I_am_reparenting_this_mask ] - -module Rust = struct - - (* type unattached_mask *) - (* type attached_mask *) - (* type any_mask *) - - (* external transaction_fuzzer : (bytes -> bytes) -> (bytes -> bytes) -> unit = "rust_transaction_fuzzer" *) - - external mask_create : int -> mask = "rust_mask_create" - external mask_get_directory : mask -> string option = "rust_mask_get_directory" - external mask_get_uuid : mask -> string = "rust_mask_get_uuid" - external mask_depth : mask -> int = "rust_mask_depth" - external mask_close : mask -> unit = "rust_mask_close" - external mask_get : mask -> addr -> account option = "rust_mask_get" - external mask_get_batch : mask -> addr list -> (addr * (account option)) list = "rust_mask_get_batch" - external mask_get_list : mask -> bytes list = "rust_mask_get_list" - external mask_accounts : mask -> bytes list = "rust_mask_accounts" - external mask_get_inner_hash_at_addr : mask -> addr -> bytes = "rust_mask_get_inner_hash_at_addr" - external mask_set_inner_hash_at_addr : mask -> addr -> bytes -> unit = "rust_mask_set_inner_hash_at_addr" - external mask_get_at_index : mask -> int -> account = "rust_mask_get_at_index" - external mask_iter : mask -> (int -> bytes -> unit) -> unit = "rust_mask_iter" - external mask_location_of_account : mask -> account_id -> addr option = "rust_mask_location_of_account" - external mask_location_of_account_batch : mask -> account_id list -> (account_id * (addr option)) list = "rust_mask_location_of_account_batch" - external mask_last_filled : mask -> addr option = "rust_mask_last_filled" - external mask_token_owners : mask -> bytes list = "rust_mask_token_owners" - external mask_token_owner : mask -> token_id -> account_id option = "rust_mask_token_owner" - external mask_tokens : mask -> pubkey -> token_id list = "rust_mask_tokens" - external mask_set : mask -> addr -> account -> unit = "rust_mask_set" - external mask_index_of_account : mask -> account_id -> int = "rust_mask_index_of_account" - external mask_set_at_index : mask -> int -> account -> unit = "rust_mask_set_at_index" - external mask_get_or_create_account : mask -> account_id -> account -> (([ `Added | `Existed ] * addr), rust_dberror) result = "rust_mask_get_or_create_account" - external mask_num_accounts : mask -> int = "rust_mask_num_accounts" - (* external mask_fold_with_ignored_accounts : mask -> bytes list -> bytes -> (bytes -> unit) -> bytes = "rust_mask_fold_with_ignored_accounts" *) - (* external mask_fold : mask -> bytes -> (bytes -> unit) -> bytes = "rust_mask_fold" *) - (* external mask_fold_until : mask -> bytes -> (bytes -> bool) -> bytes = "rust_mask_fold_until" *) - external mask_merkle_root : mask -> bytes = "rust_mask_merkle_root" - external mask_remove_accounts : mask -> account_id list -> unit = "rust_mask_remove_accounts" - external mask_merkle_path : mask -> addr -> rust_path list = "rust_mask_merkle_path" - external mask_merkle_path_at_addr : mask -> addr -> rust_path list = "rust_mask_merkle_path_at_addr" - external mask_merkle_path_at_index : mask -> int -> rust_path list = "rust_mask_merkle_path_at_index" - external mask_set_all_accounts_rooted_at : mask -> addr -> bytes list -> unit = "rust_mask_set_all_accounts_rooted_at" - external mask_set_batch_accounts : mask -> (addr * account) list -> unit = "rust_mask_set_batch_accounts" - external mask_get_all_accounts_rooted_at : mask -> addr -> (addr * account) list = "rust_mask_get_all_accounts_rooted_at" - (* TODO: Make those method *) - external mask_foldi : mask -> (addr -> bytes -> unit) -> unit = "rust_mask_foldi" - external mask_foldi_with_ignored_accounts : mask -> account_id list -> (addr -> bytes -> unit) -> unit = "rust_mask_foldi_with_ignored_accounts" - - (* external mask_get_parent : mask -> mask = "rust_mask_get_parent" *) - (* external mask_get_hash : mask -> addr -> bytes = "rust_mask_get_hash" *) - external mask_commit : mask -> unit = "rust_mask_commit" - external mask_copy : mask -> mask = "rust_mask_copy" - - (* external mask_set_parent : mask -> mask -> mask = "rust_mask_set_parent" *) - (* external mask_register_mask : mask -> mask -> mask = "rust_mask_register_mask" *) - (* external mask_register_mask : any_mask -> unattached_mask -> attached_mask = "rust_mask_register_mask" *) - (* external mask_unregister_mask : mask -> rust_grandchildren -> mask = "rust_mask_unregister_mask" - * external mask_remove_and_reparent : mask -> mask -> unit = "rust_mask_remove_and_reparent" *) - - external database_create : int -> string option -> database = "rust_database_create" - external database_get_uuid : database -> string = "rust_database_get_uuid" - external database_get_directory : database -> string option = "rust_database_get_directory" - external database_depth : database -> int = "rust_database_depth" - external database_create_checkpoint : database -> string -> database = "rust_database_create_checkpoint" - external database_make_checkpoint : database -> string -> unit = "rust_database_make_checkpoint" - external database_close : database -> unit = "rust_database_close" - external database_get : database -> addr -> account option = "rust_database_get" - external database_get_batch : database -> addr list -> (addr * (account option)) list = "rust_database_get_batch" - external database_get_list : database -> bytes list = "rust_database_get_list" - external database_accounts : database -> bytes list = "rust_database_accounts" - external database_get_inner_hash_at_addr : database -> addr -> bytes = "rust_database_get_inner_hash_at_addr" - external database_set_inner_hash_at_addr : database -> addr -> bytes -> unit = "rust_database_set_inner_hash_at_addr" - external database_get_at_index : database -> int -> account = "rust_database_get_at_index" - external database_iter : database -> (int -> bytes -> unit) -> unit = "rust_database_iter" - external database_location_of_account : database -> account_id -> addr option = "rust_database_location_of_account" - external database_location_of_account_batch : database -> account_id list -> (account_id * (addr option)) list = "rust_database_location_of_account_batch" - external database_last_filled : database -> addr option = "rust_database_last_filled" - external database_token_owners : database -> bytes list = "rust_database_token_owners" - external database_token_owner : database -> token_id -> account_id option = "rust_database_token_owner" - external database_tokens : database -> pubkey -> token_id list = "rust_database_tokens" - external database_set : database -> addr -> account -> unit = "rust_database_set" - external database_index_of_account : database -> account_id -> int = "rust_database_index_of_account" - external database_set_at_index : database -> int -> account -> unit = "rust_database_set_at_index" - external database_get_or_create_account : database -> account_id -> account -> (([ `Added | `Existed ] * addr), rust_dberror) result = "rust_database_get_or_create_account" - external database_num_accounts : database -> int = "rust_database_num_accounts" - (* external database_fold_with_ignored_accounts : database -> bytes list -> bytes -> (bytes -> unit) -> bytes = "rust_database_fold_with_ignored_accounts" *) - (* external database_fold : database -> bytes -> (bytes -> unit) -> bytes = "rust_database_fold" *) - (* external database_fold_until : database -> bytes -> (bytes -> bool) -> bytes = "rust_database_fold_until" *) - external database_merkle_root : database -> bytes = "rust_database_merkle_root" - external database_remove_accounts : database -> account_id list -> unit = "rust_database_remove_accounts" - external database_merkle_path : database -> addr -> rust_path list = "rust_database_merkle_path" - external database_merkle_path_at_addr : database -> addr -> rust_path list = "rust_database_merkle_path_at_addr" - external database_merkle_path_at_index : database -> int -> rust_path list = "rust_database_merkle_path_at_index" - external database_set_all_accounts_rooted_at : database -> addr -> bytes list -> unit = "rust_database_set_all_accounts_rooted_at" - external database_set_batch_accounts : database -> (addr * account) list -> unit = "rust_database_set_batch_accounts" - external database_get_all_accounts_rooted_at : database -> addr -> (addr * account) list = "rust_database_get_all_accounts_rooted_at" - - (* TODO: Make those method *) - external database_foldi : database -> (addr -> bytes -> unit) -> unit = "rust_database_foldi" - external database_foldi_with_ignored_accounts : database -> account_id list -> (addr -> bytes -> unit) -> unit = "rust_database_foldi_with_ignored_accounts" - - external ondisk_database_create : string -> ondisk_database ondisk_result = "rust_ondisk_database_create" - external ondisk_database_create_checkpoint : ondisk_database -> string -> ondisk_database ondisk_result = "rust_ondisk_database_create_checkpoint" - external ondisk_database_make_checkpoint : ondisk_database -> string -> unit ondisk_result = "rust_ondisk_database_make_checkpoint" - external ondisk_database_get_uuid : ondisk_database -> string ondisk_result = "rust_ondisk_database_get_uuid" - external ondisk_database_close : ondisk_database -> unit ondisk_result = "rust_ondisk_database_close" - external ondisk_database_get : ondisk_database -> ondisk_key -> (ondisk_value option) ondisk_result = "rust_ondisk_database_get" - external ondisk_database_get_batch : ondisk_database -> ondisk_key list -> (ondisk_value option list) ondisk_result = "rust_ondisk_database_get_batch" - external ondisk_database_set : ondisk_database -> ondisk_key -> ondisk_value -> unit ondisk_result = "rust_ondisk_database_set" - external ondisk_database_set_batch : ondisk_database -> Core.Bigstring.t list -> (ondisk_key * ondisk_value) list -> unit ondisk_result = "rust_ondisk_database_set_batch" - external ondisk_database_remove : ondisk_database -> ondisk_key -> unit ondisk_result = "rust_ondisk_database_remove" - external ondisk_database_to_alist : ondisk_database -> ((ondisk_key * ondisk_value) list) ondisk_result = "rust_ondisk_database_to_alist" - - external ondisk_database_batch_create : unit -> ondisk_batch = "rust_ondisk_database_batch_create" - external ondisk_database_batch_set : ondisk_batch -> ondisk_key -> ondisk_value -> unit = "rust_ondisk_database_batch_set" - external ondisk_database_batch_remove : ondisk_batch -> ondisk_key -> unit = "rust_ondisk_database_batch_remove" - external ondisk_database_batch_run : ondisk_database -> ondisk_batch -> unit ondisk_result = "rust_ondisk_database_batch_run" - external ondisk_database_gc : ondisk_database -> unit ondisk_result = "rust_ondisk_database_gc" - - (* For testing *) - external test_random_accounts : (bytes -> bytes) -> unit = "rust_test_random_accounts" - external test_random_account_ids : (bytes -> int) -> unit = "rust_test_random_account_ids" - external test_random_account_id_order : (bytes list -> bytes list) -> unit = "rust_test_random_account_id_order" - external test_random_account_updates : (bytes -> bytes) -> unit = "rust_test_random_account_updates" - external get_random_account : (bytes -> unit) -> bytes = "rust_get_random_account" - external rust_print_backtrace : int -> unit = "rust_print_backtrace" -end diff --git a/ledger/src/account/account.rs b/ledger/src/account/account.rs index 698fd5d1f5..68227efffb 100644 --- a/ledger/src/account/account.rs +++ b/ledger/src/account/account.rs @@ -1,17 +1,3 @@ -use std::{io::Cursor, str::FromStr, sync::Arc}; - -use ark_ff::{BigInteger256, One, UniformRand, Zero}; -use mina_core::constants::PROTOCOL_VERSION; -use mina_curves::pasta::Fp; -use mina_p2p_messages::{ - binprot::{BinProtRead, BinProtWrite}, - v2, -}; -use mina_signer::CompressedPubKey; -use once_cell::sync::{Lazy, OnceCell}; -use rand::{prelude::ThreadRng, seq::SliceRandom, Rng}; -use serde::{Deserialize, Serialize}; - use crate::{ gen_compressed, proofs::{ @@ -31,6 +17,15 @@ use crate::{ zkapps::snark::FlaggedOption, AppendToInputs as _, MerklePath, MyCow, ToInputs, }; +use ark_ff::{BigInteger256, One, UniformRand, Zero}; +use mina_core::constants::PROTOCOL_VERSION; +use mina_curves::pasta::Fp; +use mina_p2p_messages::{ + binprot::{BinProtRead, BinProtWrite}, + v2, +}; +use mina_signer::CompressedPubKey; +use once_cell::sync::{Lazy, OnceCell}; use poseidon::hash::{ hash_noinputs, hash_with_kimchi, params::{ @@ -39,6 +34,9 @@ use poseidon::hash::{ }, Inputs, }; +use rand::{prelude::ThreadRng, seq::SliceRandom, Rng}; +use serde::{Deserialize, Serialize}; +use std::{io::Cursor, str::FromStr, sync::Arc}; use super::common::*; @@ -424,12 +422,6 @@ pub struct VerificationKey { pub wrap_vk: Option<()>, } -// impl From for MinaBaseVerificationKeyWireStableV1Base64 { -// fn from(value: VerificationKey) -> Self { -// MinaBaseVerificationKeyWireStableV1Base64((&value).into()) -// } -// } - impl Check for VerificationKey { fn check(&self, w: &mut Witness) { let Self { diff --git a/ledger/src/account/common.rs b/ledger/src/account/common.rs index 84b9cb3591..521de1b44b 100644 --- a/ledger/src/account/common.rs +++ b/ledger/src/account/common.rs @@ -1,10 +1,3 @@ -use std::str::FromStr; - -use ark_ff::{UniformRand, Zero}; -use mina_curves::pasta::Fp; -use o1_utils::{field_helpers::FieldHelpersError, FieldHelpers}; -use serde::{Deserialize, Serialize}; - use crate::{ proofs::{ field::{Boolean, FieldWitness, ToBoolean}, @@ -17,6 +10,11 @@ use crate::{ scan_state::currency::{Amount, Balance, Magnitude, Slot, SlotSpan}, ControlTag, ToInputs, }; +use ark_ff::{UniformRand, Zero}; +use mina_curves::pasta::Fp; +use o1_utils::{field_helpers::FieldHelpersError, FieldHelpers}; +use serde::{Deserialize, Serialize}; +use std::str::FromStr; #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct VotingFor(pub Fp); diff --git a/ledger/src/account/conv.rs b/ledger/src/account/conv.rs index d9e82d851c..a3909f575a 100644 --- a/ledger/src/account/conv.rs +++ b/ledger/src/account/conv.rs @@ -1,5 +1,15 @@ #![allow(clippy::type_complexity)] +use super::{Account, AccountId, AuthRequired, TokenId, VerificationKeyWire}; +use crate::{ + proofs::{ + field::FieldWitness, + transaction::{make_group, InnerCurve, PlonkVerificationKeyEvals}, + }, + scan_state::currency::{Amount, Balance, Nonce, Slot, SlotSpan, TxnVersion}, + AccountIndex, Permissions, ProofVerified, ReceiptChainHash, SetVerificationKey, Timing, + TokenSymbol, VerificationKey, VotingFor, ZkAppAccount, +}; use ark_ec::short_weierstrass::Affine; use ark_ff::{Field, PrimeField}; use mina_curves::pasta::Fp; @@ -17,18 +27,6 @@ use mina_p2p_messages::{ }, }; -use crate::{ - proofs::{ - field::FieldWitness, - transaction::{make_group, InnerCurve, PlonkVerificationKeyEvals}, - }, - scan_state::currency::{Amount, Balance, Nonce, Slot, SlotSpan, TxnVersion}, - AccountIndex, Permissions, ProofVerified, ReceiptChainHash, SetVerificationKey, Timing, - TokenSymbol, VerificationKey, VotingFor, ZkAppAccount, -}; - -use super::{Account, AccountId, AuthRequired, TokenId, VerificationKeyWire}; - impl binprot::BinProtRead for TokenId { fn binprot_read(r: &mut R) -> Result where diff --git a/ledger/src/account/legacy.rs b/ledger/src/account/legacy.rs index 132db48d0c..e3b04e787f 100644 --- a/ledger/src/account/legacy.rs +++ b/ledger/src/account/legacy.rs @@ -1,13 +1,10 @@ -use std::borrow::Cow; - +use super::common::*; +use crate::scan_state::currency::{Balance, Magnitude, Nonce}; use ark_ff::Zero; use mina_hasher::{create_legacy, Fp, Hashable, Hasher, ROInput}; use mina_signer::CompressedPubKey; use o1_utils::FieldHelpers; - -use crate::scan_state::currency::{Balance, Magnitude, Nonce}; - -use super::common::*; +use std::borrow::Cow; #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct TokenIdLegacy(pub u64); diff --git a/ledger/src/address/raw.rs b/ledger/src/address/raw.rs index 7bca2c29a1..f12e751818 100644 --- a/ledger/src/address/raw.rs +++ b/ledger/src/address/raw.rs @@ -261,15 +261,6 @@ impl Address { pub fn nused_bytes(&self) -> usize { self.length.saturating_sub(1) / 8 + 1 - - // let length_div = self.length / 8; - // let length_mod = self.length % 8; - - // if length_mod == 0 { - // length_div - // } else { - // length_div + 1 - // } } pub fn used_bytes(&self) -> &[u8] { diff --git a/ledger/src/lib.rs b/ledger/src/lib.rs index d66aa84276..bd0eeed0d9 100644 --- a/ledger/src/lib.rs +++ b/ledger/src/lib.rs @@ -129,9 +129,6 @@ mod wasm { #[macro_use] mod cache; -#[cfg(all(not(target_family = "wasm"), feature = "ocaml-interop"))] -mod ffi; - #[cfg(any(test, feature = "fuzzing"))] pub mod generators; diff --git a/ledger/src/proofs/mod.rs b/ledger/src/proofs/mod.rs index 02e48edaf0..e9d67f2497 100644 --- a/ledger/src/proofs/mod.rs +++ b/ledger/src/proofs/mod.rs @@ -52,12 +52,14 @@ pub fn generate_tx_proof( let mut w: Witness = Witness::new::(); transaction::generate_tx_proof(params, &mut w) } + pub fn generate_merge_proof(params: merge::MergeParams) -> anyhow::Result { use mina_curves::pasta::Fp; use witness::Witness; let mut w: Witness = Witness::new::(); merge::generate_merge_proof(params, &mut w) } + pub fn generate_block_proof(params: block::BlockParams) -> anyhow::Result { use mina_curves::pasta::Fp; use witness::Witness; diff --git a/ledger/src/proofs/prover.rs b/ledger/src/proofs/prover.rs index c30314c546..91a8fcb547 100644 --- a/ledger/src/proofs/prover.rs +++ b/ledger/src/proofs/prover.rs @@ -7,7 +7,6 @@ use kimchi::{ use mina_curves::pasta::{Fp, Pallas}; use once_cell::sync::Lazy; use poly_commitment::{commitment::CommitmentCurve, ipa::OpeningProof}; - use super::{util::extract_bulletproof, ProverProof}; use mina_curves::pasta::Fq; use mina_p2p_messages::{bigint::BigInt, v2::PicklesProofProofsVerified2ReprStableV2}; @@ -75,13 +74,6 @@ pub fn make_padded_proof_from_p2p( let evals = &proof.evaluations; - // let to_fields = |x: &Vec| x.iter().map(BigInt::to_field).collect(); - // let to_pt_eval = |(first, second): &(Vec, Vec)| PointEvaluations { - // zeta: to_fields(first), - // zeta_omega: to_fields(second), - // }; - - // let to_fields = |x: &Vec| x.iter().map(BigInt::to_field).collect(); let to_pt_eval = |(first, second): &(BigInt, BigInt)| -> anyhow::Result<_> { Ok(PointEvaluations { zeta: vec![first.to_field::()?], diff --git a/ledger/src/proofs/step.rs b/ledger/src/proofs/step.rs index b72eb740e6..d2bf9cbcac 100644 --- a/ledger/src/proofs/step.rs +++ b/ledger/src/proofs/step.rs @@ -1,5 +1,4 @@ use std::rc::Rc; - use crate::{ proofs::{ prover::make_padded_proof_from_p2p, @@ -26,7 +25,6 @@ use kimchi::proof::{PointEvaluations, ProverCommitments, RecursionChallenge}; use mina_curves::pasta::{Fp, Fq, Pallas}; use mina_p2p_messages::{bigint::InvalidBigInt, v2}; use poly_commitment::{commitment::b_poly_coefficients, ipa::OpeningProof}; - use crate::proofs::{ public_input::{ plonk_checks::{derive_plonk, InCircuit}, @@ -41,7 +39,6 @@ use crate::proofs::{ }, BACKEND_TICK_ROUNDS_N, BACKEND_TOCK_ROUNDS_N, }; - use super::{ constants::ProofConstants, field::{Boolean, CircuitVar, FieldWitness, GroupAffine}, diff --git a/ledger/src/proofs/util.rs b/ledger/src/proofs/util.rs index ee114f2301..2cb25e0b82 100644 --- a/ledger/src/proofs/util.rs +++ b/ledger/src/proofs/util.rs @@ -1,5 +1,4 @@ use std::fmt::Debug; - use ark_ff::{BigInteger256, Field}; use kimchi::proof::{PointEvaluations, ProofEvaluations}; use mina_p2p_messages::{ @@ -7,9 +6,7 @@ use mina_p2p_messages::{ pseq::PaddedSeq, v2::PicklesReducedMessagesForNextProofOverSameFieldWrapChallengesVectorStableV2A, }; - use crate::proofs::field::{field, Boolean, FieldWitness}; - use super::{ public_input::scalar_challenge::ScalarChallenge, step::{Opt, OptFlag}, diff --git a/mina-p2p-messages/src/array.rs b/mina-p2p-messages/src/array.rs index 1a70c818f9..78d3e137a8 100644 --- a/mina-p2p-messages/src/array.rs +++ b/mina-p2p-messages/src/array.rs @@ -1,9 +1,8 @@ -use std::ops::Deref; - use binprot::{BinProtRead, BinProtWrite, Nat0}; use malloc_size_of_derive::MallocSizeOf; use rsexp::OfSexp; use serde::{Deserialize, Serialize}; +use std::ops::Deref; /// Mina array bounded to specific length. Note that the length is only checked /// when performing binprot operations. diff --git a/mina-p2p-messages/src/b58.rs b/mina-p2p-messages/src/b58.rs index 3479e68803..920cdf3a48 100644 --- a/mina-p2p-messages/src/b58.rs +++ b/mina-p2p-messages/src/b58.rs @@ -1,12 +1,11 @@ //! Base58check encoding/decoding. -use std::{fmt, marker::PhantomData, str::FromStr}; - use binprot::{BinProtRead, BinProtWrite}; use binprot_derive::{BinProtRead, BinProtWrite}; use derive_more::From; use malloc_size_of_derive::MallocSizeOf; use serde::{Deserialize, Serialize}; +use std::{fmt, marker::PhantomData, str::FromStr}; /// Before encoding, data is prepended with the version byte. pub fn encode(b: &[u8], v: u8) -> String { @@ -373,7 +372,6 @@ mod tests { } #[test] - #[ignore = "fix or remove"] fn binable_base58check() { #[derive(Clone, BinProtRead, BinProtWrite)] struct Binable(BigInt); diff --git a/mina-p2p-messages/src/bigint.rs b/mina-p2p-messages/src/bigint.rs index 7c21b54203..b9ddfb61af 100644 --- a/mina-p2p-messages/src/bigint.rs +++ b/mina-p2p-messages/src/bigint.rs @@ -1,4 +1,4 @@ -use ark_ff::BigInteger256; +use ark_ff::{BigInteger256, PrimeField}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use malloc_size_of::MallocSizeOf; use rsexp::{OfSexp, SexpOf}; @@ -100,34 +100,31 @@ impl AsRef for BigInt { impl From for BigInt { fn from(field: mina_curves::pasta::Fp) -> Self { - use ark_ff::PrimeField; Self(field.into_bigint()) } } impl From for BigInt { fn from(field: mina_curves::pasta::Fq) -> Self { - use ark_ff::PrimeField; Self(field.into_bigint()) } } impl From<&mina_curves::pasta::Fp> for BigInt { fn from(field: &mina_curves::pasta::Fp) -> Self { - use ark_ff::PrimeField; Self(field.into_bigint()) } } impl From<&mina_curves::pasta::Fq> for BigInt { fn from(field: &mina_curves::pasta::Fq) -> Self { - use ark_ff::PrimeField; Self(field.into_bigint()) } } impl TryFrom for mina_curves::pasta::Fp { type Error = InvalidBigInt; + fn try_from(bigint: BigInt) -> Result { bigint.to_field() } @@ -135,6 +132,7 @@ impl TryFrom for mina_curves::pasta::Fp { impl TryFrom for mina_curves::pasta::Fq { type Error = InvalidBigInt; + fn try_from(bigint: BigInt) -> Result { bigint.to_field() } @@ -142,6 +140,7 @@ impl TryFrom for mina_curves::pasta::Fq { impl TryFrom<&BigInt> for mina_curves::pasta::Fp { type Error = InvalidBigInt; + fn try_from(bigint: &BigInt) -> Result { bigint.to_field() } @@ -149,6 +148,7 @@ impl TryFrom<&BigInt> for mina_curves::pasta::Fp { impl TryFrom<&BigInt> for mina_curves::pasta::Fq { type Error = InvalidBigInt; + fn try_from(bigint: &BigInt) -> Result { bigint.to_field() } @@ -333,9 +333,8 @@ impl mina_hasher::Hashable for BigInt { #[cfg(test)] mod tests { - use binprot::{BinProtRead, BinProtWrite}; - use super::BigInt; + use binprot::{BinProtRead, BinProtWrite}; fn to_binprot(v: &BigInt) -> Vec { let mut w = Vec::new(); @@ -347,10 +346,9 @@ mod tests { BigInt::binprot_read(&mut b).unwrap() } - fn from_byte(b: u8) -> BigInt { - BigInt::from_bytes([b; 32]) - } - + /// Build a BigInt from a sequence of bytes. + /// If the input contains less than 32 bytes, the sequence is repeated until reaching 32 bytes + /// and filling the BigInt buffer. fn from_bytes<'a, I>(it: I) -> BigInt where I: IntoIterator, @@ -365,9 +363,9 @@ mod tests { #[test] fn serialize_bigint() { let bigints = [ - from_byte(0), - from_byte(1), - from_byte(0xff), + BigInt::from_bytes([0; 32]), + BigInt::from_bytes([1; 32]), + BigInt::from_bytes([0xff; 32]), from_bytes(&[0, 1, 2, 3, 4]), ]; @@ -380,9 +378,9 @@ mod tests { #[test] fn deserialize_bigint() { let bigints = [ - from_byte(0), - from_byte(1), - from_byte(0xff), + BigInt::from_bytes([0; 32]), + BigInt::from_bytes([1; 32]), + BigInt::from_bytes([0xff; 32]), from_bytes(&[0, 1, 2, 3, 4]), ]; @@ -395,9 +393,9 @@ mod tests { #[test] fn to_json() { let bigints = [ - from_byte(0), - from_byte(1), - from_byte(0xff), + BigInt::from_bytes([0; 32]), + BigInt::from_bytes([1; 32]), + BigInt::from_bytes([0xff; 32]), from_bytes(&[0, 1, 2, 3, 4]), ]; @@ -413,9 +411,9 @@ mod tests { #[test] fn from_json() { let bigints = [ - from_byte(0), - from_byte(1), - from_byte(0xff), + BigInt::from_bytes([0; 32]), + BigInt::from_bytes([1; 32]), + BigInt::from_bytes([0xff; 32]), from_bytes(&[0, 1, 2, 3, 4]), ]; diff --git a/mina-p2p-messages/src/core.rs b/mina-p2p-messages/src/core.rs index 811565fe7a..87fecf1381 100644 --- a/mina-p2p-messages/src/core.rs +++ b/mina-p2p-messages/src/core.rs @@ -1,13 +1,12 @@ //! Types from Janestreet's Core library. -use std::net::IpAddr; - use crate::{ string::{ByteString, CharString}, versioned::Versioned, }; use binprot_derive::{BinProtRead, BinProtWrite}; use serde::{Deserialize, Serialize}; +use std::net::IpAddr; /// This type corresponds to `Bounded_types.Wrapped_error` OCaml type, but the /// structure is different. It only refrects the data that is passed over the diff --git a/mina-p2p-messages/src/gossip.rs b/mina-p2p-messages/src/gossip.rs index 10a7c23334..e3be443871 100644 --- a/mina-p2p-messages/src/gossip.rs +++ b/mina-p2p-messages/src/gossip.rs @@ -1,10 +1,8 @@ -use std::sync::Arc; - +use crate::{number::Int32, v2}; use binprot_derive::{BinProtRead, BinProtWrite}; use derive_more::{From, TryInto}; use serde::{Deserialize, Serialize}; - -use crate::{number::Int32, v2}; +use std::sync::Arc; #[derive( Clone, Debug, Serialize, Deserialize, BinProtRead, BinProtWrite, PartialEq, From, TryInto, diff --git a/mina-p2p-messages/src/hash.rs b/mina-p2p-messages/src/hash.rs index d9dd16a0df..adc992c056 100644 --- a/mina-p2p-messages/src/hash.rs +++ b/mina-p2p-messages/src/hash.rs @@ -1,6 +1,5 @@ -use mina_curves::pasta::Fp; - use crate::bigint::InvalidBigInt; +use mina_curves::pasta::Fp; pub trait MinaHash { fn try_hash(&self) -> Result; diff --git a/mina-p2p-messages/src/hash_input.rs b/mina-p2p-messages/src/hash_input.rs index 0fd27c8591..c3e036e483 100644 --- a/mina-p2p-messages/src/hash_input.rs +++ b/mina-p2p-messages/src/hash_input.rs @@ -1,13 +1,11 @@ -use std::ops::Deref; - -use poseidon::hash::Inputs; - use crate::{ bigint::{BigInt, InvalidBigInt}, list::List, number::{Int32, Int64, UInt32, UInt64}, string::{ByteString, ZkAppUri}, }; +use poseidon::hash::Inputs; +use std::ops::Deref; /// Difference with `ToInputs` in `ledger` is that it can fail here, due /// to invalid bigints @@ -87,9 +85,8 @@ where #[cfg(test)] mod tests { - use o1_utils::FieldHelpers; - use super::Inputs; + use o1_utils::FieldHelpers; macro_rules! test_to_field { ($test:ident : $fun:ident ( $( $value:expr ),* $(,)? ) = $hex:expr ) => { diff --git a/mina-p2p-messages/src/v2/dummy/mod.rs b/mina-p2p-messages/src/v2/dummy/mod.rs index 9b28c0f3fb..e9382fa461 100644 --- a/mina-p2p-messages/src/v2/dummy/mod.rs +++ b/mina-p2p-messages/src/v2/dummy/mod.rs @@ -1,8 +1,6 @@ -use std::sync::Arc; - -use binprot::BinProtRead; - use super::{MinaBaseProofStableV2, TransactionSnarkProofStableV2}; +use binprot::BinProtRead; +use std::sync::Arc; /// Value of `Proof.transaction_dummy` when we run `dune runtest src/lib/staged_ledger -f` /// The file was generated this way: diff --git a/mina-p2p-messages/src/v2/generated.rs b/mina-p2p-messages/src/v2/generated.rs index 8ce70d3443..326a772db3 100644 --- a/mina-p2p-messages/src/v2/generated.rs +++ b/mina-p2p-messages/src/v2/generated.rs @@ -1,3 +1,5 @@ +use super::manual::*; +use crate::{array::ArrayN16, list::List, pseq::PaddedSeq}; use binprot_derive::{BinProtRead, BinProtWrite}; use derive_more::Deref; use malloc_size_of::MallocSizeOf; @@ -7,10 +9,6 @@ use rsexp_derive::{OfSexp, SexpOf}; use serde::{Deserialize, Serialize}; use std::sync::Arc; -use crate::{array::ArrayN16, list::List, pseq::PaddedSeq}; - -use super::manual::*; - /// **OCaml name**: `Mina_block__Block.Stable.V2` /// /// Gid: `1102` diff --git a/mina-p2p-messages/src/v2/manual.rs b/mina-p2p-messages/src/v2/manual.rs index 527f9fc9bd..e2c62480aa 100644 --- a/mina-p2p-messages/src/v2/manual.rs +++ b/mina-p2p-messages/src/v2/manual.rs @@ -1,14 +1,4 @@ pub mod conv; - -use ark_ff::BigInteger256; -use binprot::{BinProtRead, BinProtWrite}; -use binprot_derive::{BinProtRead, BinProtWrite}; -use derive_more::Deref; -use malloc_size_of_derive::MallocSizeOf; -use poseidon::hash::params::NO_INPUT_COINBASE_STACK; -use serde::{de::Visitor, ser::SerializeTuple, Deserialize, Serialize, Serializer}; -use time::OffsetDateTime; - use crate::{ b58::{self, Base58CheckOfBinProt, Base58CheckOfBytes}, b58version::USER_COMMAND_MEMO, @@ -18,6 +8,14 @@ use crate::{ string::ByteString, versioned::Versioned, }; +use ark_ff::BigInteger256; +use binprot::{BinProtRead, BinProtWrite}; +use binprot_derive::{BinProtRead, BinProtWrite}; +use derive_more::Deref; +use malloc_size_of_derive::MallocSizeOf; +use poseidon::hash::params::NO_INPUT_COINBASE_STACK; +use serde::{de::Visitor, ser::SerializeTuple, Deserialize, Serialize, Serializer}; +use time::OffsetDateTime; use super::*; @@ -866,12 +864,9 @@ impl PrecomputedBlock { #[cfg(test)] mod tests { - use std::fmt::Debug; - use binprot::{BinProtRead, BinProtWrite}; use serde::{de::DeserializeOwned, Serialize}; - - use super::*; + use std::fmt::Debug; fn base58check_test( b58: &str,