Skip to content

Commit

Permalink
Move custom Goldilocks field implementation into the verifier contract
Browse files Browse the repository at this point in the history
  • Loading branch information
ekovalev committed Dec 26, 2024
1 parent f680210 commit 018068e
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 40 deletions.
7 changes: 3 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/plonky2-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ homepage.workspace = true
repository.workspace = true

[dependencies]
gcore = { workspace = true, features = ["codec"] }
gstd.workspace = true
num = { workspace = true, features = ["alloc"] }
plonky2.workspace = true
plonky2_field.workspace = true
serde = { workspace = true, features = ["derive", "alloc"] }

[build-dependencies]
gear-wasm-builder.workspace = true
Expand Down
10 changes: 9 additions & 1 deletion examples/plonky2-verifier/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use gear_wasm_builder::WasmBuilder;

fn main() {
gear_wasm_builder::build();
// We are forcing recommended nightly toolchain due to the need to compile this
// program with `oom-handler` feature. The WASM binary of this program is then
// used by the `oom_handler_works` pallet test.
WasmBuilder::new()
.exclude_features(vec!["std"])
.with_forced_recommended_toolchain() // NOTE: Don't use this in production programs!
.build();
}
2 changes: 1 addition & 1 deletion examples/plonky2-verifier/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

//! Circuit config for a custom `Goldilocks` field implementation from `gstd`.
use gstd::primitives::goldilocks_field::GoldilocksFieldWrapper;
use super::goldilocks_field::GoldilocksFieldWrapper;
use plonky2::{hash::poseidon::PoseidonHash, plonk::config::GenericConfig};
use plonky2_field::extension::quadratic::QuadraticExtension;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,10 @@ impl Poseidon for GoldilocksFieldWrapper {

#[inline]
fn poseidon(input: [Self; 12]) -> [Self; 12] {
// Using the fact that `GoldilocksFieldWrapper` is essentially a newtype around
// `u64`.
// Using the fact that `GoldilocksFieldWrapper` is a newtype around `u64`.
let data: [u64; 12] = unsafe { core::mem::transmute(input) };

// Using proper type conversion because not every u64 number is a valid field
// element.
// Using proper conversion because not every u64 number is a valid field element.
exec::permute(data)
.expect("Error in permute")
.map(Field::from_canonical_u64)
Expand Down
3 changes: 3 additions & 0 deletions examples/plonky2-verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ pub mod serialize;

#[cfg(not(feature = "std"))]
pub mod circuit;

#[cfg(not(feature = "std"))]
pub mod goldilocks_field;
5 changes: 3 additions & 2 deletions examples/plonky2-verifier/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
//! The output message would either contain "Success" (as a byte array) or an error message.
use super::{
circuit::CustomPoseidonGoldilocksConfig as Config, serialize::parse_circuit_data_and_proof,
circuit::CustomPoseidonGoldilocksConfig as Config,
goldilocks_field::GoldilocksFieldWrapper as GF, serialize::parse_circuit_data_and_proof,
};
use gstd::{debug, msg, primitives::goldilocks_field::GoldilocksFieldWrapper as GF};
use gstd::{debug, msg};

#[gstd::async_main]
async fn main() {
Expand Down
4 changes: 0 additions & 4 deletions gstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ parity-scale-codec = { workspace = true, features = ["derive"] }
scale-info = { workspace = true, features = ["derive"] }
futures = { workspace = true, features = ["alloc"] }
waker-fn = "1.2.0"
num = { workspace = true, features = ["alloc"] }
plonky2.workspace = true
plonky2_field.workspace = true
serde = { workspace = true, features = ["derive", "alloc"] }

[features]
#! ## Default features:
Expand Down
2 changes: 0 additions & 2 deletions gstd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ mod reservations;
pub mod sync;
pub mod util;

pub mod primitives;

pub use async_runtime::{handle_reply_with_hook, message_loop};
pub use common::errors;
pub use config::{Config, SYSTEM_RESERVE};
Expand Down
22 changes: 0 additions & 22 deletions gstd/src/primitives/mod.rs

This file was deleted.

0 comments on commit 018068e

Please sign in to comment.