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

fix: check all features on each crate #1312

Merged
merged 6 commits into from Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 23 additions & 2 deletions .github/workflows/rust.yml
Expand Up @@ -121,6 +121,9 @@ jobs:

- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true

- name: Install cargo-all-features
uses: taiki-e/install-action@v2
with:
Expand Down Expand Up @@ -157,8 +160,26 @@ jobs:
cairo_programs/**/*.json
key: cairo_1_test_contracts-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}

- name: Check all features
run: cargo check-all-features --workspace --all-targets
# NOTE: we do this separately because --workspace operates in weird ways
- name: Check all features (felt)
run: |
cd felt
cargo check-all-features
cargo check-all-features --workspace --all-targets

- name: Check all features (vm)
run: |
cd vm
cargo check-all-features

- name: Check all features (CLI)
run: |
cd cairo-vm-cli
cargo check-all-features

- name: Check all features (workspace)
run: |
cargo check-all-features --workspace --all-targets
Oppen marked this conversation as resolved.
Show resolved Hide resolved

- name: Check no-std
run: |
Expand Down
4 changes: 2 additions & 2 deletions felt/src/lib_lambdaworks.rs
Expand Up @@ -955,13 +955,13 @@ impl FromPrimitive for Felt252 {

impl fmt::Display for Felt252 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_str_radix(10))
write!(f, "{}", self.to_biguint().to_str_radix(10))
}
}

impl fmt::Debug for Felt252 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.to_str_radix(10))
write!(f, "{}", self.to_biguint().to_str_radix(10))
}
}

Expand Down
12 changes: 6 additions & 6 deletions vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs
Expand Up @@ -23,11 +23,11 @@
operand::{CellRef, ResOperand},
};
use core::any::Any;
use core::ops::Shl;

use num_bigint::BigUint;
use num_integer::Integer;
use num_traits::{cast::ToPrimitive, Zero};
use std::ops::Shl;

/// Execution scope for constant memory allocation.
struct MemoryExecScope {
Expand Down Expand Up @@ -767,17 +767,17 @@
.map_err(HintError::from)
}

#[allow(unused_variables)]
fn debug_print(
&self,
vm: &mut VirtualMachine,
start: &ResOperand,
end: &ResOperand,
) -> Result<(), HintError> {
let mut curr = as_relocatable(vm, start)?;
let end = as_relocatable(vm, end)?;

#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "std")]
{
let mut curr = as_relocatable(vm, start)?;
let end = as_relocatable(vm, end)?;

Check warning on line 780 in vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs

View check run for this annotation

Codecov / codecov/patch

vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs#L779-L780

Added lines #L779 - L780 were not covered by tests
while curr != end {
let value = vm.get_integer(curr)?;
if let Some(shortstring) = as_cairo_short_string(&value) {
Expand Down Expand Up @@ -1066,7 +1066,7 @@
if let Some(root) = res.sqrt() {
let root0: BigUint = root.into_bigint().into();
let root1: BigUint = (-root).into_bigint().into();
let root = Felt252::from(std::cmp::min(root0, root1));
let root = Felt252::from(core::cmp::min(root0, root1));
vm.insert_value(cell_ref_to_relocatable(sqrt, vm)?, root)
.map_err(HintError::from)
} else {
Expand Down
Expand Up @@ -4,7 +4,7 @@ use crate::vm::errors::{hint_errors::HintError, vm_errors::VirtualMachineError};
use crate::vm::vm_core::VirtualMachine;
use cairo_lang_casm::operand::{CellRef, DerefOrImmediate, Operation, Register, ResOperand};
use felt::Felt252;
use num_traits::Zero;

/// Extracts a parameter assumed to be a buffer.
pub(crate) fn extract_buffer(buffer: &ResOperand) -> Result<(&CellRef, Felt252), HintError> {
let (cell, base_offset) = match buffer {
Expand Down Expand Up @@ -58,6 +58,7 @@ pub(crate) fn get_ptr(
Ok((vm.get_relocatable(cell_ref_to_relocatable(cell, vm)?)? + offset)?)
}

#[cfg(feature = "std")]
pub(crate) fn as_relocatable(
vm: &mut VirtualMachine,
value: &ResOperand,
Expand Down Expand Up @@ -97,10 +98,15 @@ pub(crate) fn res_operand_get_val(
}
}

#[cfg(feature = "std")]
pub(crate) fn as_cairo_short_string(value: &Felt252) -> Option<String> {
let mut as_string = String::default();
let mut is_end = false;
for byte in value.to_be_bytes().into_iter().skip_while(Zero::is_zero) {
for byte in value
.to_be_bytes()
.into_iter()
.skip_while(num_traits::Zero::is_zero)
{
if byte == 0 {
is_end = true;
} else if is_end || !byte.is_ascii() {
Expand Down