Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change minimum Rust toolchain to 1.77 #294

Merged
merged 2 commits into from Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .drone.yml
Expand Up @@ -53,10 +53,10 @@ steps:
- cp /usr/local/bin/mina cli/bin/

- name: build
image: rust:1.75-bullseye
image: rust:1.77-bullseye
commands:
- apt-get update && apt-get install -y libssl-dev libjemalloc-dev jq
- rustup update 1.75 && rustup default 1.75
- rustup update 1.77 && rustup default 1.77
- rustup component add rustfmt
# just to be sure it builds without errors
- cargo build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Expand Up @@ -43,8 +43,8 @@ jobs:

- name: Setup Rust
run: |
rustup install 1.75
rustup override set 1.75
rustup install 1.77
rustup override set 1.77
rustup component add clippy rustfmt

# - name: Check
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rustfmt.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.75
toolchain: 1.77
default: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Change minimum Rust toolchain to 1.77.

## [0.2.0] - 2024-02-29

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,7 +1,7 @@
ARG MINA_SNARK_WORKER_TAG=0.0.9

FROM rust:buster AS build
RUN rustup default 1.75 && rustup component add rustfmt
RUN rustup default 1.77 && rustup component add rustfmt
WORKDIR /openmina
COPY . .
RUN cargo build --release --package=cli --bin=openmina
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -72,8 +72,8 @@ Open up the command line and enter the following:
And then:

