Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ concurrency:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
SIMPLEX_VERSION: 0.0.11

jobs:
simplex-tests:
Expand All @@ -40,20 +41,29 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.toolchain }}
components: rustfmt, clippy

- name: Use Rust cache
uses: Swatinem/rust-cache@v2

- name: Install simplex-cli
uses: BlockstreamResearch/simplicityhl-toolchain@v0.0.2
with:
components: simplex
components: simplex@${{ env.SIMPLEX_VERSION }}

- name: Generate contract artifacts
shell: bash
run: |
simplex build

- name: Check formatting
run: |
cargo fmt --all --check

- name: Run clippy
run: |
cargo clippy --workspace --all-targets --all-features -- -D warnings

- name: Build
run: |
cargo build --workspace --all-features --verbose
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ When submitting a feature request, please provide as many details as possible fo

## Pull Requests

If you're interested in contributing code to the library, start by [forking the repository](https://github.com/BlockstreamResearch/simplicityhl-std/fork) and submitting a pull request.
If you're interested in contributing code to the library, start by [forking the repository](https://github.com/BlockstreamResearch/simplicityhl-std/fork) and submitting a pull request.

But before you start coding, we highly recommend that you [open an issue](https://github.com/BlockstreamResearch/simplicityhl-std/issues/new/choose) first to discuss the changes you want to make.

Expand Down
62 changes: 0 additions & 62 deletions simf/asserts_test.simf

This file was deleted.

21 changes: 0 additions & 21 deletions simf/binary_test.simf

This file was deleted.

13 changes: 0 additions & 13 deletions simf/helper.simf

This file was deleted.

8 changes: 4 additions & 4 deletions simf/lib/binary.simf
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/// Returns the result of the NOT operation on the provided value
pub fn not(bit: bool) -> bool {
<u1>::into(jet::complement_1(<bool>::into(bit)))
<u1>::into(jet::complement_1(<bool>::into(bit)))
}

/// Returns the result of the OR operation on the provided values
pub fn or(a: bool, b: bool) -> bool {
<u1>::into(jet::or_1(<bool>::into(a), <bool>::into(b)))
<u1>::into(jet::or_1(<bool>::into(a), <bool>::into(b)))
}

/// Returns the result of the AND operation on the provided values
pub fn and(a: bool, b: bool) -> bool {
<u1>::into(jet::and_1(<bool>::into(a), <bool>::into(b)))
<u1>::into(jet::and_1(<bool>::into(a), <bool>::into(b)))
}

/// Returns the result of the XOR operation on the provided values
pub fn xor(a: bool, b: bool) -> bool {
and(or(a, b), not(and(a, b)))
and(or(a, b), not(and(a, b)))
}
2 changes: 1 addition & 1 deletion simf/lib/op_return.simf
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pub fn is_output_op_return(output_index: u32) -> bool {

/// Asserts that the specified output is an OP_RETURN (null data) output
pub fn assert_output_is_op_return(output_index: u32) {
assert!(is_output_op_return(output_index));
assert!(is_output_op_return(output_index));
}
2 changes: 1 addition & 1 deletion simf/lib/secp256k1/operations.simf
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn assert_scalar_eq(a: Scalar, b: Scalar) {
pub fn assert_ge_eq(a: Ge, b: Ge) {
let (ax, ay): (Fe, Fe) = a;
let (bx, by): (Fe, Fe) = b;

assert_fe_eq(ax, bx);
assert_fe_eq(ay, by);
}
Expand Down
18 changes: 12 additions & 6 deletions simf/lib/u128/bit.simf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ pub fn left_shift_128(shift: u8, a: u128) -> u128 {

match jet::lt_8(shift, 64) {
true => {
let (_, low_to_high_amount): (bool, u8) = jet::subtract_8(64, shift); // shift < 64
let (
_,
low_to_high_amount
): (bool, u8) = jet::subtract_8(64, shift); // shift < 64
let shifted_bits: u64 = jet::right_shift_64(low_to_high_amount, a_low);

let res_high: u64 = jet::or_64(jet::left_shift_64(shift, a_high), shifted_bits);
Expand All @@ -46,9 +49,9 @@ pub fn left_shift_128(shift: u8, a: u128) -> u128 {
let (_, shift): (bool, u8) = jet::subtract_8(shift, 64); // shift >= 64

<(u64, u64)>::into((jet::left_shift_64(shift, a_low), 0))
}
},
}
}
},
}
}

