Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 50 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ smplx-std = "0.0.8"
anyhow = { version = "1.0.101" }
rand = { version = "0.8.6" }
primitive-types = { version = "0.14" }
num-bigint = { version = "0.5.1" }
num-traits = { version = "0.2.19" }
secp256k1-zkp = { version = "0.11.0", features = ["rand"] }
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This repository contains the standard library for [SimplicityHL](https://github.
> [!NOTE]
> The VS Code syntax-highlighting extension does not yet support modules and imports, so you may see spurious errors when editing files in this repo.

## Modules:
## Modules

- asserts
- logical_operations
Expand All @@ -15,6 +15,7 @@ This repository contains the standard library for [SimplicityHL](https://github.
- u32
- u64
- u128
- secp256k1

---
`Asserts`
Expand All @@ -35,38 +36,55 @@ Utilities for detecting and enforcing OP_RETURN (null data) outputs.
`u8`

Operations for the u8 type:

- overflow-checked arithmetic operations;
- comparison helpers.

---
`u16`

Operations for the u16 type:

- overflow-checked arithmetic operations;
- comparison helpers.

---
`u32`

Operations for the u32 type:

- overflow-checked arithmetic operations;
- comparison helpers.

---
`u64`

Operations for the u64 type:

- overflow-checked arithmetic operations;
- comparison helpers.

---
`u128`

Operations for the u128 type:

- overflow-checked arithmetic operations;
- comparison helpers;
- basic operations that are available as jets for `u8`-`u64` but are missing for `u128`.

---
`secp256k1`

Operations on the secp256k1 curve:

- subtraction for `Fe`, `Scalar`, `Gej`;
- equality predicates and their `assert_*` counterparts;
- conversions between `Ge`, `Gej`, and compressed `Point`;
- safe Jacobian-to-affine normalization.

`fe_eq` and `scalar_eq` use modular arithmetic, so `fe_eq(0, p) == true`. `ge_eq` and `gej_point_eq` distinguish `P` from `-P`.

## Installation

Install `simplexup`, then use it to install the pinned Simplex toolchain:
Expand Down Expand Up @@ -116,7 +134,7 @@ simplex test --test-threads 8
To run a specific test module:

```bash
simplex test u8_test
simplex test u8_tests
```

To run a specific test:
Expand Down
36 changes: 22 additions & 14 deletions simf/asserts_test.simf
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
use crate::lib::asserts::{assert_eq_8, assert_eq_16, assert_eq_32, assert_eq_64,assert_eq_128, assert_eq_256, assert_none_8, assert_none_16, assert_none_32, assert_none_64, assert_none_128, assert_none_256};
use crate::lib::asserts::{
assert_eq_1, assert_eq_8, assert_eq_16, assert_eq_32, assert_eq_64,assert_eq_128, assert_eq_256,
assert_none_1, assert_none_8, assert_none_16, assert_none_32, assert_none_64, assert_none_128, assert_none_256
};
use crate::helper::if_test_this_function;

fn main() {
let fn_idx: u8 = witness::FUNCTION_INDEX;

let a_u1: Option<u1> = witness::FIRST_ARG_U1;
let b_u1: Option<u1> = witness::SECOND_ARG_U1;

let a_u8: Option<u8> = witness::FIRST_ARG_U8;
let b_u8: Option<u8> = witness::SECOND_ARG_U8;

let a_u16: Option<u16> = witness::FIRST_ARG_U16;
let b_u16: Option<u16> = witness::SECOND_ARG_U16;

let a_u32: Option<u32> = witness::FIRST_ARG_U32;
let b_u32: Option<u32> = witness::SECOND_ARG_U32;

Expand All @@ -23,18 +29,20 @@ fn main() {
let b_u256: Option<u256> = witness::SECOND_ARG_U256;

// Assert Eq
match if_test_this_function(0, fn_idx) { true => { assert_eq_8(unwrap(a_u8), unwrap(b_u8)); }, false => (), };
match if_test_this_function(1, fn_idx) { true => { assert_eq_16(unwrap(a_u16), unwrap(b_u16)); }, false => (), };
match if_test_this_function(2, fn_idx) { true => { assert_eq_32(unwrap(a_u32), unwrap(b_u32)); }, false => (), };
match if_test_this_function(3, fn_idx) { true => { assert_eq_64(unwrap(a_u64), unwrap(b_u64)); }, false => (), };
match if_test_this_function(4, fn_idx) { true => { assert_eq_128(unwrap(a_u128), unwrap(b_u128)); }, false => (), };
match if_test_this_function(5, fn_idx) { true => { assert_eq_256(unwrap(a_u256), unwrap(b_u256)); }, false => (), };
match if_test_this_function(0, fn_idx) { true => { assert_eq_1(unwrap(a_u1), unwrap(b_u1)); }, false => (), };
match if_test_this_function(1, fn_idx) { true => { assert_eq_8(unwrap(a_u8), unwrap(b_u8)); }, false => (), };
match if_test_this_function(2, fn_idx) { true => { assert_eq_16(unwrap(a_u16), unwrap(b_u16)); }, false => (), };
match if_test_this_function(3, fn_idx) { true => { assert_eq_32(unwrap(a_u32), unwrap(b_u32)); }, false => (), };
match if_test_this_function(4, fn_idx) { true => { assert_eq_64(unwrap(a_u64), unwrap(b_u64)); }, false => (), };
match if_test_this_function(5, fn_idx) { true => { assert_eq_128(unwrap(a_u128), unwrap(b_u128)); }, false => (), };
match if_test_this_function(6, fn_idx) { true => { assert_eq_256(unwrap(a_u256), unwrap(b_u256)); }, false => (), };

// Assert None
match if_test_this_function(6, fn_idx) { true => { assert_none_8(a_u8); }, false => (), };
match if_test_this_function(7, fn_idx) { true => { assert_none_16(a_u16); }, false => (), };
match if_test_this_function(8, fn_idx) { true => { assert_none_32(a_u32); }, false => (), };
match if_test_this_function(9, fn_idx) { true => { assert_none_64(a_u64); }, false => (), };
match if_test_this_function(10, fn_idx) { true => { assert_none_128(a_u128); }, false => (), };
match if_test_this_function(11, fn_idx) { true => { assert_none_256(a_u256); }, false => (), };
match if_test_this_function(7, fn_idx) { true => { assert_none_1(a_u1); }, false => (), };
match if_test_this_function(8, fn_idx) { true => { assert_none_8(a_u8); }, false => (), };
match if_test_this_function(9, fn_idx) { true => { assert_none_16(a_u16); }, false => (), };
match if_test_this_function(10, fn_idx) { true => { assert_none_32(a_u32); }, false => (), };
match if_test_this_function(11, fn_idx) { true => { assert_none_64(a_u64); }, false => (), };
match if_test_this_function(12, fn_idx) { true => { assert_none_128(a_u128); }, false => (), };
match if_test_this_function(13, fn_idx) { true => { assert_none_256(a_u256); }, false => (), };
}
12 changes: 11 additions & 1 deletion simf/lib/asserts.simf
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use crate::lib::u128::{eq_128};
use crate::lib::u128::eq_128;

/// Asserts that two `u1` are equal
pub fn assert_eq_1(a: u1, b: u1) {
assert!(jet::eq_1(a, b))
}

/// Asserts that two u8 are equal
pub fn assert_eq_8(a: u8, b: u8) {
Expand Down Expand Up @@ -30,6 +35,11 @@ pub fn assert_eq_256(a: u256, b: u256) {
assert!(jet::eq_256(a, b));
}

/// Asserts that provided `Option<u1>` value is a `None`
pub fn assert_none_1(val: Option<u1>) {
assert!(is_none::<u1>(val));
}

/// Asserts that provided u8 Option value is a None
pub fn assert_none_8(val: Option<u8>) {
assert!(is_none::<u8>(val));
Expand Down
Loading