```sh
# Install rustup and set the default Rust toolchain to 1.75 (newer versions work too)
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.75
# Install rustup and set the default Rust toolchain to 1.77 (newer versions work too)
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.77
# Setup the current shell with rustup
source "$HOME/.cargo/env"
# Clone the openmina repository
Expand Down
30 changes: 19 additions & 11 deletions ledger/src/account/conv.rs
Expand Up @@ -8,7 +8,7 @@ use mina_p2p_messages::{
binprot,
pseq::PaddedSeq,
v2::{
MinaBaseAccountBinableArgStableV2, MinaBaseAccountIdDigestStableV1,
self, MinaBaseAccountBinableArgStableV2, MinaBaseAccountIdDigestStableV1,
MinaBaseAccountIdStableV2, MinaBaseAccountIndexStableV1, MinaBaseAccountTimingStableV2,
MinaBasePermissionsAuthRequiredStableV2, MinaBasePermissionsStableV2,
MinaBaseVerificationKeyWireStableV1, MinaBaseVerificationKeyWireStableV1WrapIndex,
Expand Down Expand Up @@ -115,15 +115,15 @@ where
T: 'a,
U: From<&'a T>,
{
std::array::from_fn(|i| U::from(&value[i]))
value.each_ref().map(|value| U::from(value))
}

pub fn array_into_with<'a, T, U, F, const N: usize>(value: &'a [T; N], fun: F) -> [U; N]
where
T: 'a,
F: Fn(&T) -> U,
{
std::array::from_fn(|i| fun(&value[i]))
value.each_ref().map(|value| fun(value))
}

impl From<&MinaBaseVerificationKeyWireStableV1> for VerificationKey {
Expand Down Expand Up @@ -509,16 +509,24 @@ impl From<&MinaBaseAccountBinableArgStableV2> for Account {
timing: (&acc.timing).into(),
permissions: (&acc.permissions).into(),
zkapp: acc.zkapp.as_ref().map(|zkapp| {
let app_state = std::array::from_fn(|i| zkapp.app_state[i].to_field());
let v2::MinaBaseZkappAccountStableV2 {
app_state,
verification_key,
zkapp_version,
action_state,
last_action_slot,
proved_state,
zkapp_uri,
} = zkapp;

ZkAppAccount {
app_state,
verification_key: zkapp.verification_key.as_ref().map(Into::into),
zkapp_version: zkapp.zkapp_version.as_u32(),
action_state: std::array::from_fn(|i| zkapp.action_state[i].to_field()),
last_action_slot: Slot::from_u32(zkapp.last_action_slot.as_u32()),
proved_state: zkapp.proved_state,
zkapp_uri: (&zkapp.zkapp_uri).try_into().unwrap(),
app_state: app_state.each_ref().map(|s| s.to_field()),
verification_key: verification_key.as_ref().map(Into::into),
zkapp_version: zkapp_version.as_u32(),
action_state: action_state.each_ref().map(|s| s.to_field()),
last_action_slot: Slot::from_u32(last_action_slot.as_u32()),
proved_state: *proved_state,
zkapp_uri: zkapp_uri.try_into().unwrap(),
}
}),
}
Expand Down
4 changes: 1 addition & 3 deletions ledger/src/proofs/accumulator_check.rs
@@ -1,5 +1,3 @@
use std::array;

use mina_curves::pasta::Vesta;
use mina_hasher::Fp;
use mina_p2p_messages::{bigint::BigInt, v2::PicklesProofProofsVerified2ReprStableV2};
Expand All @@ -23,7 +21,7 @@ pub fn accumulator_check(
.iter()
.map(|chal| {
let prechallenge = &chal.prechallenge.inner;
let prechallenge: [u64; 2] = array::from_fn(|k| prechallenge[k].as_u64());
let prechallenge: [u64; 2] = prechallenge.each_ref().map(|c| c.as_u64());

ScalarChallenge::limbs_to_field(&prechallenge)
})
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/proofs/block.rs
Expand Up @@ -702,8 +702,8 @@ mod vrf {
pub const VRF_OUTPUT_NBITS: usize = 253;

fn truncate_vrf_output(output: Fp, w: &mut Witness<Fp>) -> Box<[bool; VRF_OUTPUT_NBITS]> {
let output = w.exists(field_to_bits::<_, 255>(output));
Box::new(std::array::from_fn(|i| output[i]))
let output: [bool; 255] = w.exists(field_to_bits(output));
Box::new(std::array::from_fn(|i| output[i])) // 2 last bits are ignored
}

pub fn check(
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/proofs/caching.rs
Expand Up @@ -328,7 +328,7 @@ impl From<&VerifierIndex<Pallas>> for VerifierIndexCached {
foreign_field_mul_comm: foreign_field_mul_comm.clone(),
xor_comm: xor_comm.clone(),
rot_comm: rot_comm.clone(),
shift: std::array::from_fn(|i| shift[i].into()),
shift: shift.each_ref().map(|s| s.into()),
zkpm: zkpm.get().unwrap().into(),
w: (*w.get().unwrap()).into(),
endo: endo.into(),
Expand Down Expand Up @@ -384,7 +384,7 @@ impl From<&VerifierIndexCached> for VerifierIndex<Pallas> {
endomul_scalar_comm: endomul_scalar_comm.clone(),
foreign_field_add_comm: foreign_field_add_comm.clone(),
xor_comm: xor_comm.clone(),
shift: std::array::from_fn(|i| shift[i].to_field()),
shift: shift.each_ref().map(|s| s.to_field()),
zkpm: OnceCell::with_value(zkpm.into()),
w: OnceCell::with_value(w.to_field()),
endo: endo.to_field(),
Expand Down
10 changes: 6 additions & 4 deletions ledger/src/proofs/merge.rs
Expand Up @@ -113,10 +113,12 @@ impl<F: FieldWitness>
feature_flags: _, // TODO: Handle features flags
} = value;

let alpha_bytes = std::array::from_fn(|i| alpha.inner[i].as_u64());
let beta_bytes = std::array::from_fn(|i| beta[i].as_u64());
let gamma_bytes = std::array::from_fn(|i| gamma[i].as_u64());
let zeta_bytes = std::array::from_fn(|i| zeta.inner[i].as_u64());
let to_bytes = |v: &v2::LimbVectorConstantHex64StableV1| v.as_u64();

let alpha_bytes = alpha.inner.each_ref().map(to_bytes);
let beta_bytes = beta.each_ref().map(to_bytes);
let gamma_bytes = gamma.each_ref().map(to_bytes);
let zeta_bytes = zeta.inner.each_ref().map(to_bytes);

assert!(joint_combiner.is_none());

Expand Down
12 changes: 5 additions & 7 deletions ledger/src/proofs/prover.rs
@@ -1,4 +1,4 @@
use std::{array, borrow::Cow, str::FromStr};
use std::{borrow::Cow, str::FromStr};

use kimchi::{
poly_commitment::PolyComm,
Expand Down Expand Up @@ -46,10 +46,8 @@ pub fn make_padded_proof_from_p2p(
shifted: None,
};

let w_comm: [PolyComm<Pallas>; 15] =
array::from_fn(|i| make_poly(&proof.commitments.w_comm[i]));
let w_comm: [PolyComm<Pallas>; 15] = proof.commitments.w_comm.each_ref().map(make_poly);
let z_comm: PolyComm<Pallas> = make_poly(&proof.commitments.z_comm);
// let t_comm: [PolyComm<Pallas>; 7] = array::from_fn(|i| make_poly(&proof.commitments.t_comm[i]));
let t_comm: PolyComm<Pallas> = {
let unshifted = proof.commitments.t_comm.iter().map(of_coord).collect();
PolyComm {
Expand Down Expand Up @@ -84,12 +82,12 @@ pub fn make_padded_proof_from_p2p(
};

let evals: ProofEvaluations<PointEvaluations<Vec<Fq>>> = ProofEvaluations {
w: array::from_fn(|i| to_pt_eval(&evals.w[i])),
w: evals.w.each_ref().map(to_pt_eval),
z: to_pt_eval(&evals.z),
s: array::from_fn(|i| to_pt_eval(&evals.s[i])),
s: evals.s.each_ref().map(to_pt_eval),
generic_selector: to_pt_eval(&evals.generic_selector),
poseidon_selector: to_pt_eval(&evals.poseidon_selector),
coefficients: array::from_fn(|i| to_pt_eval(&evals.coefficients[i])),
coefficients: evals.coefficients.each_ref().map(to_pt_eval),
complete_add_selector: to_pt_eval(&evals.complete_add_selector),
mul_selector: to_pt_eval(&evals.mul_selector),
emul_selector: to_pt_eval(&evals.emul_selector),
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/proofs/public_input/messages.rs
Expand Up @@ -17,8 +17,8 @@ impl<'a> From<&'a VerifierIndex<Pallas>> for PlonkVerificationKeyEvals<Fp> {
let to_curve = |v: &PolyComm<Pallas>| InnerCurve::of_affine(v.unshifted[0]);

Self {
sigma: std::array::from_fn(|i| to_curve(&verifier_index.sigma_comm[i])),
coefficients: std::array::from_fn(|i| to_curve(&verifier_index.coefficients_comm[i])),
sigma: verifier_index.sigma_comm.each_ref().map(to_curve),
coefficients: verifier_index.coefficients_comm.each_ref().map(to_curve),
generic: to_curve(&verifier_index.generic_comm),
psm: to_curve(&verifier_index.psm_comm),
complete_add: to_curve(&verifier_index.complete_add_comm),
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/proofs/public_input/scalar_challenge.rs
Expand Up @@ -95,7 +95,7 @@ impl ScalarChallenge {

pub fn array_to_fields<F: FieldWitness, const N: usize>(array: &[F; N]) -> [F; N] {
let (_, endo) = endos::<F::Scalar>();
std::array::from_fn(|i| Self::from(array[i]).to_field(&endo))
array.each_ref().map(|v| Self::from(*v).to_field(&endo))
}

pub fn limbs_to_field<F: FieldWitness>(limbs: &[u64; 2]) -> F {
Expand Down
61 changes: 29 additions & 32 deletions ledger/src/proofs/step.rs
Expand Up @@ -209,28 +209,24 @@ impl From<&v2::PicklesProofProofsVerified2ReprStableV2StatementProofState> for S
Self {
deferred_values: StatementDeferredValues {
plonk: plonk.into(),
bulletproof_challenges: std::array::from_fn(|i| {
std::array::from_fn(|j| {
bulletproof_challenges[i].prechallenge.inner[j].as_u64()
})
}),
bulletproof_challenges: bulletproof_challenges
.each_ref()
.map(|challenge| challenge.prechallenge.inner.each_ref().map(|v| v.as_u64())),
branch_data: branch_data.clone(),
},
sponge_digest_before_evaluations: std::array::from_fn(|i| {
sponge_digest_before_evaluations[i].as_u64()
}),
sponge_digest_before_evaluations: sponge_digest_before_evaluations
.each_ref()
.map(|v| v.as_u64()),
messages_for_next_wrap_proof: MessagesForNextWrapProof {
challenge_polynomial_commitment: InnerCurve::from((
c0.to_field::<Fq>(),
c1.to_field(),
)),
old_bulletproof_challenges: old_bulletproof_challenges
.iter()
.map(|v| {
std::array::from_fn(|i| {
u64_to_field::<_, 2>(&std::array::from_fn(|j| {
v.0[i].prechallenge.inner[j].as_u64()
}))
.map(|old_bulletproof_challenge| {
old_bulletproof_challenge.each_ref().map(|chal| {
u64_to_field(&chal.prechallenge.inner.each_ref().map(|v| v.as_u64()))
})
})
.collect(),
Expand Down Expand Up @@ -2101,17 +2097,17 @@ fn expand_proof(params: ExpandProofParams) -> ExpandedProof {
.deferred_values
.bulletproof_challenges
.iter()
.map(|v| {
u64_to_field::<_, 2>(&std::array::from_fn(|i| {
v.prechallenge.inner[i].as_u64()
}))
.map(|challenge| {
u64_to_field(&challenge.prechallenge.inner.each_ref().map(|v| v.as_u64()))
})
.collect(),
branch_data: deferred_values.branch_data,
},
sponge_digest_before_evaluations: std::array::from_fn(|i| {
statement.proof_state.sponge_digest_before_evaluations[i].as_u64()
}),
sponge_digest_before_evaluations: statement
.proof_state
.sponge_digest_before_evaluations
.each_ref()
.map(|v| v.as_u64()),
messages_for_next_wrap_proof: MessagesForNextWrapProof {
old_bulletproof_challenges: prev_challenges.clone(),
challenge_polynomial_commitment: {
Expand Down Expand Up @@ -2473,9 +2469,8 @@ pub fn extract_recursion_challenges<const N: usize>(
) -> Vec<RecursionChallenge<GroupAffine<Fq>>> {
use poly_commitment::PolyComm;

let comms: [(Fq, Fq); N] = std::array::from_fn(|i| {
let p = &proofs[i];
let (a, b) = &p
let comms: [(Fq, Fq); N] = proofs.map(|proof| {
let (a, b) = &proof
.statement
.proof_state
.messages_for_next_wrap_proof
Expand Down Expand Up @@ -2582,15 +2577,15 @@ pub fn step<C: ProofConstants, const N_PREVIOUS: usize>(
.unwrap();

let prevs: [&PerProofWitness; N_PREVIOUS] =
w.exists(std::array::from_fn(|i| &expanded_proofs[i].witness));
w.exists(expanded_proofs.each_ref().map(|p| &p.witness));
let unfinalized_proofs_unextended: [&Unfinalized; N_PREVIOUS] =
w.exists(std::array::from_fn(|i| &expanded_proofs[i].unfinalized));
w.exists(expanded_proofs.each_ref().map(|p| &p.unfinalized));

let messages_for_next_wrap_proof: [Fp; N_PREVIOUS] = {
let f = u64_to_field::<Fp, 4>;
std::array::from_fn(|i| {
f(&expanded_proofs[i]
.prev_statement_with_hashes

expanded_proofs.each_ref().map(|p| {
f(&p.prev_statement_with_hashes
.proof_state
.messages_for_next_wrap_proof)
})
Expand All @@ -2611,7 +2606,7 @@ pub fn step<C: ProofConstants, const N_PREVIOUS: usize>(
let all_possible_domains = wrap_verifier::all_possible_domains();

let actuals_wrap_domain: [u32; N_PREVIOUS] =
std::array::from_fn(|i| expanded_proofs[i].actual_wrap_domain);
expanded_proofs.each_ref().map(|p| p.actual_wrap_domain);

actuals_wrap_domain.map(|domain_size| {
let domain_size = domain_size as u64;
Expand Down Expand Up @@ -2715,8 +2710,10 @@ pub fn step<C: ProofConstants, const N_PREVIOUS: usize>(
w,
)?;

let proofs: [&v2::PicklesProofProofsVerified2ReprStableV2; N_PREVIOUS] =
std::array::from_fn(|i| rule.previous_proof_statements[i].proof);
let proofs: [&v2::PicklesProofProofsVerified2ReprStableV2; N_PREVIOUS] = rule
.previous_proof_statements
.each_ref()
.map(|stmt| stmt.proof);

let prev_evals = proofs
.iter()
Expand Down Expand Up @@ -2757,7 +2754,7 @@ pub fn step<C: ProofConstants, const N_PREVIOUS: usize>(

let old_bulletproof_challenges = old_bulletproof_challenges
.into_iter()
.map(|v: [[u64; 2]; 16]| std::array::from_fn(|i| u64_to_field::<Fp, 2>(&v[i])))
.map(|v: [[u64; 2]; 16]| v.each_ref().map(u64_to_field))
.collect();

let step_statement = crate::proofs::transaction::StepStatement {
Expand Down