Skip to content

Commit

Permalink
Merge pull request #1747 from multiversx/deps-upgrade
Browse files Browse the repository at this point in the history
Dependencies upgraded
  • Loading branch information
andrei-marinica authored Aug 30, 2024
2 parents 47b4357 + 82cd85a commit ddc233b
Show file tree
Hide file tree
Showing 18 changed files with 328 additions and 324 deletions.
548 changes: 275 additions & 273 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions data/codec-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ default = ["syn/full", "syn/parsing", "syn/extra-traits"]

[dependencies]
proc-macro2 = "=1.0.86"
quote = "=1.0.36"
syn = "=2.0.72"
quote = "=1.0.37"
syn = "=2.0.76"
hex = "=0.4.3"
2 changes: 1 addition & 1 deletion data/codec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ version = "=0.20.1"
optional = true

[dependencies]
arrayvec = { version = "=0.7.4", default-features = false }
arrayvec = { version = "=0.7.6", default-features = false }
num-bigint = { version = "0.4", optional = true } # can only be used in std contexts
unwrap-infallible = "0.1.5"

Expand Down
4 changes: 2 additions & 2 deletions framework/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ categories = ["cryptography::cryptocurrencies", "development-tools::procedural-m

[dependencies]
proc-macro2 = "=1.0.86"
quote = "=1.0.36"
syn = "=2.0.72"
quote = "=1.0.37"
syn = "=2.0.76"
hex = "=0.4.3"
radix_trie = "=0.2.1"

Expand Down
4 changes: 2 additions & 2 deletions framework/meta-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ colored = "2.0"
lazy_static = "1.4.0"
convert_case = "0.6.0"
hex = "0.4"
wasmparser = "0.214"
wasmprinter = "0.214"
wasmparser = "0.216"
wasmprinter = "0.216"
semver = "1.0.20"

[dependencies.multiversx-sc]
Expand Down
6 changes: 3 additions & 3 deletions framework/scenario/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ base64 = "0.22"
num-bigint = "0.4"
num-traits = "0.2"
hex = "0.4"
bech32 = "0.9"
bech32 = "0.11"
log = "0.4.17"
sha2 = "0.10.6"
serde = "1.0"
Expand All @@ -32,8 +32,8 @@ colored = "2.0"
unwrap-infallible = "0.1.5"

[features]
default = ["wasm-incopatible"]
wasm-incopatible = ["multiversx-chain-vm/wasm-incopatible"]
default = ["wasm-incompatible"]
wasm-incompatible = ["multiversx-chain-vm/wasm-incompatible"]
run-go-tests = []

[dependencies.multiversx-sc]
Expand Down
9 changes: 4 additions & 5 deletions framework/scenario/src/bech32.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use bech32::{FromBase32, ToBase32, Variant};
use bech32::{Bech32, Hrp};
use multiversx_sc::types::heap::Address;

pub fn decode(bech32_address: &str) -> Address {
let (_, dest_address_bytes_u5, _) = bech32::decode(bech32_address)
let (_hrp, dest_address_bytes) = bech32::decode(bech32_address)
.unwrap_or_else(|err| panic!("bech32 decode error for {bech32_address}: {err}"));
let dest_address_bytes = Vec::<u8>::from_base32(&dest_address_bytes_u5).unwrap();
if dest_address_bytes.len() != 32 {
panic!("Invalid address length after decoding")
}
Expand All @@ -13,6 +12,6 @@ pub fn decode(bech32_address: &str) -> Address {
}

pub fn encode(address: &Address) -> String {
bech32::encode("erd", address.as_bytes().to_base32(), Variant::Bech32)
.expect("bech32 encode error")
let hrp = Hrp::parse("erd").expect("invalid hrp");
bech32::encode::<Bech32>(hrp, address.as_bytes()).expect("bech32 encode error")
}
2 changes: 1 addition & 1 deletion sdk/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ hex = "0.4.3"
base64 = "0.22"
pbkdf2 = { version = "0.12.2", default-features = false }
zeroize = "1.4.2"
bech32 = "0.9"
bech32 = "0.11"
itertools = "0.13.0"
pem = "3.0.2"
log = "0.4.17"
Expand Down
5 changes: 3 additions & 2 deletions sdk/core/src/crypto/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Display;

use super::private_key::PrivateKey;
use anyhow::Result;
use bech32::{self, ToBase32, Variant};
use bech32::{self, Bech32, Hrp};
use serde::{
de::{Deserialize, Deserializer},
ser::{Serialize, Serializer},
Expand All @@ -23,7 +23,8 @@ impl PublicKey {
}

pub fn to_address(&self) -> Result<String> {
let address = bech32::encode("erd", self.0.to_base32(), Variant::Bech32)?;
let hrp = Hrp::parse("erd")?;
let address = bech32::encode::<Bech32>(hrp, &self.0)?;
Ok(address)
}

Expand Down
8 changes: 4 additions & 4 deletions sdk/core/src/data/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::{Debug, Display};

use crate::crypto::public_key::PublicKey;
use anyhow::Result;
use bech32::{FromBase32, ToBase32, Variant};
use bech32::{Bech32, Hrp};
use serde::{
de::{Deserialize, Deserializer},
ser::{Serialize, Serializer},
Expand All @@ -21,8 +21,7 @@ impl Address {
}

pub fn from_bech32_string(bech32: &str) -> Result<Self> {
let (_, data, _) = bech32::decode(bech32)?;
let data = Vec::<u8>::from_base32(&data)?;
let (_hrp, data) = bech32::decode(bech32)?;

let mut bits: [u8; 32] = [0u8; 32];
bits.copy_from_slice(&data);
Expand All @@ -31,7 +30,8 @@ impl Address {
}

pub fn to_bech32_string(&self) -> Result<String> {
let address = bech32::encode("erd", self.0.to_base32(), Variant::Bech32)?;
let hrp = Hrp::parse("erd")?;
let address = bech32::encode::<Bech32>(hrp, &self.0)?;
Ok(address)
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/scenario-format/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ num-bigint = "0.4"
num-traits = "0.2"
hex = "0.4"
sha3 = "0.10.8"
bech32 = "0.9.0"
bech32 = "0.11.0"
5 changes: 2 additions & 3 deletions sdk/scenario-format/src/value_interpreter/functions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::value_interpreter::*;
use bech32::FromBase32;
use sha3::{Digest, Keccak256};

pub const SC_ADDRESS_NUM_LEADING_ZEROS: usize = 8;
Expand Down Expand Up @@ -71,6 +70,6 @@ pub(crate) fn sc_address_expression(input: &str, vm_type: &VMIdentifier) -> Vec<
}

pub(crate) fn bech32(input: &str) -> Vec<u8> {
let (_, decoded, _) = bech32::decode(input).expect("bech32 decode error");
Vec::<u8>::from_base32(&decoded).expect("bech32 base64 decode error")
let (_hrp, decoded) = bech32::decode(input).expect("bech32 decode error");
decoded
}
2 changes: 1 addition & 1 deletion tools/mxpy-snippet-generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version = "0.52.3"
path = "../../framework/base"

[dependencies]
bech32 = "0.9"
bech32 = "0.11"
num-bigint = "0.4"
num-traits = "0.2"
hex = "0.4"
4 changes: 1 addition & 3 deletions tools/mxpy-snippet-generator/src/helper_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bech32::FromBase32;
use multiversx_sc::types::heap::Address;

use crate::constants::*;
Expand Down Expand Up @@ -79,8 +78,7 @@ impl TransactionType {
}

pub fn bech32_to_bytes(bech32_address: &str) -> Address {
let (_, dest_address_bytes_u5, _) = bech32::decode(bech32_address).unwrap();
let dest_address_bytes = Vec::<u8>::from_base32(&dest_address_bytes_u5).unwrap();
let (_hrp, dest_address_bytes) = bech32::decode(bech32_address).unwrap();
if dest_address_bytes.len() != ADDRESS_LEN {
panic!("Invalid address length after decoding")
}
Expand Down
6 changes: 3 additions & 3 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ categories = ["cryptography::cryptocurrencies", "development-tools::debugging"]

[features]
# not supported when compiling to wasm
wasm-incopatible = ["rand", "rand_seeder", "ed25519-dalek"]
wasm-incompatible = ["rand"]

[dependencies]
num-bigint = "0.4"
Expand All @@ -31,8 +31,8 @@ hex-literal = "=0.4.1"
bitflags = "=2.6.0"
colored = "2.1.0"
rand = { version= "0.8.5", optional = true }
rand_seeder = { version= "0.2.2", optional = true }
ed25519-dalek = { version = "1.0.1" , optional = true }
rand_seeder = "0.3.0"
ed25519-dalek = "2.1.0"

[dependencies.multiversx-chain-vm-executor]
version = "0.2.0"
31 changes: 18 additions & 13 deletions vm/src/crypto_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,29 @@ pub fn keccak256(data: &[u8]) -> [u8; KECCAK256_RESULT_LEN] {
hasher.finalize().into()
}

#[cfg(feature = "wasm-incopatible")]
pub fn verify_ed25519(key: &[u8], message: &[u8], signature: &[u8]) -> bool {
use ed25519_dalek::*;
use ed25519_dalek::{Signature, Verifier, VerifyingKey};

let public = PublicKey::from_bytes(key);
if public.is_err() {
let key_32: [u8; 32] = if let Ok(key_32) = key.try_into() {
key_32
} else {
return false;
}
};
let signature_64: [u8; 64] = if let Ok(signature_64) = signature.try_into() {
signature_64
} else {
return false;
};

let sig = Signature::from_bytes(signature);
if sig.is_err() {
let verifying_key_result = VerifyingKey::from_bytes(&key_32);
let verifying_key = if let Ok(verifying_key) = verifying_key_result {
verifying_key
} else {
return false;
}
};

public.unwrap().verify(message, &sig.unwrap()).is_ok()
}
let sig = Signature::from_bytes(&signature_64);

#[cfg(not(feature = "wasm-incopatible"))]
pub fn verify_ed25519(_key: &[u8], _message: &[u8], _signature: &[u8]) -> bool {
panic!("verify_ed25519 not supported for wasm builds, feature `wasm-incopatible` needs to be enabled")
let result = verifying_key.verify(message, &sig);
result.is_ok()
}
8 changes: 4 additions & 4 deletions vm/src/tx_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ pub use tx_panic::*;
pub use tx_result::*;
pub use tx_result_calls::*;

#[cfg(feature = "wasm-incopatible")]
#[cfg(feature = "wasm-incompatible")]
mod blockchain_rng;
#[cfg(feature = "wasm-incopatible")]
#[cfg(feature = "wasm-incompatible")]
pub use blockchain_rng::BlockchainRng;

#[cfg(not(feature = "wasm-incopatible"))]
#[cfg(not(feature = "wasm-incompatible"))]
mod blockchain_rng_unsupported;
#[cfg(not(feature = "wasm-incopatible"))]
#[cfg(not(feature = "wasm-incompatible"))]
pub use blockchain_rng_unsupported::BlockchainRng;
2 changes: 1 addition & 1 deletion vm/src/tx_mock/blockchain_rng_unsupported.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ impl BlockchainRng {
}

pub fn next_bytes(&mut self, _length: usize) -> Vec<u8> {
panic!("BlockchainRng not supported for wasm builds, feature `wasm-incopatible` needs to be enabled")
panic!("BlockchainRng not supported for wasm builds, feature `wasm-incompatible` needs to be enabled")
}
}

0 comments on commit ddc233b

Please sign in to comment.