From c03d48645c385a588cef14d7eaf3723974827bb5 Mon Sep 17 00:00:00 2001 From: parazyd Date: Wed, 17 Jan 2024 15:46:29 +0100 Subject: [PATCH] runtime/import: Subtract gas fee in get_slot() --- src/runtime/import/util.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/runtime/import/util.rs b/src/runtime/import/util.rs index b803286c0..a525234ae 100644 --- a/src/runtime/import/util.rs +++ b/src/runtime/import/util.rs @@ -265,8 +265,8 @@ pub(crate) fn get_verifying_slot_epoch(ctx: FunctionEnvMut) -> u64 { /// /// On success, returns the index of the new object in the object store. /// Otherwise, returns an error code. -pub(crate) fn get_slot(ctx: FunctionEnvMut, slot: u64) -> i64 { - let env = ctx.data(); +pub(crate) fn get_slot(mut ctx: FunctionEnvMut, slot: u64) -> i64 { + let (env, mut store) = ctx.data_and_store_mut(); let cid = &env.contract_id; // Enforce function ACL @@ -292,6 +292,9 @@ pub(crate) fn get_slot(ctx: FunctionEnvMut, slot: u64) -> i64 { } }; + // Subtract used gas. Here we count the size of the object. + env.subtract_gas(&mut store, ret.len() as u64); + // Copy Vec to the VM let mut objects = env.objects.borrow_mut(); objects.push(ret.to_vec());