Skip to content

Commit

Permalink
piecrust: implemented double economic mode buffer scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed May 7, 2024
1 parent 3d97533 commit 4272f58
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions piecrust/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use dusk_wasmtime::{
Caller, Extern, Func, Module, Result as WasmtimeResult, Store,
};
use piecrust_uplink::{
ContractError, ContractId, ARGBUF_LEN, CONTRACT_ID_BYTES, ECO_MODE_LEN,
ContractError, ContractId, ARGBUF_LEN, CONTRACT_ID_BYTES, ECO_MODE_BUF_LEN,
ECO_MODE_LEN,
};

use crate::instance::{Env, WrappedInstance};
Expand Down Expand Up @@ -249,20 +250,17 @@ pub(crate) fn c(
let arg = &arg_buf[..arg_len as usize];

callee.write_argument(arg);
callee.clear_eco_mode();
let ret_len = callee
.call(name, arg.len() as u32, callee_limit)
.map_err(Error::normalize)?;
check_arg(callee, ret_len as u32)?;

// copy back result
callee.read_argument(&mut memory[argbuf_ofs..][..ret_len as usize]);
callee.read_eco_mode_buf(&mut memory[eco_mode_ofs..][..ECO_MODE_LEN]);
// if depth of the stack is 3 or more, economic mode is not read
const ECO_STACK_DEPTH: usize = 2;
if env.nth_from_top(ECO_STACK_DEPTH).is_some() {
callee.clear_eco_mode();
}
callee.read_eco_mode_buf(
&mut memory[eco_mode_ofs..][ECO_MODE_LEN..ECO_MODE_BUF_LEN],
);
callee.clear_eco_mode();

let callee_remaining = callee.get_remaining_gas();
let callee_spent = callee_limit - callee_remaining;
Expand Down

0 comments on commit 4272f58

Please sign in to comment.