Skip to content

Commit

Permalink
Merge pull request #18 from lambdaclass/update_emu_gas
Browse files Browse the repository at this point in the history
update gas to u64, rust and deps
  • Loading branch information
edg-l authored Nov 11, 2024
2 parents 92591b5 + d9ba586 commit 783b577
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 150 deletions.
34 changes: 17 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ version = "0.1.0"
edition = "2021"

[dependencies]
cairo-lang-compiler = "2.8.2"
cairo-lang-filesystem = "2.8.2"
cairo-lang-sierra = "2.8.0"
cairo-lang-sierra-ap-change = "2.8.0"
cairo-lang-sierra-gas = "2.8.0"
cairo-lang-utils = "2.8.0"
clap = { version = "4.5.16", features = ["derive"] }
k256 = "0.13.3"
cairo-lang-compiler = "2.8.4"
cairo-lang-filesystem = "2.8.4"
cairo-lang-sierra = "2.8.4"
cairo-lang-sierra-ap-change = "2.8.4"
cairo-lang-sierra-gas = "2.8.4"
cairo-lang-utils = "2.8.4"
clap = { version = "4.5.20", features = ["derive"] }
k256 = "0.13.4"
keccak = "0.1.5"
num-bigint = "0.4.6"
num-traits = "0.2.19"
p256 = "0.13.2"
rand = "0.8.5"
sec1 = { version = "0.7.3", features = ["std"] }
serde = { version = "1.0.209", features = ["derive"] }
serde_json = "1.0.127"
serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.132"
sha2 = { version = "0.10.8", features = ["compress"] }
smallvec = "1.13.2"
starknet-crypto = "0.7.1"
starknet-curve = "0.5.0"
starknet-types-core = "0.1.2"
tempfile = "3.13.0"
thiserror = "1.0.63"
starknet-crypto = "0.7.3"
starknet-curve = "0.5.1"
starknet-types-core = "0.1.7"
tempfile = "3.14.0"
thiserror = "2.0.3"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

[dev-dependencies]
cairo-lang-compiler = "2.8.0"
cairo-lang-starknet = "2.8.0"
cairo-lang-compiler = "2.8.4"
cairo-lang-starknet = "2.8.4"

# On dev optimize dependencies a bit so it's not as slow.
[profile.dev.package."*"]
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.80.1"
channel = "1.82.0"
components = ["rustfmt", "clippy"]
profile = "minimal"
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct CmdArgs {

pub args: Vec<String>,
#[clap(long)]
pub available_gas: Option<u128>,
pub available_gas: Option<u64>,

#[clap(long, short)]
pub output: Option<PathBuf>,
Expand Down
4 changes: 2 additions & 2 deletions src/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Serialize for StateDump {

#[derive(Debug, Clone)]
pub struct ContractExecutionResult {
pub remaining_gas: u128,
pub remaining_gas: u64,
pub failure_flag: bool,
pub return_values: Vec<Felt>,
pub error_msg: Option<String>,
Expand All @@ -72,7 +72,7 @@ impl ContractExecutionResult {

for value in last.items.values() {
match value {
Value::U128(gas) => remaining_gas = Some(*gas),
Value::U64(gas) => remaining_gas = Some(*gas),
Value::Enum {
self_ty: _,
index,
Expand Down
16 changes: 8 additions & 8 deletions src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub enum GasMetadataError {
#[error(transparent)]
CostError(#[from] CostError),
#[error("Not enough gas to run the operation. Required: {:?}, Available: {:?}.", gas.0, gas.1)]
NotEnoughGas { gas: Box<(u128, u128)> },
NotEnoughGas { gas: Box<(u64, u64)> },
}

impl GasMetadata {
Expand All @@ -66,8 +66,8 @@ impl GasMetadata {
pub fn get_initial_available_gas(
&self,
func: &FunctionId,
available_gas: Option<u128>,
) -> Result<u128, GasMetadataError> {
available_gas: Option<u64>,
) -> Result<u64, GasMetadataError> {
let Some(available_gas) = available_gas else {
return Ok(0);
};
Expand All @@ -86,25 +86,25 @@ impl GasMetadata {
})
}

pub fn initial_required_gas(&self, func: &FunctionId) -> Option<u128> {
pub fn initial_required_gas(&self, func: &FunctionId) -> Option<u64> {
if self.gas_info.function_costs.is_empty() {
return None;
}
Some(
self.gas_info.function_costs[func]
.iter()
.map(|(token_type, val)| val.into_or_panic::<usize>() * token_gas_cost(*token_type))
.sum::<usize>() as u128,
.sum::<usize>() as u64,
)
}

pub fn get_gas_cost_for_statement(&self, idx: StatementIdx) -> Option<u128> {
pub fn get_gas_cost_for_statement(&self, idx: StatementIdx) -> Option<u64> {
let mut cost = None;
for cost_type in CostTokenType::iter_casm_tokens() {
if let Some(amount) =
self.get_gas_cost_for_statement_and_cost_token_type(idx, *cost_type)
{
*cost.get_or_insert(0) += amount * token_gas_cost(*cost_type) as u128;
*cost.get_or_insert(0) += amount * token_gas_cost(*cost_type) as u64;
}
}
cost
Expand All @@ -114,7 +114,7 @@ impl GasMetadata {
&self,
idx: StatementIdx,
cost_type: CostTokenType,
) -> Option<u128> {
) -> Option<u64> {
self.gas_info
.variable_values
.get(&(idx, cost_type))
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let type_info = vm.registry().get_type(type_id).unwrap();
match type_info {
CoreTypeConcrete::Felt252(_) => Value::parse_felt(&iter.next().unwrap()),
CoreTypeConcrete::GasBuiltin(_) => Value::U128(args.available_gas.unwrap()),
CoreTypeConcrete::GasBuiltin(_) => Value::U64(args.available_gas.unwrap()),
CoreTypeConcrete::RangeCheck(_)
| CoreTypeConcrete::RangeCheck96(_)
| CoreTypeConcrete::Bitwise(_)
Expand Down
Loading

0 comments on commit 783b577

Please sign in to comment.