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

Cosmwasm #2

Open
wants to merge 7 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
628 changes: 591 additions & 37 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ members = [
"console/types/group",
"console/types/integers",
"console/types/scalar",
"console/types/string",
"console/types/string", "cosmwasm",
"curves",
"fields",
"ledger",
Expand Down Expand Up @@ -149,6 +149,7 @@ parameters = [ "snarkvm-parameters" ]
synthesizer = [ "snarkvm-synthesizer" ]
utilities = [ "snarkvm-utilities" ]
wasm = [ "snarkvm-wasm" ]
cosmwasm = [ "snarkvm-cosmwasm" ]
test_targets = [ "snarkvm-console/test_targets" ]

[dependencies.snarkvm-algorithms]
Expand Down Expand Up @@ -207,6 +208,12 @@ path = "./wasm"
version = "=1.1.0"
optional = true

[dependencies.snarkvm-cosmwasm]
path = "./cosmwasm"
version = "=1.1.0"
optional = true


[dependencies.anstyle]
version = "1"

Expand Down
9 changes: 9 additions & 0 deletions algorithms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ wasm = [
"snark",
"wasm-bindgen-futures"
]
cosmwasm = [
"crypto_hash",
"fft",
"msm",
"polycommit_cosmwasm",
"r1cs",
"snark",
]
cuda = [ "snarkvm-algorithms-cuda" ]
profiler = [ "aleo-std/profiler" ]
crypto_hash = [ ]
Expand All @@ -204,6 +212,7 @@ msm = [ ]
test = [ ]
polycommit = [ "crypto_hash", "fft", "msm", "rand_core" ]
polycommit_wasm = [ "polycommit", "snarkvm-parameters/wasm" ]
polycommit_cosmwasm = [ "polycommit", "snarkvm-parameters/cosmwasm" ]
polycommit_full = [ "polycommit", "snarkvm-parameters/default" ]
r1cs = [ "cfg-if", "fxhash", "indexmap" ]
serial = [
Expand Down
18 changes: 8 additions & 10 deletions console/network/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
[package]
name = "snarkvm-console-network"
version = "1.1.0"
authors = [ "The Aleo Team <[email protected]>" ]
authors = ["The Aleo Team <[email protected]>"]
description = "Network console library for a decentralized virtual machine"
homepage = "https://aleo.org"
repository = "https://github.com/AleoNet/snarkVM"
license = "Apache-2.0"
edition = "2021"

[features]
default = [ "snarkvm-algorithms/polycommit_full" ]
wasm = [
"snarkvm-algorithms/polycommit_wasm",
"snarkvm-parameters/wasm"
]
test = [ ]
test_targets = [ ]
default = ["snarkvm-algorithms/polycommit_full"]
wasm = ["snarkvm-algorithms/polycommit_wasm", "snarkvm-parameters/wasm"]
test = []
test_targets = []
cosmwasm = ["snarkvm-parameters/cosmwasm", "snarkvm-utilities/cosmwasm"]

[dependencies.snarkvm-algorithms]
path = "../../algorithms"
version = "=1.1.0"
default-features = false
features = [ "snark" ]
features = ["snark"]

[dependencies.snarkvm-console-algorithms]
path = "../algorithms"
Expand All @@ -39,7 +37,7 @@ version = "=1.1.0"
path = "../types"
version = "=1.1.0"
default-features = false
features = [ "field", "group", "scalar" ]
features = ["field", "group", "scalar"]

[dependencies.snarkvm-curves]
path = "../../curves"
Expand Down
42 changes: 42 additions & 0 deletions cosmwasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "snarkvm-cosmwasm"
version = "1.1.0"
edition = "2024"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = []
full = ["account", "network", "types", "program"]
account = ["snarkvm-console-account"]
network = ["snarkvm-console-network"]
types = ["snarkvm-console-types"]
program = ["snarkvm-console-program"]

[dependencies.snarkvm-console-account]
path = "../console/account"
version = "=1.1.0"
optional = true

[dependencies.snarkvm-console-network]
path = "../console/network"
version = "=1.1.0"
features = ["cosmwasm"]
optional = true

[dependencies.snarkvm-console-types]
path = "../console/types"
version = "=1.1.0"
default-features = false
features = ["address"]
optional = true

[dependencies.snarkvm-console-program]
path = "../console/program"
version = "=1.1.0"
optional = true

[dependencies.getrandom]
version = "0.2"
features = ["custom"]
24 changes: 24 additions & 0 deletions cosmwasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 Aleo Network Foundation
// This file is part of the snarkVM library.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


#[cfg(feature = "account")]
pub use snarkvm_console_account as account;
#[cfg(feature = "network")]
pub use snarkvm_console_network as network;
#[cfg(feature = "types")]
pub use snarkvm_console_types as types;
#[cfg(feature = "program")]
pub use snarkvm_console_program as program;
2 changes: 1 addition & 1 deletion fields/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ macro_rules! sqrt_impl {
let v = $self.pow($P::T_MINUS_ONE_DIV_TWO);
let x = *$self * v.square();

let k = ((n - 1) as f64).sqrt().floor() as u64;
let k = n.isqrt();
// It's important that k_2 results in a number which makes `l_minus_one_times_k`
// divisible by `k`, because the native arithmetic will not match the field
// arithmetic otherwise (native numbers will divide and round down, but field
Expand Down
4 changes: 4 additions & 0 deletions parameters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ default = [ "colored", "remote" ]
no_std_out = [ ]
remote = [ "curl" ]
wasm = [ "encoding", "js-sys", "web-sys" ]
cosmwasm = [ "getrandom/custom" ]

[dependencies.getrandom]
version = "0.2"

[dependencies.snarkvm-curves]
path = "../curves"
Expand Down
1 change: 1 addition & 0 deletions parameters/src/canary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub use genesis::*;
/// The restrictions list as a JSON-compatible string.
pub const RESTRICTIONS_LIST: &str = include_str!("./resources/restrictions.json");

#[cfg(not(feature = "cosmwasm"))]
const REMOTE_URL: &str = "https://parameters.aleo.org/canary";

// BondPublic
Expand Down
2 changes: 1 addition & 1 deletion parameters/src/errors/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub enum ParameterError {
Wasm(String),
}

#[cfg(not(feature = "wasm"))]
#[cfg(not(any(feature = "wasm", feature = "cosmwasm")))]
impl From<curl::Error> for ParameterError {
fn from(error: curl::Error) -> Self {
ParameterError::Crate("curl::error", format!("{error:?}"))
Expand Down
105 changes: 60 additions & 45 deletions parameters/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ macro_rules! checksum_error {
macro_rules! remove_file {
($filepath:expr) => {
// Safely remove the corrupt file, if it exists.
#[cfg(not(feature = "wasm"))]
#[cfg(not(any(feature = "wasm", feature = "cosmwasm")))]
if std::path::PathBuf::from(&$filepath).exists() {
match std::fs::remove_file(&$filepath) {
Ok(()) => println!("Removed {:?}. Please retry the command.", $filepath),
Expand All @@ -44,7 +44,7 @@ macro_rules! remove_file {

macro_rules! impl_store_and_remote_fetch {
() => {
#[cfg(not(feature = "wasm"))]
#[cfg(not(any(feature = "wasm", feature = "cosmwasm")))]
fn store_bytes(buffer: &[u8], file_path: &std::path::Path) -> Result<(), $crate::errors::ParameterError> {
use snarkvm_utilities::Write;

Expand All @@ -68,7 +68,7 @@ macro_rules! impl_store_and_remote_fetch {
Ok(())
}

#[cfg(not(feature = "wasm"))]
#[cfg(not(any(feature = "wasm", feature = "cosmwasm")))]
fn remote_fetch(buffer: &mut Vec<u8>, url: &str) -> Result<(), $crate::errors::ParameterError> {
let mut easy = curl::easy::Easy::new();
easy.follow_location(true)?;
Expand Down Expand Up @@ -167,6 +167,7 @@ macro_rules! impl_load_bytes_logic_local {
};
}

#[cfg(not(feature = "cosmwasm"))]
macro_rules! impl_load_bytes_logic_remote {
($remote_url: expr, $local_dir: expr, $filename: expr, $metadata: expr, $expected_checksum: expr, $expected_size: expr) => {
// Compose the correct file path for the parameter file.
Expand Down Expand Up @@ -194,7 +195,7 @@ macro_rules! impl_load_bytes_logic_remote {

// Load remote file
cfg_if::cfg_if! {
if #[cfg(not(feature = "wasm"))] {
if #[cfg(not(any(feature = "wasm", feature = "cosmwasm")))] {
let mut buffer = vec![];
Self::remote_fetch(&mut buffer, &url)?;

Expand Down Expand Up @@ -224,7 +225,7 @@ macro_rules! impl_load_bytes_logic_remote {
}

buffer
} else {
} else {
return Err($crate::errors::ParameterError::RemoteFetchDisabled);
}
}
Expand Down Expand Up @@ -321,27 +322,33 @@ macro_rules! impl_remote {
impl_store_and_remote_fetch!();

pub fn load_bytes() -> Result<Vec<u8>, $crate::errors::ParameterError> {
let metadata: serde_json::Value =
serde_json::from_str(Self::METADATA).expect("Metadata was not well-formatted");
let expected_checksum: String =
metadata["checksum"].as_str().expect("Failed to parse checksum").to_string();
let expected_size: usize =
metadata["size"].to_string().parse().expect("Failed to retrieve the file size");
#[cfg(not(feature = "cosmwasm"))]
{
let metadata: serde_json::Value =
serde_json::from_str(Self::METADATA).expect("Metadata was not well-formatted");
let expected_checksum: String =
metadata["checksum"].as_str().expect("Failed to parse checksum").to_string();
let expected_size: usize =
metadata["size"].to_string().parse().expect("Failed to retrieve the file size");

// Construct the versioned filename.
let filename = match expected_checksum.get(0..7) {
Some(sum) => format!("{}.{}.{}", $fname, "usrs", sum),
_ => format!("{}.{}", $fname, "usrs"),
};

impl_load_bytes_logic_remote!(
$remote_url,
$local_dir,
&filename,
metadata,
expected_checksum,
expected_size
);
}

// Construct the versioned filename.
let filename = match expected_checksum.get(0..7) {
Some(sum) => format!("{}.{}.{}", $fname, "usrs", sum),
_ => format!("{}.{}", $fname, "usrs"),
};

impl_load_bytes_logic_remote!(
$remote_url,
$local_dir,
&filename,
metadata,
expected_checksum,
expected_size
);
#[cfg(feature = "cosmwasm")]
unimplemented!()
}
}
paste::item! {
Expand All @@ -361,27 +368,35 @@ macro_rules! impl_remote {
impl_store_and_remote_fetch!();

pub fn load_bytes() -> Result<Vec<u8>, $crate::errors::ParameterError> {
let metadata: serde_json::Value =
serde_json::from_str(Self::METADATA).expect("Metadata was not well-formatted");
let expected_checksum: String =
metadata[concat!($ftype, "_checksum")].as_str().expect("Failed to parse checksum").to_string();
let expected_size: usize =
metadata[concat!($ftype, "_size")].to_string().parse().expect("Failed to retrieve the file size");
#[cfg(not(feature = "cosmwasm"))]
{
let metadata: serde_json::Value =
serde_json::from_str(Self::METADATA).expect("Metadata was not well-formatted");
let expected_checksum: String =
metadata[concat!($ftype, "_checksum")].as_str().expect("Failed to parse checksum").to_string();
let expected_size: usize = metadata[concat!($ftype, "_size")]
.to_string()
.parse()
.expect("Failed to retrieve the file size");

// Construct the versioned filename.
let filename = match expected_checksum.get(0..7) {
Some(sum) => format!("{}.{}.{}", $fname, $ftype, sum),
_ => format!("{}.{}", $fname, $ftype),
};

impl_load_bytes_logic_remote!(
$remote_url,
$local_dir,
&filename,
metadata,
expected_checksum,
expected_size
);
}

// Construct the versioned filename.
let filename = match expected_checksum.get(0..7) {
Some(sum) => format!("{}.{}.{}", $fname, $ftype, sum),
_ => format!("{}.{}", $fname, $ftype),
};

impl_load_bytes_logic_remote!(
$remote_url,
$local_dir,
&filename,
metadata,
expected_checksum,
expected_size
);
#[cfg(feature = "cosmwasm")]
unimplemented!()
}
}

Expand Down
1 change: 1 addition & 0 deletions parameters/src/mainnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub use powers::*;
/// The restrictions list as a JSON-compatible string.
pub const RESTRICTIONS_LIST: &str = include_str!("./resources/restrictions.json");

#[cfg(not(feature = "cosmwasm"))]
const REMOTE_URL: &str = "https://parameters.aleo.org/mainnet";

// Degrees
Expand Down
1 change: 1 addition & 0 deletions parameters/src/testnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub use genesis::*;
/// The restrictions list as a JSON-compatible string.
pub const RESTRICTIONS_LIST: &str = include_str!("./resources/restrictions.json");

#[cfg(not(feature = "cosmwasm"))]
const REMOTE_URL: &str = "https://parameters.aleo.org/testnet";

// BondPublic
Expand Down
Loading