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

Fix compose by changing bit shifts #101

Merged
merged 1 commit into from
Dec 30, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dusk-wallet-core"
version = "0.21.2"
version = "0.21.6"
edition = "2021"
description = "The core functionality of the Dusk wallet"
license = "MPL-2.0"
Expand Down
Binary file modified assets/dusk_wallet_core.wasm
Binary file not shown.
Binary file modified dusk-wallet-core-0.21.0.wasm
Binary file not shown.
22 changes: 12 additions & 10 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};

type Node = (Note, tx::Opening, u64, JubJubScalar);
const MAX_ALLOC_LEN: u32 = 2u32.pow(24);

/// Composes a `i64` from the provided arguments. This will be returned from the
/// WASM module functions.
pub const fn compose(success: bool, ptr: u32, len: u32) -> i64 {
pub fn compose(success: bool, ptr: u32, len: u32) -> i64 {
assert!(
len <= MAX_ALLOC_LEN,
"len must be less than {MAX_ALLOC_LEN}"
);

let success = (!success) as u64;
let ptr = (ptr as u64) << 32;
let len = ((len as u64) << 48) >> 32;
let len = ((len as u64) << 40) >> 32;

(success | ptr | len) as i64
}

Expand All @@ -36,9 +43,9 @@ pub const fn compose(success: bool, ptr: u32, len: u32) -> i64 {
/// - status: a boolean indicating the success of the operation
/// - ptr: a pointer to the underlying data
/// - len: the length of the underlying data
pub const fn decompose(result: i64) -> (bool, u32, u32) {
pub fn decompose(result: i64) -> (bool, u32, u32) {
let ptr = (result >> 32) as u32;
let len = ((result & 0xFFFFFF00) >> 16) as u32;
let len = ((result & 0xFFFFFFF0) >> 8) as u32;
let success = ((result << 63) >> 63) == 0;

(success, ptr, len)
Expand Down Expand Up @@ -76,15 +83,10 @@ pub fn sanitize_rng_seed(bytes: Vec<u8>) -> Option<[u8; 32]> {
}

/// Fails the operation
pub const fn fail() -> i64 {
pub fn fail() -> i64 {
compose(false, 0, 0)
}

/// fail
pub const fn fail_with() -> i64 {
compose(true, 0, 0)
}

/// Converts the provided response into an allocated pointer and returns the
/// composed success value.
pub fn into_ptr<T>(response: T) -> i64
Expand Down
Loading