Skip to content

Commit 4b24932

Browse files
Merge pull request #1921 from multiversx/feat/barnard
feat/barnard (targeting VM barnard release)
2 parents e6565f0 + 686e6f3 commit 4b24932

File tree

197 files changed

+9238
-1014
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+9238
-1014
lines changed

Cargo.lock

Lines changed: 287 additions & 221 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ members = [
114114
"contracts/feature-tests/abi-tester/meta",
115115
"contracts/feature-tests/alloc-features",
116116
"contracts/feature-tests/alloc-features/meta",
117+
"contracts/feature-tests/barnard-features",
118+
"contracts/feature-tests/barnard-features/meta",
119+
"contracts/feature-tests/barnard-features/interactor",
117120
"contracts/feature-tests/basic-features",
118121
"contracts/feature-tests/basic-features/meta",
119122
"contracts/feature-tests/basic-features/interact",
@@ -133,8 +136,10 @@ members = [
133136
"contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/child",
134137
"contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/child/meta",
135138
"contracts/feature-tests/composability/forwarder",
136-
"contracts/feature-tests/composability/forwarder-interactor",
137139
"contracts/feature-tests/composability/forwarder/meta",
140+
"contracts/feature-tests/composability/forwarder-barnard",
141+
"contracts/feature-tests/composability/forwarder-barnard/meta",
142+
"contracts/feature-tests/composability/forwarder-interactor",
138143
"contracts/feature-tests/composability/forwarder-legacy",
139144
"contracts/feature-tests/composability/forwarder-legacy/meta",
140145
"contracts/feature-tests/composability/forwarder-queue",

chain/core/src/types/flags/esdt_token_type.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// use multiversx_sc_derive::{type_abi, ManagedVecItem};
2-
31
use crate::codec::{
42
self,
53
derive::{NestedDecode, NestedEncode, TopDecode, TopEncode},
@@ -102,3 +100,19 @@ impl<'a> From<&'a [u8]> for EsdtTokenType {
102100
}
103101
}
104102
}
103+
104+
impl From<Option<u64>> for EsdtTokenType {
105+
#[inline]
106+
fn from(value: Option<u64>) -> Self {
107+
match value {
108+
Some(0) => Self::Fungible,
109+
Some(1) => Self::NonFungible,
110+
Some(2) => Self::SemiFungible,
111+
Some(3) => Self::Meta,
112+
Some(4) => Self::DynamicNFT,
113+
Some(5) => Self::DynamicSFT,
114+
Some(6) => Self::DynamicMeta,
115+
_ => Self::Invalid,
116+
}
117+
}
118+
}

chain/vm/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ path = "../core"
4545

4646
[dependencies.multiversx-chain-vm-executor]
4747
version = "0.4.0"
48+
git = "https://github.com/multiversx/mx-vm-executor-rs"
49+
rev = "5804799ee7b6446c9e7641b8308acb48ec00d751"
4850

4951
[dependencies.multiversx-chain-vm-executor-wasmer-experimental]
5052
version = "0.4.0"
5153
optional = true
54+
git = "https://github.com/multiversx/mx-vm-executor-rs"
55+
rev = "5804799ee7b6446c9e7641b8308acb48ec00d751"

chain/vm/src/host/context/managed_type_container.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ mod tx_managed_map;
66

77
pub use handle_map::HandleMap;
88
use num_bigint::BigInt;
9-
pub use tx_big_int::big_int_to_i64;
9+
pub use tx_big_int::{
10+
big_int_signed_bytes, big_int_to_i64, big_uint_to_u64, big_uint_unsigned_bytes,
11+
};
1012
pub use tx_managed_buffer::InvalidSliceError;
1113

1214
use std::collections::HashMap;

chain/vm/src/host/context/managed_type_container/tx_big_int.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ impl ManagedTypeContainer {
4747

4848
pub fn bi_get_signed_bytes(&self, handle: RawHandle) -> Vec<u8> {
4949
let bi = self.bi_get(handle);
50-
if bi.is_zero() {
51-
Vec::new()
52-
} else {
53-
bi.to_signed_bytes_be()
54-
}
50+
big_int_signed_bytes(&bi)
5551
}
5652

5753
pub fn bi_set_signed_bytes(&mut self, destination: RawHandle, bytes: &[u8]) {
@@ -90,3 +86,28 @@ pub fn big_int_to_i64(bi: &num_bigint::BigInt) -> Option<i64> {
9086
},
9187
}
9288
}
89+
90+
pub fn big_uint_to_u64(bu: &num_bigint::BigUint) -> Option<u64> {
91+
let digits = bu.to_u64_digits();
92+
match digits.len() {
93+
0 => Some(0),
94+
1 => Some(digits[0]),
95+
_ => None,
96+
}
97+
}
98+
99+
pub fn big_uint_unsigned_bytes(bu: &num_bigint::BigUint) -> Vec<u8> {
100+
if bu.is_zero() {
101+
Vec::new()
102+
} else {
103+
bu.to_bytes_be()
104+
}
105+
}
106+
107+
pub fn big_int_signed_bytes(bi: &num_bigint::BigInt) -> Vec<u8> {
108+
if bi.is_zero() {
109+
Vec::new()
110+
} else {
111+
bi.to_signed_bytes_be()
112+
}
113+
}

chain/vm/src/host/vm_hooks/vh_dispatcher.rs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ impl<C: VMHooksContext> VMHooks for VMHooksDispatcher<C> {
501501
self.handler.get_block_timestamp()
502502
}
503503

504+
fn get_block_timestamp_ms(&mut self) -> Result<i64, VMHooksEarlyExit> {
505+
self.handler.get_block_timestamp_ms()
506+
}
507+
504508
fn get_block_nonce(&mut self) -> Result<i64, VMHooksEarlyExit> {
505509
self.handler.get_block_nonce()
506510
}
@@ -525,6 +529,10 @@ impl<C: VMHooksContext> VMHooks for VMHooksDispatcher<C> {
525529
self.handler.get_prev_block_timestamp()
526530
}
527531

532+
fn get_prev_block_timestamp_ms(&mut self) -> Result<i64, VMHooksEarlyExit> {
533+
self.handler.get_prev_block_timestamp_ms()
534+
}
535+
528536
fn get_prev_block_nonce(&mut self) -> Result<i64, VMHooksEarlyExit> {
529537
self.handler.get_prev_block_nonce()
530538
}
@@ -700,6 +708,22 @@ impl<C: VMHooksContext> VMHooks for VMHooksDispatcher<C> {
700708
self.handler.get_prev_block_random_seed(result_handle)
701709
}
702710

711+
fn get_block_round_time_ms(&mut self) -> Result<i64, VMHooksEarlyExit> {
712+
panic!("Unavailable: get_block_round_time_ms")
713+
}
714+
715+
fn epoch_start_block_timestamp_ms(&mut self) -> Result<i64, VMHooksEarlyExit> {
716+
panic!("Unavailable: epoch_start_block_timestamp")
717+
}
718+
719+
fn epoch_start_block_nonce(&mut self) -> Result<i64, VMHooksEarlyExit> {
720+
panic!("Unavailable: epoch_start_block_nonce")
721+
}
722+
723+
fn epoch_start_block_round(&mut self) -> Result<i64, VMHooksEarlyExit> {
724+
panic!("Unavailable: epoch_start_block_round")
725+
}
726+
703727
fn managed_get_return_data(
704728
&mut self,
705729
result_id: i32,
@@ -708,6 +732,13 @@ impl<C: VMHooksContext> VMHooks for VMHooksDispatcher<C> {
708732
panic!("Unavailable: managed_get_return_data");
709733
}
710734

735+
fn managed_get_all_transfers_call_value(
736+
&mut self,
737+
all_transfers_handle: i32,
738+
) -> Result<(), VMHooksEarlyExit> {
739+
self.handler.load_all_transfers(all_transfers_handle)
740+
}
741+
711742
fn managed_get_multi_esdt_call_value(
712743
&mut self,
713744
multi_call_value_handle: i32,
@@ -755,6 +786,16 @@ impl<C: VMHooksContext> VMHooks for VMHooksDispatcher<C> {
755786
)
756787
}
757788

789+
fn managed_get_esdt_token_type(
790+
&mut self,
791+
address_handle: i32,
792+
token_id_handle: i32,
793+
nonce: i64,
794+
type_handle: i32,
795+
) -> Result<(), VMHooksEarlyExit> {
796+
panic!("Unavailable: managed_get_esdt_token_type")
797+
}
798+
758799
fn managed_get_back_transfers(
759800
&mut self,
760801
esdt_transfer_value_handle: i32,
@@ -961,6 +1002,18 @@ impl<C: VMHooksContext> VMHooks for VMHooksDispatcher<C> {
9611002
Ok(RESULT_OK)
9621003
}
9631004

1005+
fn managed_execute_on_dest_context_with_error_return(
1006+
&mut self,
1007+
gas: i64,
1008+
address_handle: i32,
1009+
value_handle: i32,
1010+
function_handle: i32,
1011+
arguments_handle: i32,
1012+
result_handle: i32,
1013+
) -> Result<i32, VMHooksEarlyExit> {
1014+
panic!("Unavailable: managed_execute_on_dest_context_with_error_return")
1015+
}
1016+
9641017
fn managed_multi_transfer_esdt_nft_execute(
9651018
&mut self,
9661019
dst_handle: i32,
@@ -979,6 +1032,24 @@ impl<C: VMHooksContext> VMHooks for VMHooksDispatcher<C> {
9791032
Ok(RESULT_OK)
9801033
}
9811034

1035+
fn managed_multi_transfer_esdt_nft_execute_with_return(
1036+
&mut self,
1037+
dst_handle: i32,
1038+
token_transfers_handle: i32,
1039+
gas_limit: i64,
1040+
function_handle: i32,
1041+
arguments_handle: i32,
1042+
) -> Result<i32, VMHooksEarlyExit> {
1043+
self.handler
1044+
.managed_multi_transfer_esdt_nft_execute_with_return(
1045+
dst_handle,
1046+
token_transfers_handle,
1047+
gas_limit as u64,
1048+
function_handle,
1049+
arguments_handle,
1050+
)
1051+
}
1052+
9821053
fn managed_transfer_value_execute(
9831054
&mut self,
9841055
dst_handle: i32,
@@ -1038,6 +1109,14 @@ impl<C: VMHooksContext> VMHooks for VMHooksDispatcher<C> {
10381109
.managed_get_code_metadata(address_handle, response_handle)
10391110
}
10401111

1112+
fn managed_get_code_hash(
1113+
&mut self,
1114+
address_handle: i32,
1115+
code_hash_handle: i32,
1116+
) -> Result<(), VMHooksEarlyExit> {
1117+
panic!("Unavailable: managed_get_code_hash")
1118+
}
1119+
10411120
fn managed_is_builtin_function(
10421121
&mut self,
10431122
function_name_handle: i32,
@@ -1745,6 +1824,38 @@ impl<C: VMHooksContext> VMHooks for VMHooksDispatcher<C> {
17451824
}
17461825
}
17471826

1827+
fn mbuffer_to_small_int_unsigned(
1828+
&mut self,
1829+
m_buffer_handle: i32,
1830+
) -> Result<i64, VMHooksEarlyExit> {
1831+
self.handler.mb_to_small_int_unsigned(m_buffer_handle)
1832+
}
1833+
1834+
fn mbuffer_to_small_int_signed(
1835+
&mut self,
1836+
m_buffer_handle: i32,
1837+
) -> Result<i64, VMHooksEarlyExit> {
1838+
self.handler.mb_to_small_int_signed(m_buffer_handle)
1839+
}
1840+
1841+
fn mbuffer_from_small_int_unsigned(
1842+
&mut self,
1843+
m_buffer_handle: i32,
1844+
value: i64,
1845+
) -> Result<(), VMHooksEarlyExit> {
1846+
self.handler
1847+
.mb_from_small_int_unsigned(m_buffer_handle, value as u64)
1848+
}
1849+
1850+
fn mbuffer_from_small_int_signed(
1851+
&mut self,
1852+
m_buffer_handle: i32,
1853+
value: i64,
1854+
) -> Result<(), VMHooksEarlyExit> {
1855+
self.handler
1856+
.mb_from_small_int_signed(m_buffer_handle, value)
1857+
}
1858+
17481859
fn mbuffer_to_big_float(
17491860
&mut self,
17501861
m_buffer_handle: i32,

chain/vm/src/host/vm_hooks/vh_handler/vh_blockchain.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ impl<C: VMHooksContext> VMHooksHandler<C> {
137137
Ok(self.context.get_current_block_info().block_timestamp as i64)
138138
}
139139

140+
pub fn get_block_timestamp_ms(&mut self) -> Result<i64, VMHooksEarlyExit> {
141+
self.get_block_timestamp().map(|t| t * 1000)
142+
}
143+
140144
pub fn get_block_nonce(&mut self) -> Result<i64, VMHooksEarlyExit> {
141145
self.use_gas(self.gas_schedule().base_ops_api_cost.get_block_nonce)?;
142146

@@ -174,6 +178,10 @@ impl<C: VMHooksContext> VMHooksHandler<C> {
174178
Ok(self.context.get_previous_block_info().block_timestamp as i64)
175179
}
176180

181+
pub fn get_prev_block_timestamp_ms(&mut self) -> Result<i64, VMHooksEarlyExit> {
182+
self.get_prev_block_timestamp().map(|t| t * 1000)
183+
}
184+
177185
pub fn get_prev_block_nonce(&mut self) -> Result<i64, VMHooksEarlyExit> {
178186
self.use_gas(self.gas_schedule().base_ops_api_cost.get_block_nonce)?;
179187

chain/vm/src/host/vm_hooks/vh_handler/vh_call_value.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use crate::{
2-
host::vm_hooks::{vh_early_exit::early_exit_vm_error, VMHooksContext},
2+
host::{
3+
context::TxTokenTransfer,
4+
vm_hooks::{vh_early_exit::early_exit_vm_error, VMHooksContext},
5+
},
36
types::RawHandle,
47
vm_err_msg,
58
};
9+
use multiversx_chain_core::EGLD_000000_TOKEN_IDENTIFIER;
610
use multiversx_chain_vm_executor::VMHooksEarlyExit;
711
use num_traits::Zero;
812

@@ -43,6 +47,23 @@ impl<C: VMHooksContext> VMHooksHandler<C> {
4347
Ok(())
4448
}
4549

50+
pub fn load_all_transfers(&self, dest_handle: RawHandle) -> Result<(), VMHooksEarlyExit> {
51+
let direct_egld_value = self.context.input_ref().received_egld().clone();
52+
let transfers = if !direct_egld_value.is_zero() {
53+
vec![TxTokenTransfer {
54+
token_identifier: EGLD_000000_TOKEN_IDENTIFIER.as_bytes().to_vec(),
55+
nonce: 0,
56+
value: direct_egld_value,
57+
}]
58+
} else {
59+
self.context.input_ref().received_esdt().to_owned()
60+
};
61+
self.context
62+
.m_types_lock()
63+
.mb_set_vec_of_esdt_payments(dest_handle, &transfers);
64+
Ok(())
65+
}
66+
4667
pub fn esdt_num_transfers(&mut self) -> usize {
4768
self.context.input_ref().received_esdt().len()
4869
}

0 commit comments

Comments
 (0)