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

Feat/synth wasm #1

Open
wants to merge 13 commits into
base: testnet3
Choose a base branch
from
28 changes: 18 additions & 10 deletions Cargo.lock

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

10 changes: 8 additions & 2 deletions algorithms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ version = "1.0"
version = "0.4"
optional = true

[dependencies.web-sys]
version = "0.3"
optional = true
features = ["console"]

[dev-dependencies.expect-test]
version = "1.1.0"

Expand All @@ -167,14 +172,15 @@ default = [
"snarkvm-r1cs/default",
"snarkvm-utilities/default"
]
full = [ "crypto_hash", "fft", "msm", "polycommit_full", "snark" ]
full = [ "crypto_hash", "fft", "msm", "polycommit_full", "snark", "web-sys" ]
wasm = [
"crypto_hash",
"fft",
"msm",
"polycommit_wasm",
"snark",
"wasm-bindgen-futures"
"wasm-bindgen-futures",
"web-sys"
]
cuda = [ "snarkvm-algorithms-cuda" ]
parallel = [
Expand Down
5 changes: 5 additions & 0 deletions algorithms/src/snark/marlin/ahp/indexer/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ impl<F: PrimeField, MM: MarlinMode> CanonicalDeserialize for Circuit<F, MM> {
compress: Compress,
validate: Validate,
) -> Result<Self, SerializationError> {
//use web_sys::console;
//console::log_1(&"Deser 1".into());
let index_info: CircuitInfo<F> = CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?;
let constraint_domain_size = EvaluationDomain::<F>::compute_size_of_domain(index_info.num_constraints)
.ok_or(SerializationError::InvalidData)?;
Expand All @@ -147,13 +149,16 @@ impl<F: PrimeField, MM: MarlinMode> CanonicalDeserialize for Circuit<F, MM> {
let non_zero_c_domain_size = EvaluationDomain::<F>::compute_size_of_domain(index_info.num_non_zero_c)
.ok_or(SerializationError::InvalidData)?;

//console::log_1(&"Deser 2".into());

let (fft_precomputation, ifft_precomputation) = AHPForR1CS::<F, MM>::fft_precomputation(
constraint_domain_size,
non_zero_a_domain_size,
non_zero_b_domain_size,
non_zero_c_domain_size,
)
.ok_or(SerializationError::InvalidData)?;
//console::log_1(&"Deser 3".into());
Ok(Circuit {
index_info,
a: CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ impl<E: PairingEngine, MM: MarlinMode> ToBytes for CircuitProvingKey<E, MM> {
impl<E: PairingEngine, MM: MarlinMode> FromBytes for CircuitProvingKey<E, MM> {
#[inline]
fn read_le<R: Read>(mut reader: R) -> io::Result<Self> {
//use web_sys::console;

//console::log_1(&"Read Le 1".into());
let circuit_verifying_key = CanonicalDeserialize::deserialize_compressed(&mut reader)?;
//console::log_1(&"Read Le 2".into());
let circuit_commitment_randomness = CanonicalDeserialize::deserialize_compressed(&mut reader)?;
//console::log_1(&"Read Le 3".into());
let circuit = CanonicalDeserialize::deserialize_compressed(&mut reader)?;
//console::log_1(&"Read Le 4".into());
let committer_key = Arc::new(FromBytes::read_le(&mut reader)?);
//console::log_1(&"Read Le 5".into());

Ok(Self { circuit_verifying_key, circuit_commitment_randomness, circuit, committer_key })
}
Expand Down
8 changes: 4 additions & 4 deletions circuit/environment/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ pub trait Environment: 'static + Copy + Clone + fmt::Debug + fmt::Display + Eq +
type Network: console::Network<Affine = Self::Affine, Field = Self::BaseField, Scalar = Self::ScalarField>;

type Affine: AffineCurve<
BaseField = Self::BaseField,
ScalarField = Self::ScalarField,
Coordinates = (Self::BaseField, Self::BaseField),
>;
BaseField = Self::BaseField,
ScalarField = Self::ScalarField,
Coordinates = (Self::BaseField, Self::BaseField),
>;
type BaseField: PrimeField + SquareRootField + Copy;
type ScalarField: PrimeField<BigInteger = <Self::BaseField as PrimeField>::BigInteger> + Copy;

Expand Down
4 changes: 4 additions & 0 deletions console/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ version = "1"

[dependencies.serde]
version = "1.0"

[dependencies.web-sys]
version = "0.3"
features = ["console"]
10 changes: 5 additions & 5 deletions console/network/environment/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ pub trait Environment:
'static + Copy + Clone + Debug + PartialEq + Eq + Hash + Serialize + DeserializeOwned + Send + Sync
{
type Affine: AffineCurve<
Projective = Self::Projective,
BaseField = Self::Field,
ScalarField = Self::Scalar,
Coordinates = (Self::Field, Self::Field),
>;
Projective = Self::Projective,
BaseField = Self::Field,
ScalarField = Self::Scalar,
Coordinates = (Self::Field, Self::Field),
>;
type BigInteger: BigInteger;
type Field: PrimeField<BigInteger = Self::BigInteger> + SquareRootField + Copy;
type PairingCurve: PairingEngine<Fr = Self::Field>;
Expand Down
2 changes: 1 addition & 1 deletion console/network/src/testnet3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Network for Testnet3 {

/// Returns the genesis block bytes.
fn genesis_bytes() -> &'static [u8] {
snarkvm_parameters::testnet3::GenesisBytes::load_bytes()
&[1u8, 2u8, 3u8, 4u8, 5u8]
}

/// Returns the proving key for the given function name in `credits.aleo`.
Expand Down
34 changes: 17 additions & 17 deletions curves/src/templates/bls12/bls12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ pub trait Bls12Parameters: 'static + Copy + Clone + Debug + PartialEq + Eq + Has
type Fp12Params: Fp12Parameters<Fp6Params = Self::Fp6Params>;
type G1Parameters: ShortWeierstrassParameters<BaseField = Self::Fp>;
type G2Parameters: ShortWeierstrassParameters<
BaseField = Fp2<Self::Fp2Params>,
ScalarField = <Self::G1Parameters as ModelParameters>::ScalarField,
>;
BaseField = Fp2<Self::Fp2Params>,
ScalarField = <Self::G1Parameters as ModelParameters>::ScalarField,
>;

fn g1_is_in_correct_subgroup(p: &short_weierstrass_jacobian::Affine<Self::G1Parameters>) -> bool {
p.mul_bits(BitIteratorBE::new(<Self::G1Parameters as ModelParameters>::ScalarField::characteristic())).is_zero()
Expand Down Expand Up @@ -108,21 +108,21 @@ impl<P: Bls12Parameters> Bls12<P> {
impl<P: Bls12Parameters> PairingEngine for Bls12<P>
where
G1Affine<P>: PairingCurve<
BaseField = <P::G1Parameters as ModelParameters>::BaseField,
ScalarField = <P::G1Parameters as ModelParameters>::ScalarField,
Projective = G1Projective<P>,
PairWith = G2Affine<P>,
Prepared = G1Prepared<P>,
PairingResult = Fp12<P::Fp12Params>,
>,
BaseField = <P::G1Parameters as ModelParameters>::BaseField,
ScalarField = <P::G1Parameters as ModelParameters>::ScalarField,
Projective = G1Projective<P>,
PairWith = G2Affine<P>,
Prepared = G1Prepared<P>,
PairingResult = Fp12<P::Fp12Params>,
>,
G2Affine<P>: PairingCurve<
BaseField = <P::G2Parameters as ModelParameters>::BaseField,
ScalarField = <P::G1Parameters as ModelParameters>::ScalarField,
Projective = G2Projective<P>,
PairWith = G1Affine<P>,
Prepared = G2Prepared<P>,
PairingResult = Fp12<P::Fp12Params>,
>,
BaseField = <P::G2Parameters as ModelParameters>::BaseField,
ScalarField = <P::G1Parameters as ModelParameters>::ScalarField,
Projective = G2Projective<P>,
PairWith = G1Affine<P>,
Prepared = G2Prepared<P>,
PairingResult = Fp12<P::Fp12Params>,
>,
{
type Fq = P::Fp;
type Fqe = Fp2<P::Fp2Params>;
Expand Down
4 changes: 4 additions & 0 deletions fields/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ features = [ "derive" ]
[dependencies.thiserror]
version = "1.0"

[dependencies.web-sys]
version = "0.3"
features = ["console"]

[features]
default = [ "parallel", "snarkvm-utilities/default" ]
parallel = [ "rayon", "snarkvm-utilities/parallel" ]
Expand Down
5 changes: 5 additions & 0 deletions fields/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ macro_rules! impl_primefield_serializer {
mut reader: R,
) -> Result<(Self, F), snarkvm_utilities::serialize::SerializationError> {
use snarkvm_utilities::serialize::SerializationError;
use web_sys::console;
// All reasonable `Flags` should be less than 8 bits in size
// (256 values are enough for anyone!)
if F::BIT_SIZE > 8 {
Expand All @@ -273,6 +274,10 @@ macro_rules! impl_primefield_serializer {

let mut masked_bytes = [0; $byte_size + 1];
reader.read_exact(&mut masked_bytes[..output_byte_size])?;
let formatted_string = format!("{:?} , {}", masked_bytes, output_byte_size);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super weird bug here. It deserializes differently from the wasm vs the rust test. Not sure why yet, maybe some deserialization reordering. This happens when deserializing the transfer prover file.

This is the bug preventing it from working.

Screenshot 2023-02-06 at 10 32 06 PM

Screenshot 2023-02-06 at 10 32 39 PM

Screenshot 2023-02-06 at 10 33 16 PM

console::log_1(&formatted_string.into());

println!("{:?} , {}", masked_bytes, output_byte_size);

let flags = F::from_u8_remove_flags(&mut masked_bytes[output_byte_size - 1])
.ok_or(SerializationError::UnexpectedFlags)?;
Expand Down
11 changes: 10 additions & 1 deletion parameters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ default-features = false
[dependencies.thiserror]
version = "1.0"

[dependencies.web-sys]
version = "0.3"
optional = true
features = ["console"]

[dependencies.wasm-bindgen]
version = "0.2"
optional = true

[dependencies.wasm-bindgen-futures]
version = "0.4"
optional = true
Expand Down Expand Up @@ -119,4 +128,4 @@ version = "0.8"
default = [ "colored", "remote" ]
no_std_out = [ ]
remote = [ "curl" ]
wasm = [ "reqwest", "wasm-bindgen-futures" ]
wasm = [ "reqwest", "web-sys", "wasm-bindgen", "wasm-bindgen-futures" ]
3 changes: 3 additions & 0 deletions parameters/src/errors/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub enum ParameterError {
#[error("Remote fetch is disabled, enable compiler flag for feature")]
RemoteFetchDisabled,

#[error("Necessary File Not Found")]
NotFound,

#[error("Expected size of {}, found size of {}", _0, _1)]
SizeMismatch(usize, usize),
}
Expand Down
1 change: 1 addition & 0 deletions parameters/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ macro_rules! impl_remote {
}
}
};

($name: ident, $remote_url: expr, $local_dir: expr, $fname: tt, $ftype: tt) => {
pub struct $name;

Expand Down
30 changes: 15 additions & 15 deletions parameters/src/testnet3/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
// You should have received a copy of the GNU General Public License
// along with the snarkVM library. If not, see <https://www.gnu.org/licenses/>.

pub struct GenesisBytes;
// pub struct GenesisBytes;

impl GenesisBytes {
pub const fn load_bytes() -> &'static [u8] {
include_bytes!("./resources/block.genesis")
}
}
// impl GenesisBytes {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just testing the limits of how much I could remove before things break. This isn't necessary for the client.

// pub const fn load_bytes() -> &'static [u8] {
// include_bytes!("./resources-tmp/block.genesis")
// }
// }

#[cfg(test)]
mod tests {
use super::*;
// #[cfg(test)]
// mod tests {
// use super::*;

#[test]
fn test_genesis_block() {
let bytes = GenesisBytes::load_bytes();
assert_eq!(1783, bytes.len() as u64, "Update me if serialization has changed");
}
}
// #[test]
// fn test_genesis_block() {
// let bytes = GenesisBytes::load_bytes();
// assert_eq!(1783, bytes.len() as u64, "Update me if serialization has changed");
// }
// }
Loading