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

Remove gas accounting from AotContractExecutor #938

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 9 additions & 20 deletions src/executor/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ impl AotContractExecutor {
/// - selector: The selector of the entry point to run.
/// - args: The calldata.
/// - gas: The gas for the execution.
/// - initial_gas_cost: is the gas cost for the called entry point, usually 10k ( `INITIAL_GAS_COST` ).
/// - builtin_costs: An optional argument to customize the costs of the builtins.
/// - syscall_handler: The syscall handler implementation to use when executing the contract.
///
/// This method doesn't do any gas accounting, meaning it wont substract the initial gas cost of the entry point from the given gas.
edg-l marked this conversation as resolved.
Show resolved Hide resolved
pub fn run(
&self,
selector: Felt,
args: &[Felt],
gas: Option<u64>,
initial_gas_cost: u64,
gas: u64,
builtin_costs: Option<BuiltinCosts>,
mut syscall_handler: impl StarknetSyscallHandler,
) -> Result<ContractExecutionResult, Error> {
Expand Down Expand Up @@ -316,13 +316,6 @@ impl AotContractExecutor {
// We may be inside a recursive contract, save the possible saved builtin costs to restore it after our call.
let old_builtincosts_ptr = set_costs_builtin(builtin_costs.cast());

let gas = gas.unwrap_or(initial_gas_cost);
let gas = gas.checked_sub(initial_gas_cost).ok_or_else(|| {
Error::GasMetadataError(crate::metadata::gas::GasMetadataError::NotEnoughGas {
gas: Box::new((gas, initial_gas_cost)),
})
})?;

// it can vary from contract to contract thats why we need to store/ load it.
let builtins_size: usize = self.contract_info.entry_points_info[&function_id.id]
.builtins
Expand Down Expand Up @@ -705,15 +698,14 @@ mod tests {
.run(
Felt::from(&selector),
&[n.into()],
Some(u64::MAX),
INITIAL_GAS_COST,
u64::MAX,
None,
&mut StubSyscallHandler::default(),
)
.unwrap();

assert_eq!(result.return_values, vec![Felt::from(n), Felt::from(n * 2)]);
assert_eq!(result.remaining_gas, 18446744073709539845);
assert_eq!(result.remaining_gas, 18446744073709549845);
});
}

Expand Down Expand Up @@ -741,8 +733,7 @@ mod tests {
.run(
Felt::from(&selector),
&[2.into()],
Some(u64::MAX),
INITIAL_GAS_COST,
u64::MAX,
None,
&mut StubSyscallHandler::default(),
)
Expand Down Expand Up @@ -777,15 +768,14 @@ mod tests {
.run(
Felt::from(&selector),
&[10.into()],
Some(u64::MAX),
INITIAL_GAS_COST,
u64::MAX,
None,
&mut StubSyscallHandler::default(),
)
.unwrap();

assert_eq!(result.return_values, vec![Felt::from(3628800)]);
assert_eq!(result.remaining_gas, 18446744073709525475);
assert_eq!(result.remaining_gas, 18446744073709535475);
}

#[rstest]
Expand Down Expand Up @@ -816,8 +806,7 @@ mod tests {
.run(
Felt::from(&selector),
&[],
Some(u64::MAX),
INITIAL_GAS_COST,
u64::MAX,
None,
&mut StubSyscallHandler::default(),
)
Expand Down
3 changes: 1 addition & 2 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ pub fn run_native_starknet_aot_contract(
.run(
Felt::from(selector),
args,
u64::MAX.into(),
INITIAL_GAS_COST,
u64::MAX,
None,
handler,
)
Expand Down
Loading