Expand All @@ -61,7 +64,10 @@ pub fn right_shift_128(shift: u8, a: u128) -> u128 {

match jet::lt_8(shift, 64) {
true => {
let (_, high_to_low_amount): (bool, u8) = jet::subtract_8(64, shift); // shift < 64
let (
_,
high_to_low_amount
): (bool, u8) = jet::subtract_8(64, shift); // shift < 64
let shifted_bits: u64 = jet::left_shift_64(high_to_low_amount, a_high);

let res_low: u64 = jet::or_64(jet::right_shift_64(shift, a_low), shifted_bits);
Expand All @@ -72,8 +78,8 @@ pub fn right_shift_128(shift: u8, a: u128) -> u128 {
let (_, shift): (bool, u8) = jet::subtract_8(shift, 64); // shift >= 64

<(u64, u64)>::into((0, jet::right_shift_64(shift, a_high)))
}
},
}
}
},
}
}
19 changes: 11 additions & 8 deletions simf/lib/u128/math.simf
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,12 @@ pub fn calculate_normalizer_base_64(b: u128, is_b_u128: bool) -> u64 {
match jet::is_zero_64(remainder) {
true => norm,
false => {
let (_, norm): (bool, u64) = jet::add_64(norm, 1); // norm <= 2^63, so norm + 1 can not overflow
let (
_,
norm
): (bool, u64) = jet::add_64(norm, 1); // norm <= 2^63, so norm + 1 can not overflow
norm
}
},
}
}

Expand All @@ -221,7 +224,11 @@ fn normalize_to_threshold_128_63(a: u128, b: u128, is_b_u128: bool) -> (u256, u1
/// Returns the quotient digit to use in the subsequent multiply-and-subtract step.
/// Expects result to fit into u64
pub fn estimate_quotient_digit_base_64(u2: u64, u1: u64, u0: u64, v1: u64, v0: u64) -> u64 {
let (q_hat, r_hat, carry): (u64, u64, bool) = match jet::lt_64(u2, v1) {
let (
q_hat,
r_hat,
carry
): (u64, u64, bool) = match jet::lt_64(u2, v1) {
true => {
let (q_hat, r_hat): (u64, u64) = jet::div_mod_128_64(<(u64, u64)>::into((u2, u1)), v1);
(q_hat, r_hat, false)
Expand Down Expand Up @@ -309,11 +316,7 @@ pub fn div_mod_128_64(a: u128, b: u64) -> (u128, u64) {
a_normalized,
b_normalized,
norm
): (u256, u128, u64) = normalize_to_threshold_128_63(
a_prime,
u64_to_u128(b),
false
);
): (u256, u128, u64) = normalize_to_threshold_128_63(a_prime, u64_to_u128(b), false);

// a_normalized fits into u128, because remainder < b and b_normalized fits into u64
let (_, a_normalized): (u128, u128) = <u256>::into(a_normalized);
Expand Down
2 changes: 1 addition & 1 deletion simf/lib/u16/math.simf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn safe_add_16(a: u16, b: u16) -> u16 {
/// Returns the difference of two u16 values wrapped in Some, or None if the result overflows u16
pub fn checked_sub_16(a: u16, b: u16) -> Option<u16> {
let (borrow, diff): (bool, u16) = jet::subtract_16(a, b);

match borrow {
true => None,
false => Some(diff),
Expand Down
18 changes: 12 additions & 6 deletions simf/lib/u256/bit.simf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ pub fn left_shift_256(shift: u8, a: u256) -> u256 {

match jet::lt_8(shift, 128) {
true => {
let (_, low_to_high_amount): (bool, u8) = jet::subtract_8(128, shift); // shift < 128
let (
_,
low_to_high_amount
): (bool, u8) = jet::subtract_8(128, shift); // shift < 128
let shifted_bits: u128 = right_shift_128(low_to_high_amount, a_low);

let res_high: u128 = or_128(left_shift_128(shift, a_high), shifted_bits);
Expand All @@ -38,9 +41,9 @@ pub fn left_shift_256(shift: u8, a: u256) -> u256 {
let (_, shift): (bool, u8) = jet::subtract_8(shift, 128); // shift >= 128

<(u128, u128)>::into((left_shift_128(shift, a_low), 0))
}
},
}
}
},
}
}

Expand All @@ -53,7 +56,10 @@ pub fn right_shift_256(shift: u8, a: u256) -> u256 {

match jet::lt_8(shift, 128) {
true => {
let (_, high_to_low_amount): (bool, u8) = jet::subtract_8(128, shift); // shift < 128
let (
_,
high_to_low_amount
): (bool, u8) = jet::subtract_8(128, shift); // shift < 128
let shifted_bits: u128 = left_shift_128(high_to_low_amount, a_high);

let res_low: u128 = or_128(right_shift_128(shift, a_low), shifted_bits);
Expand All @@ -64,8 +70,8 @@ pub fn right_shift_256(shift: u8, a: u256) -> u256 {
let (_, shift): (bool, u8) = jet::subtract_8(shift, 128); // shift >= 128

<(u128, u128)>::into((0, right_shift_128(shift, a_high)))
}
},
}
}
},
}
}
8 changes: 7 additions & 1 deletion simf/lib/u256/math.simf
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,13 @@ pub fn calculate_normalizer_base_128(b: u256) -> u128 {
match is_zero_128(remainder) {
true => norm,
false => {
let (_, norm): (bool, u128) = add_128(norm, 1); // norm <= 2^127, so norm + 1 can not overflow
let (
_,
norm
): (bool, u128) = add_128(
norm,
1
); // norm <= 2^127, so norm + 1 can not overflow
norm
},
}
Expand Down
Loading