Skip to content

Commit

Permalink
Make gas type be u128 (#319)
Browse files Browse the repository at this point in the history
* free ci space to avoid errors

* dont free on macos

* needs sudo

* needs sudo

* make gas u128

* fix bench

* modern way

* remove comment
  • Loading branch information
edg-l authored Oct 17, 2023
1 parent 273ce25 commit db1c3f6
Show file tree
Hide file tree
Showing 20 changed files with 197 additions and 185 deletions.
46 changes: 25 additions & 21 deletions examples/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ impl StarkNetSyscallHandler for SyscallHandler {
fn get_block_hash(
&mut self,
block_number: u64,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<cairo_felt::Felt252> {
println!("Called `get_block_hash({block_number})` from MLIR.");
Ok(Felt252::from_bytes_be(b"get_block_hash ok"))
}

fn get_execution_info(
&self,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<cairo_native::starknet::ExecutionInfo> {
println!("Called `get_execution_info()` from MLIR.");
Ok(ExecutionInfo {
Expand Down Expand Up @@ -58,7 +58,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
contract_address_salt: cairo_felt::Felt252,
calldata: &[cairo_felt::Felt252],
deploy_from_zero: bool,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<(cairo_felt::Felt252, Vec<cairo_felt::Felt252>)> {
println!("Called `deploy({class_hash}, {contract_address_salt}, {calldata:?}, {deploy_from_zero})` from MLIR.");
Ok((
Expand All @@ -70,7 +70,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
fn replace_class(
&mut self,
class_hash: cairo_felt::Felt252,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<()> {
println!("Called `replace_class({class_hash})` from MLIR.");
Ok(())
Expand All @@ -81,7 +81,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
class_hash: cairo_felt::Felt252,
function_selector: cairo_felt::Felt252,
calldata: &[cairo_felt::Felt252],
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Vec<cairo_felt::Felt252>> {
println!(
"Called `library_call({class_hash}, {function_selector}, {calldata:?})` from MLIR."
Expand All @@ -94,7 +94,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
address: cairo_felt::Felt252,
entry_point_selector: cairo_felt::Felt252,
calldata: &[cairo_felt::Felt252],
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Vec<cairo_felt::Felt252>> {
println!(
"Called `call_contract({address}, {entry_point_selector}, {calldata:?})` from MLIR."
Expand All @@ -106,7 +106,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&mut self,
address_domain: u32,
address: cairo_felt::Felt252,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<cairo_felt::Felt252> {
println!("Called `storage_read({address_domain}, {address})` from MLIR.");
Ok(address * &Felt252::new(3))
Expand All @@ -117,7 +117,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
address_domain: u32,
address: cairo_felt::Felt252,
value: cairo_felt::Felt252,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<()> {
println!("Called `storage_write({address_domain}, {address}, {value})` from MLIR.");
Ok(())
Expand All @@ -127,7 +127,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&mut self,
keys: &[cairo_felt::Felt252],
data: &[cairo_felt::Felt252],
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<()> {
println!("Called `emit_event({keys:?}, {data:?})` from MLIR.");
Ok(())
Expand All @@ -137,13 +137,17 @@ impl StarkNetSyscallHandler for SyscallHandler {
&mut self,
to_address: cairo_felt::Felt252,
payload: &[cairo_felt::Felt252],
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<()> {
println!("Called `send_message_to_l1({to_address}, {payload:?})` from MLIR.");
Ok(())
}

fn keccak(&self, input: &[u64], _gas: &mut u64) -> SyscallResult<cairo_native::starknet::U256> {
fn keccak(
&self,
input: &[u64],
_gas: &mut u128,
) -> SyscallResult<cairo_native::starknet::U256> {
println!("Called `keccak({input:?})` from MLIR.");
Ok(U256(Felt252::from(1234567890).to_le_bytes()))
}
Expand All @@ -152,7 +156,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&mut self,
_p0: cairo_native::starknet::Secp256k1Point,
_p1: cairo_native::starknet::Secp256k1Point,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand All @@ -161,15 +165,15 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_x: cairo_native::starknet::U256,
_y_parity: bool,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}

fn secp256k1_get_xy(
&self,
_p: cairo_native::starknet::Secp256k1Point,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<(cairo_native::starknet::U256, cairo_native::starknet::U256)> {
todo!()
}
Expand All @@ -178,7 +182,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_p: cairo_native::starknet::Secp256k1Point,
_m: cairo_native::starknet::U256,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand All @@ -187,7 +191,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_x: cairo_native::starknet::U256,
_y: cairo_native::starknet::U256,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand All @@ -196,7 +200,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_p0: cairo_native::starknet::Secp256k1Point,
_p1: cairo_native::starknet::Secp256k1Point,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand All @@ -205,15 +209,15 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_x: cairo_native::starknet::U256,
_y_parity: bool,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}

fn secp256r1_get_xy(
&self,
_p: cairo_native::starknet::Secp256k1Point,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<(cairo_native::starknet::U256, cairo_native::starknet::U256)> {
todo!()
}
Expand All @@ -222,7 +226,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_p: cairo_native::starknet::Secp256k1Point,
_m: cairo_native::starknet::U256,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand All @@ -231,7 +235,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&mut self,
_x: cairo_native::starknet::U256,
_y: cairo_native::starknet::U256,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand Down
46 changes: 25 additions & 21 deletions examples/starknet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ impl StarkNetSyscallHandler for SyscallHandler {
fn get_block_hash(
&mut self,
block_number: u64,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<cairo_felt::Felt252> {
println!("Called `get_block_hash({block_number})` from MLIR.");
Ok(Felt252::from_bytes_be(b"get_block_hash ok"))
}

fn get_execution_info(
&self,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<cairo_native::starknet::ExecutionInfo> {
println!("Called `get_execution_info()` from MLIR.");
Ok(ExecutionInfo {
Expand Down Expand Up @@ -58,7 +58,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
contract_address_salt: cairo_felt::Felt252,
calldata: &[cairo_felt::Felt252],
deploy_from_zero: bool,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<(cairo_felt::Felt252, Vec<cairo_felt::Felt252>)> {
println!("Called `deploy({class_hash}, {contract_address_salt}, {calldata:?}, {deploy_from_zero})` from MLIR.");
Ok((
Expand All @@ -70,7 +70,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
fn replace_class(
&mut self,
class_hash: cairo_felt::Felt252,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<()> {
println!("Called `replace_class({class_hash})` from MLIR.");
Ok(())
Expand All @@ -81,7 +81,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
class_hash: cairo_felt::Felt252,
function_selector: cairo_felt::Felt252,
calldata: &[cairo_felt::Felt252],
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Vec<cairo_felt::Felt252>> {
println!(
"Called `library_call({class_hash}, {function_selector}, {calldata:?})` from MLIR."
Expand All @@ -94,7 +94,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
address: cairo_felt::Felt252,
entry_point_selector: cairo_felt::Felt252,
calldata: &[cairo_felt::Felt252],
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Vec<cairo_felt::Felt252>> {
println!(
"Called `call_contract({address}, {entry_point_selector}, {calldata:?})` from MLIR."
Expand All @@ -106,7 +106,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&mut self,
address_domain: u32,
address: cairo_felt::Felt252,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<cairo_felt::Felt252> {
println!("Called `storage_read({address_domain}, {address})` from MLIR.");
Ok(address * &Felt252::new(3))
Expand All @@ -117,7 +117,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
address_domain: u32,
address: cairo_felt::Felt252,
value: cairo_felt::Felt252,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<()> {
println!("Called `storage_write({address_domain}, {address}, {value})` from MLIR.");
Ok(())
Expand All @@ -127,7 +127,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&mut self,
keys: &[cairo_felt::Felt252],
data: &[cairo_felt::Felt252],
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<()> {
println!("Called `emit_event({keys:?}, {data:?})` from MLIR.");
Ok(())
Expand All @@ -137,13 +137,17 @@ impl StarkNetSyscallHandler for SyscallHandler {
&mut self,
to_address: cairo_felt::Felt252,
payload: &[cairo_felt::Felt252],
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<()> {
println!("Called `send_message_to_l1({to_address}, {payload:?})` from MLIR.");
Ok(())
}

fn keccak(&self, input: &[u64], _gas: &mut u64) -> SyscallResult<cairo_native::starknet::U256> {
fn keccak(
&self,
input: &[u64],
_gas: &mut u128,
) -> SyscallResult<cairo_native::starknet::U256> {
println!("Called `keccak({input:?})` from MLIR.");
Ok(U256(Felt252::from(1234567890).to_le_bytes()))
}
Expand All @@ -152,7 +156,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&mut self,
_p0: cairo_native::starknet::Secp256k1Point,
_p1: cairo_native::starknet::Secp256k1Point,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand All @@ -161,15 +165,15 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_x: cairo_native::starknet::U256,
_y_parity: bool,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}

fn secp256k1_get_xy(
&self,
_p: cairo_native::starknet::Secp256k1Point,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<(cairo_native::starknet::U256, cairo_native::starknet::U256)> {
todo!()
}
Expand All @@ -178,7 +182,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_p: cairo_native::starknet::Secp256k1Point,
_m: cairo_native::starknet::U256,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand All @@ -187,7 +191,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_x: cairo_native::starknet::U256,
_y: cairo_native::starknet::U256,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand All @@ -196,7 +200,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_p0: cairo_native::starknet::Secp256k1Point,
_p1: cairo_native::starknet::Secp256k1Point,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand All @@ -205,15 +209,15 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_x: cairo_native::starknet::U256,
_y_parity: bool,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}

fn secp256r1_get_xy(
&self,
_p: cairo_native::starknet::Secp256k1Point,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<(cairo_native::starknet::U256, cairo_native::starknet::U256)> {
todo!()
}
Expand All @@ -222,7 +226,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&self,
_p: cairo_native::starknet::Secp256k1Point,
_m: cairo_native::starknet::U256,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand All @@ -231,7 +235,7 @@ impl StarkNetSyscallHandler for SyscallHandler {
&mut self,
_x: cairo_native::starknet::U256,
_y: cairo_native::starknet::U256,
_gas: &mut u64,
_gas: &mut u128,
) -> SyscallResult<Option<cairo_native::starknet::Secp256k1Point>> {
todo!()
}
Expand Down
2 changes: 1 addition & 1 deletion programs/benches/factorial.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

typedef struct factorial_return_values
{
uint64_t remaining_gas;
unsigned __int128 remaining_gas;
struct {
uint8_t discriminant;
union {
Expand Down
2 changes: 1 addition & 1 deletion programs/benches/factorial_100.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

typedef struct factorial_return_values
{
uint64_t remaining_gas;
unsigned __int128 remaining_gas;
struct {
uint8_t discriminant;
union {
Expand Down
Loading

0 comments on commit db1c3f6

Please sign in to comment.