Skip to content

Commit

Permalink
Merge pull request 0xPolygonZero#870 from mir-protocol/prep_for_publish
Browse files Browse the repository at this point in the history
Prep for publishing to crates.io
  • Loading branch information
dlubarov authored Jan 30, 2023
2 parents 8151138 + 137bc78 commit 9990632
Show file tree
Hide file tree
Showing 41 changed files with 98 additions and 73 deletions.
10 changes: 6 additions & 4 deletions ecdsa/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
[package]
name = "plonky2_ecdsa"
description = "ECDSA gadget for Plonky2"
version = "0.1.0"
license = "MIT OR Apache-2.0"
edition = "2021"

[features]
parallel = ["maybe_rayon/parallel", "plonky2/parallel"]
parallel = ["plonky2_maybe_rayon/parallel", "plonky2/parallel"]

[dependencies]
anyhow = { version = "1.0.40", default-features = false }
itertools = { version = "0.10.0", default-features = false }
maybe_rayon = { path = "../maybe_rayon", default-features = false }
plonky2_maybe_rayon = { version = "0.1.0", default-features = false }
num = { version = "0.4.0", default-features = false }
plonky2 = { path = "../plonky2", default-features = false }
plonky2_u32 = { path = "../u32", default-features = false }
plonky2 = { version = "0.1.1", default-features = false }
plonky2_u32 = { version = "0.1.0", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive"] }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion ecdsa/src/curve/curve_msm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use alloc::vec::Vec;

use itertools::Itertools;
use maybe_rayon::*;
use plonky2::field::types::{Field, PrimeField};
use plonky2_maybe_rayon::*;

use crate::curve::curve_summation::affine_multisummation_best;
use crate::curve::curve_types::{AffinePoint, Curve, ProjectivePoint};
Expand Down
13 changes: 9 additions & 4 deletions evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
name = "plonky2_evm"
description = "Implementation of STARKs for the Ethereum Virtual Machine"
version = "0.1.0"
authors = ["Daniel Lubarov <daniel@lubarov.com>", "William Borgeaud <williamborgeaud@gmail.com>"]
readme = "README.md"
repository = "https://github.com/mir-protocol/plonky2"
keywords = ["EVM", "STARK", "Ethereum"]
categories = ["cryptography"]
edition = "2021"

[dependencies]
Expand All @@ -15,13 +20,13 @@ hex-literal = "0.3.4"
itertools = "0.10.3"
keccak-hash = "0.10.0"
log = "0.4.14"
maybe_rayon = { path = "../maybe_rayon" }
plonky2_maybe_rayon = "0.1.0"
num = "0.4.0"
once_cell = "1.13.0"
pest = "2.1.3"
pest_derive = "2.1.0"
plonky2 = { path = "../plonky2", default-features = false, features = ["timing"] }
plonky2_util = { path = "../util" }
plonky2 = { version = "0.1.1", default-features = false, features = ["timing"] }
plonky2_util = { version = "0.1.0" }
rand = "0.8.5"
rand_chacha = "0.3.1"
rlp = "0.5.1"
Expand All @@ -42,7 +47,7 @@ sha2 = "0.10.6"
[features]
default = ["parallel"]
asmtools = ["hex"]
parallel = ["plonky2/parallel", "maybe_rayon/parallel"]
parallel = ["plonky2/parallel", "plonky2_maybe_rayon/parallel"]

[[bin]]
name = "assemble"
Expand Down
4 changes: 2 additions & 2 deletions evm/src/cpu/kernel/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ impl Kernel {
prover_inputs: HashMap<usize, ProverInputFn>,
) -> Self {
let code_hash_bytes = keccak(&code).0;
let code_hash = std::array::from_fn(|i| {
u32::from_le_bytes(std::array::from_fn(|j| code_hash_bytes[i * 4 + j]))
let code_hash = core::array::from_fn(|i| {
u32::from_le_bytes(core::array::from_fn(|j| code_hash_bytes[i * 4 + j]))
});
let ordered_labels = global_labels
.keys()
Expand Down
8 changes: 4 additions & 4 deletions evm/src/cpu/kernel/keccak_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use crate::keccak_sponge::columns::{KECCAK_WIDTH_BYTES, KECCAK_WIDTH_U32S};

/// Like tiny-keccak's `keccakf`, but deals with `u32` limbs instead of `u64` limbs.
pub(crate) fn keccakf_u32s(state_u32s: &mut [u32; KECCAK_WIDTH_U32S]) {
let mut state_u64s: [u64; 25] = std::array::from_fn(|i| {
let mut state_u64s: [u64; 25] = core::array::from_fn(|i| {
let lo = state_u32s[i * 2] as u64;
let hi = state_u32s[i * 2 + 1] as u64;
lo | (hi << 32)
});
keccakf(&mut state_u64s);
*state_u32s = std::array::from_fn(|i| {
*state_u32s = core::array::from_fn(|i| {
let u64_limb = state_u64s[i / 2];
let is_hi = i % 2;
(u64_limb >> (is_hi * 32)) as u32
Expand All @@ -20,9 +20,9 @@ pub(crate) fn keccakf_u32s(state_u32s: &mut [u32; KECCAK_WIDTH_U32S]) {
/// Like tiny-keccak's `keccakf`, but deals with bytes instead of `u64` limbs.
pub(crate) fn keccakf_u8s(state_u8s: &mut [u8; KECCAK_WIDTH_BYTES]) {
let mut state_u64s: [u64; 25] =
std::array::from_fn(|i| u64::from_le_bytes(state_u8s[i * 8..][..8].try_into().unwrap()));
core::array::from_fn(|i| u64::from_le_bytes(state_u8s[i * 8..][..8].try_into().unwrap()));
keccakf(&mut state_u64s);
*state_u8s = std::array::from_fn(|i| {
*state_u8s = core::array::from_fn(|i| {
let u64_limb = state_u64s[i / 8];
u64_limb.to_le_bytes()[i % 8]
});
Expand Down
4 changes: 2 additions & 2 deletions evm/src/cpu/kernel/tests/mpt/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn mpt_hash_empty() -> Result<()> {

#[test]
fn mpt_hash_empty_branch() -> Result<()> {
let children = std::array::from_fn(|_| PartialTrie::Empty.into());
let children = core::array::from_fn(|_| PartialTrie::Empty.into());
let state_trie = PartialTrie::Branch {
children,
value: vec![],
Expand Down Expand Up @@ -85,7 +85,7 @@ fn mpt_hash_branch_to_leaf() -> Result<()> {
value: test_account_2_rlp(),
}
.into();
let mut children = std::array::from_fn(|_| PartialTrie::Empty.into());
let mut children = core::array::from_fn(|_| PartialTrie::Empty.into());
children[3] = leaf;
let state_trie = PartialTrie::Branch {
children,
Expand Down
8 changes: 4 additions & 4 deletions evm/src/cpu/kernel/tests/mpt/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn mpt_insert_leaf_leaf_key_extends_insert_key() -> Result<()> {

#[test]
fn mpt_insert_branch_replacing_empty_child() -> Result<()> {
let children = std::array::from_fn(|_| PartialTrie::Empty.into());
let children = core::array::from_fn(|_| PartialTrie::Empty.into());
let state_trie = PartialTrie::Branch {
children,
value: vec![],
Expand All @@ -81,7 +81,7 @@ fn mpt_insert_branch_replacing_empty_child() -> Result<()> {
#[ignore]
fn mpt_insert_extension_nonoverlapping_keys() -> Result<()> {
// Existing keys are 0xABC, 0xABCDEF; inserted key is 0x12345.
let mut children = std::array::from_fn(|_| PartialTrie::Empty.into());
let mut children = core::array::from_fn(|_| PartialTrie::Empty.into());
children[0xD] = PartialTrie::Leaf {
nibbles: 0xEF_u64.into(),
value: test_account_1_rlp(),
Expand All @@ -104,7 +104,7 @@ fn mpt_insert_extension_nonoverlapping_keys() -> Result<()> {
#[ignore]
fn mpt_insert_extension_insert_key_extends_node_key() -> Result<()> {
// Existing keys are 0xA, 0xABCD; inserted key is 0xABCDEF.
let mut children = std::array::from_fn(|_| PartialTrie::Empty.into());
let mut children = core::array::from_fn(|_| PartialTrie::Empty.into());
children[0xB] = PartialTrie::Leaf {
nibbles: 0xCD_u64.into(),
value: test_account_1_rlp(),
Expand All @@ -129,7 +129,7 @@ fn mpt_insert_branch_to_leaf_same_key() -> Result<()> {
}
.into();

let mut children = std::array::from_fn(|_| PartialTrie::Empty.into());
let mut children = core::array::from_fn(|_| PartialTrie::Empty.into());
children[0] = leaf;
let state_trie = PartialTrie::Branch {
children,
Expand Down
2 changes: 1 addition & 1 deletion evm/src/cpu/kernel/tests/mpt/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn load_all_mpts_hash() -> Result<()> {

#[test]
fn load_all_mpts_empty_branch() -> Result<()> {
let children = std::array::from_fn(|_| PartialTrie::Empty.into());
let children = core::array::from_fn(|_| PartialTrie::Empty.into());
let state_trie = PartialTrie::Branch {
children,
value: vec![],
Expand Down
8 changes: 4 additions & 4 deletions evm/src/fixed_recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ where
stark_config: &StarkConfig,
) -> RootCircuitData<F, C, D> {
let inner_common_data: [_; NUM_TABLES] =
std::array::from_fn(|i| &by_table[i].final_circuits()[0].common);
core::array::from_fn(|i| &by_table[i].final_circuits()[0].common);

let mut builder = CircuitBuilder::new(CircuitConfig::standard_recursion_config());
let recursive_proofs =
std::array::from_fn(|i| builder.add_virtual_proof_with_pis::<C>(inner_common_data[i]));
let pis: [_; NUM_TABLES] = std::array::from_fn(|i| {
core::array::from_fn(|i| builder.add_virtual_proof_with_pis::<C>(inner_common_data[i]));
let pis: [_; NUM_TABLES] = core::array::from_fn(|i| {
PublicInputs::from_vec(&recursive_proofs[i].public_inputs, stark_config)
});
let index_verifier_data = std::array::from_fn(|_i| builder.add_virtual_target());
let index_verifier_data = core::array::from_fn(|_i| builder.add_virtual_target());

let mut challenger = RecursiveChallenger::<F, C::Hasher, D>::new(&mut builder);
for pi in &pis {
Expand Down
2 changes: 1 addition & 1 deletion evm/src/get_challenges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize> A
let num_permutation_batch_sizes = all_stark.permutation_batch_sizes();

AllProofChallenges {
stark_challenges: std::array::from_fn(|i| {
stark_challenges: core::array::from_fn(|i| {
challenger.compact();
self.stark_proofs[i].proof.get_challenges(
&mut challenger,
Expand Down
2 changes: 1 addition & 1 deletion evm/src/memory/memory_stark.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::marker::PhantomData;

use itertools::Itertools;
use maybe_rayon::*;
use plonky2::field::extension::{Extendable, FieldExtension};
use plonky2::field::packed::PackedField;
use plonky2::field::polynomial::PolynomialValues;
Expand All @@ -10,6 +9,7 @@ use plonky2::hash::hash_types::RichField;
use plonky2::timed;
use plonky2::util::timing::TimingTree;
use plonky2::util::transpose;
use plonky2_maybe_rayon::*;

use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
use crate::cross_table_lookup::Column;
Expand Down
2 changes: 1 addition & 1 deletion evm/src/permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::fmt::Debug;

use itertools::Itertools;
use maybe_rayon::*;
use plonky2::field::batch_util::batch_multiply_inplace;
use plonky2::field::extension::{Extendable, FieldExtension};
use plonky2::field::packed::PackedField;
Expand All @@ -17,6 +16,7 @@ use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::config::{AlgebraicHasher, GenericConfig, Hasher};
use plonky2::plonk::plonk_common::{reduce_with_powers, reduce_with_powers_ext_circuit};
use plonky2::util::reducing::{ReducingFactor, ReducingFactorTarget};
use plonky2_maybe_rayon::*;

use crate::config::StarkConfig;
use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
Expand Down
4 changes: 2 additions & 2 deletions evm/src/proof.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use ethereum_types::{Address, H256, U256};
use itertools::Itertools;
use maybe_rayon::*;
use plonky2::field::extension::{Extendable, FieldExtension};
use plonky2::fri::oracle::PolynomialBatch;
use plonky2::fri::proof::{FriChallenges, FriChallengesTarget, FriProof, FriProofTarget};
Expand All @@ -13,6 +12,7 @@ use plonky2::hash::merkle_tree::MerkleCap;
use plonky2::iop::ext_target::ExtensionTarget;
use plonky2::iop::target::Target;
use plonky2::plonk::config::GenericConfig;
use plonky2_maybe_rayon::*;
use serde::{Deserialize, Serialize};

use crate::all_stark::NUM_TABLES;
Expand All @@ -29,7 +29,7 @@ pub struct AllProof<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, co

impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize> AllProof<F, C, D> {
pub fn degree_bits(&self, config: &StarkConfig) -> [usize; NUM_TABLES] {
std::array::from_fn(|i| self.stark_proofs[i].proof.recover_degree_bits(config))
core::array::from_fn(|i| self.stark_proofs[i].proof.recover_degree_bits(config))
}
}

Expand Down
2 changes: 1 addition & 1 deletion evm/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::any::type_name;

use anyhow::{ensure, Result};
use itertools::Itertools;
use maybe_rayon::*;
use once_cell::sync::Lazy;
use plonky2::field::extension::Extendable;
use plonky2::field::packable::Packable;
Expand All @@ -17,6 +16,7 @@ use plonky2::plonk::config::{GenericConfig, Hasher};
use plonky2::timed;
use plonky2::util::timing::TimingTree;
use plonky2::util::transpose;
use plonky2_maybe_rayon::*;
use plonky2_util::{log2_ceil, log2_strict};

use crate::all_stark::{AllStark, Table, NUM_TABLES};
Expand Down
4 changes: 2 additions & 2 deletions evm/src/recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
where
[(); C::Hasher::HASH_SIZE]:,
{
let pis: [_; NUM_TABLES] = std::array::from_fn(|i| {
let pis: [_; NUM_TABLES] = core::array::from_fn(|i| {
PublicInputs::from_vec(&self.recursive_proofs[i].public_inputs, inner_config)
});

Expand Down Expand Up @@ -279,7 +279,7 @@ where
num_permutation_zs,
);

let init_challenger_state_target = std::array::from_fn(|_| builder.add_virtual_public_input());
let init_challenger_state_target = core::array::from_fn(|_| builder.add_virtual_public_input());
let mut challenger =
RecursiveChallenger::<F, C::Hasher, D>::from_state(init_challenger_state_target);
let challenges = proof_target.get_challenges::<F, C>(
Expand Down
2 changes: 1 addition & 1 deletion evm/src/witness/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub(crate) fn stack_pop_with_log_and_fill<const N: usize, F: Field>(
return Err(ProgramError::StackUnderflow);
}

let result = std::array::from_fn(|i| {
let result = core::array::from_fn(|i| {
let address = MemoryAddress::new(
state.registers.context,
Segment::Stack,
Expand Down
4 changes: 2 additions & 2 deletions evm/tests/basic_smart_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn test_basic_smart_contract() -> anyhow::Result<()> {
};

let state_trie_before = {
let mut children = std::array::from_fn(|_| PartialTrie::Empty.into());
let mut children = core::array::from_fn(|_| PartialTrie::Empty.into());
children[sender_nibbles.get_nibble(0) as usize] = PartialTrie::Leaf {
nibbles: sender_nibbles.truncate_n_nibbles_front(1),
value: rlp::encode(&sender_account_before).to_vec(),
Expand Down Expand Up @@ -110,7 +110,7 @@ fn test_basic_smart_contract() -> anyhow::Result<()> {
..to_account_before
};

let mut children = std::array::from_fn(|_| PartialTrie::Empty.into());
let mut children = core::array::from_fn(|_| PartialTrie::Empty.into());
children[sender_nibbles.get_nibble(0) as usize] = PartialTrie::Leaf {
nibbles: sender_nibbles.truncate_n_nibbles_front(1),
value: rlp::encode(&sender_account_after).to_vec(),
Expand Down
2 changes: 1 addition & 1 deletion evm/tests/simple_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn test_simple_transfer() -> anyhow::Result<()> {
..AccountRlp::default()
};

let mut children = std::array::from_fn(|_| PartialTrie::Empty.into());
let mut children = core::array::from_fn(|_| PartialTrie::Empty.into());
children[sender_nibbles.get_nibble(0) as usize] = PartialTrie::Leaf {
nibbles: sender_nibbles.truncate_n_nibbles_front(1),
value: rlp::encode(&sender_account_after).to_vec(),
Expand Down
4 changes: 3 additions & 1 deletion field/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
name = "plonky2_field"
description = "Finite field arithmetic"
version = "0.1.0"
license = "MIT OR Apache-2.0"
authors = ["Daniel Lubarov <daniel@lubarov.com>", "William Borgeaud <williamborgeaud@gmail.com>", "Jacqueline Nabaglo <j@nab.gl>", "Hamish Ivey-Law <hamish@ivey-law.name>"]
edition = "2021"

[dependencies]
anyhow = { version = "1.0.40", default-features = false }
itertools = { version = "0.10.0", default-features = false, features = ["use_alloc"] }
num = { version = "0.4", default-features = false, features = ["alloc", "rand"] }
plonky2_util = { path = "../util", default-features = false }
plonky2_util = { version = "0.1.0", default-features = false }
rand = { version = "0.8.5", default-features = false, features = ["getrandom"] }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
static_assertions = { version = "1.1.0", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions insertion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ edition = "2021"

[dependencies]
anyhow = { version = "1.0.40", default-features = false }
plonky2 = { path = "../plonky2", default-features = false }
plonky2 = { version = "0.1.1", default-features = false }

[dev-dependencies]
plonky2 = { path = "../plonky2" }
plonky2 = { version = "0.1.1" }

4 changes: 3 additions & 1 deletion maybe_rayon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[package]
name = "maybe_rayon"
name = "plonky2_maybe_rayon"
description = "Feature-gated wrapper around rayon"
license = "MIT OR Apache-2.0"
version = "0.1.0"
edition = "2021"

Expand Down
Loading

0 comments on commit 9990632

Please sign in to comment.