Skip to content

Verify that gas costs are always positive, or handle it correctly. #1407

@JulianGCalderon

Description

@JulianGCalderon

In the metadata::gas module, we are panicking if the function costs is negative, in multiple places, but the actual data type is a signed integer.

TryInto::<usize>::try_into(*val)

We should handle the case of a negative gas cost, either by returning a Native Assert in case its impossible, or handling it in case its possible.

See the Native Assert module definition on instructions on how and why to use it:

cairo_native/src/error.rs

Lines 133 to 138 in ac3e1a4

/// In Cairo Native we want to avoid the use of panic, even in situation where
/// it *should* never happen. The downside of this is that we lose:
/// - Possible compiler opitimizations
/// - Stack backtrace on error
///
/// This modules aims to avoid panics while still obtaining a stack backtrace on eventual errors.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

In Review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions