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

Convert small int VM hooks #1713

Merged
merged 4 commits into from
Jan 15, 2025
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
92 changes: 48 additions & 44 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion chain/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ version = "=0.12.0"
path = "../core"

[dependencies.multiversx-chain-vm-executor]
version = "0.3.0"
# version = "0.3.0"
git = "https://github.com/multiversx/mx-vm-executor-rs"
rev = "45ad48765e9e2eaa446fe32327a414a3b4599820"
4 changes: 3 additions & 1 deletion chain/vm/src/tx_mock/tx_managed_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ mod tx_managed_map;

pub use handle_map::HandleMap;
use num_bigint::BigInt;
pub use tx_big_int::big_int_to_i64;
pub use tx_big_int::{
big_int_signed_bytes, big_int_to_i64, big_uint_to_u64, big_uint_unsigned_bytes,
};

use std::collections::HashMap;

Expand Down
31 changes: 26 additions & 5 deletions chain/vm/src/tx_mock/tx_managed_types/tx_big_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ impl TxManagedTypes {

pub fn bi_get_signed_bytes(&self, handle: RawHandle) -> Vec<u8> {
let bi = self.bi_get(handle);
if bi.is_zero() {
Vec::new()
} else {
bi.to_signed_bytes_be()
}
big_int_signed_bytes(&bi)
}

pub fn bi_set_signed_bytes(&mut self, destination: RawHandle, bytes: &[u8]) {
Expand Down Expand Up @@ -90,3 +86,28 @@ pub fn big_int_to_i64(bi: &num_bigint::BigInt) -> Option<i64> {
},
}
}

pub fn big_uint_to_u64(bu: &num_bigint::BigUint) -> Option<u64> {
let digits = bu.to_u64_digits();
match digits.len() {
0 => Some(0),
1 => Some(digits[0]),
_ => None,
}
}

pub fn big_uint_unsigned_bytes(bu: &num_bigint::BigUint) -> Vec<u8> {
if bu.is_zero() {
Vec::new()
} else {
bu.to_bytes_be()
}
}

pub fn big_int_signed_bytes(bi: &num_bigint::BigInt) -> Vec<u8> {
if bi.is_zero() {
Vec::new()
} else {
bi.to_signed_bytes_be()
}
}
3 changes: 3 additions & 0 deletions chain/vm/src/vm_err_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ pub const ERROR_SIGNALLED_BY_SMARTCONTRACT: &str = "error signalled by smartcont
pub const ERROR_NO_CALLBACK_CLOSURE: &str =
"no callback for closure, cannot call callback directly";

pub const ERROR_BYTES_EXCEED_INT64: &str = "bytes cannot be parsed as int64";
pub const ERROR_BYTES_EXCEED_UINT64: &str = "bytes cannot be parsed as uint64";

pub const PROMISES_TOKENIZE_FAILED: &str = "tokenize failed";
34 changes: 34 additions & 0 deletions chain/vm/src/vm_hooks/vh_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,24 @@ impl VMHooks for VMHooksDispatcher {
panic!("Unavailable: managed_multi_transfer_esdt_nft_execute_by_user")
}

fn mbuffer_to_small_int_unsigned(&self, m_buffer_handle: i32) -> i64 {
self.handler.mb_to_small_int_unsigned(m_buffer_handle) as i64
}

fn mbuffer_to_small_int_signed(&self, m_buffer_handle: i32) -> i64 {
self.handler.mb_to_small_int_signed(m_buffer_handle)
}

fn mbuffer_from_small_int_unsigned(&self, m_buffer_handle: i32, value: i64) {
self.handler
.mb_from_small_int_unsigned(m_buffer_handle, value as u64);
}

fn mbuffer_from_small_int_signed(&self, m_buffer_handle: i32, value: i64) {
self.handler
.mb_from_small_int_signed(m_buffer_handle, value);
}

fn managed_verify_secp256r1(
&self,
key_handle: i32,
Expand All @@ -1908,4 +1926,20 @@ impl VMHooks for VMHooksDispatcher {
) -> i32 {
panic!("Unavailable: managed_verify_blsaggregated_signature")
}

fn get_round_time(&self) -> i64 {
panic!("Unavailable: get_round_time")
}

fn epoch_start_block_time_stamp(&self) -> i64 {
panic!("Unavailable: epoch_start_block_time_stamp")
}

fn epoch_start_block_nonce(&self) -> i64 {
panic!("Unavailable: epoch_start_block_nonce")
}

fn epoch_start_block_round(&self) -> i64 {
panic!("Unavailable: epoch_start_block_round")
}
}
Loading
Loading