Skip to content

Commit

Permalink
Merge pull request #1022 from PhilippeR26/u512
Browse files Browse the repository at this point in the history
feat: handling of cairo u512 type
  • Loading branch information
tabaktoni authored Mar 22, 2024
2 parents c98fae4 + 218632b commit 6623ea5
Show file tree
Hide file tree
Showing 17 changed files with 3,567 additions and 10 deletions.
41 changes: 41 additions & 0 deletions __mocks__/cairo/cairo260/u512.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Cairo 2.6.0

use core::integer::u512;

#[starknet::interface]
trait IUint512<TContractState> {
fn get_u512(self: @TContractState) -> u512;
fn return_u512(self: @TContractState, my_u512: u512) -> u512;
fn div_u512(self: @TContractState, my_u512: u512, divisor: u256) -> (u512, u256);
}


#[starknet::contract]
mod TestUint512 {
use core::integer::{u512, u512_safe_div_rem_by_u256};

#[storage]
struct Storage {}

#[abi(embed_v0)]
impl Uint512 of super::IUint512<ContractState> {
fn get_u512(self: @ContractState) -> u512 {
u512 {
limb0: 0x00000000000000000000000000000000,
limb1: 0x11111111111111111111111111111111,
limb2: 0x22222222222222222222222222222222,
limb3: 0x33333333333333333333333333333333,
}
}

fn return_u512(self: @ContractState, my_u512: u512) -> u512 {
my_u512
}

fn div_u512(self: @ContractState, my_u512: u512, divisor: u256) -> (u512, u256) {
let (q, r) = u512_safe_div_rem_by_u256(my_u512, divisor.try_into().unwrap());
(q, r)
}
}
}

Loading

0 comments on commit 6623ea5

Please sign in to comment.