Skip to content

Release v1.0.0-alpha.2

Compare
Choose a tag to compare
@spapinistarkware spapinistarkware released this 26 Jan 10:06
· 3655 commits to main since this release

Release notes

Cairo Language

  • Support for type inference. For example:
    Instead of:
    let arr = ArrayTrait::<felt>::new();
    arr.append(1);
    
    You can now also use:
    let arr = ArrayTrait::new();
    arr.append(1);
    
  • Support for global constants: const CONSTANT: felt = 1;
  • Support for serialization:
    let mut data = ArrayTrait::new();
    serde::Serde::serialize(ref data, value);
    
  • Syntax change - requiring ref keyword on callsite. For example:
    Instead of
    array_append(arr, 1);
    
    Use:
    array_append(ref arr, 1);
    
  • Support for dictionaries from felt to {u128, felt, u8, u64, Nullable::<T>}.
    let mut d = DictFeltToTrait::new();
    d.insert(1, 1); // Write.
    d.get(1); // Read.
    d.squash(); // Destroy the dictionary.
    
  • Function inlining - support only for very simple functions. For example:
    #[inline(always)]
    fn foo(arg: felt) -> felt { … }
    
  • Basic print capabilities.
    debug::print_felt(‘some debug short string’);
    
  • Trait support. For example:
    trait SomeTrait<T> {
        fn some_func(a: T);
    }
    impl SomeTypeSomeTrait of SomeTrait::<SomeType> {
        fn some_func(a:  SomeType) { …implementation… }
    }
    
    // This line would now work in code that sees both `SomeTrait` and `SomeTypeSomeTrait`.
    SomeTrait::some_func(SomeType { … initialization … });
    
  • Self and methods support. For example:
    struct MyStruct { … members … }
    trait MyTrait {
        fn calc(self: MyStruct, a: felt) -> u128;
    }
    impl MyImpl of MyTrait {
        fn calc(self: MyStruct, a: felt) -> u128 { … implementation … }
    }
    
    // This line would now work in code that sees both `MyTrait` and `MyImpl`.
    let value =  MyStruct { … initialization ... }.calc(5);
    
  • Generic user code support. For example:
    fn pair_swap<T, S>(p: (T, S)) -> (S, T) {
       let (t, s) = p;
       (s, t) 
    }
    
  • Added ec library support
    • ec::{ec_state_init, ec_state_add, ec_state_finalize, ec_state_add_mul}
    • ec::{EcPoint, ec_point_new, ec_point_from_x, ec_point_unwrap, ec_neg}
    • Core Library extended:
    • Option::{is_some, is_none, unwrap, expect}
    • Result::{is_ok, is_err, unwrap, expect, unwrap_err, expect_err}
    • Array::{new, at, get, len, append, pop_front}
    • DictFeltTo::{new, insert, get, squash}

StarkNet contract features

  • Mapping storage variables. For example:
    #[contract]
    mod contract {
      struct Storage {
        mapping: Map::<key_type, value_type>,
      }
      …
    }
    
  • Wider storage variables support. For example:
    #[contract]
    mod contract {
      struct Storage {
        mapping: Map::<u256, u256>,
      }
      …
    }
    
  • Events. For example:
    #[contract]
    mod contract {
      …
      #[event]
      fn SomeEvent(value1: felt, value2: bool, value3: u256) {}
    }
    

Bug fixes

  • Borrow checking is now handled correctly.
  • Multiple panics were removed.
  • Crate can be used as a dependency - by explicitly specifying corelib location.