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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
jobs:
simplex-tests:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 60
permissions:
contents: read
strategy:
Expand Down
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Changelog

## [0.0.1]

The initial release!
- Сhecked arithmetic operations for `u8`, `u16`, `u32`, `u64`, and `u128`;
- `OP_RETURN` detection utilities.
- Implementation of `and`, `or`, `not`, and `xor` binary operators.
- Basic numeric assertions.
- Equality and conversion operators for `secp256k1` points.

## [Unreleased]

- Added `mul_div` functions.
- Organized code into modules.
- Refactored test structure.
- Removed `safe_` prefixes from math functions, so the default versions are overflow-checked.
- Added functions for retrieving and asserting `AssetId` and `Amount`.

## [0.0.1]

Initial release!
- Сhecked arithmetic operations for `u8`, `u16`, `u32`, `u64`, and `u128`.
- `OP_RETURN` detection utilities.
- Implementation of `and`, `or`, `not`, and `xor` binary operators.
- Basic numeric assertions.
- Equality and conversion operators for `secp256k1` points.
170 changes: 169 additions & 1 deletion docs/stdlib.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,174 @@
"output_type": "()",
"description": "Assert that two `bool` values are equal.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_amount",
"section": "Amount asserts",
"input_type": "u32, bool, u64",
"output_type": "()",
"description": "Asserts that the explicit amount at the specified input or output index equals the expected u64 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_amount",
"section": "Amount asserts",
"input_type": "u32, bool, Confidential1",
"output_type": "()",
"description": "Asserts that the confidential amount at the specified input or output index equals the expected Confidential1 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_input_amount",
"section": "Amount asserts",
"input_type": "u32, u64",
"output_type": "()",
"description": "Asserts that the explicit amount at the specified input index equals the expected u64 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_input_amount",
"section": "Amount asserts",
"input_type": "u32, Confidential1",
"output_type": "()",
"description": "Asserts that the confidential amount at the specified input index equals the expected Confidential1 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_output_amount",
"section": "Amount asserts",
"input_type": "u32, u64",
"output_type": "()",
"description": "Asserts that the explicit amount at the specified output index equals the expected u64 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_output_amount",
"section": "Amount asserts",
"input_type": "u32, Confidential1",
"output_type": "()",
"description": "Asserts that the confidential amount at the specified output index equals the expected Confidential1 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_current_amount",
"section": "Amount asserts",
"input_type": "u64",
"output_type": "()",
"description": "Asserts that the explicit input amount at the current_index equals the expected u64 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_current_amount",
"section": "Amount asserts",
"input_type": "Confidential1",
"output_type": "()",
"description": "Asserts that the confidential input amount at the current_index equals the expected Confidential1 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_asset_id_with_amount",
"section": "AssetId and Amount asserts",
"input_type": "u32, bool, u256, u64",
"output_type": "()",
"description": "Asserts that explicit asset_id and amount at the specified input or output index equal the expected u256 and u64 values.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_asset_id_with_amount",
"section": "AssetId and Amount asserts",
"input_type": "u32, bool, Confidential1, Confidential1",
"output_type": "()",
"description": "Asserts that confidential asset_id and amount at the specified input or output index equal the expected Confidential1 values.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_input_asset_id_with_amount",
"section": "AssetId and Amount asserts",
"input_type": "u32, u256, u64",
"output_type": "()",
"description": "Asserts that explicit asset_id and amount at the specified input index equal the expected u256 and u64 values.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_input_asset_id_with_amount",
"section": "AssetId and Amount asserts",
"input_type": "u32, Confidential1, Confidential1",
"output_type": "()",
"description": "Asserts that confidential asset_id and amount at the specified input index equal the expected Confidential1 values.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_output_asset_id_with_amount",
"section": "AssetId and Amount asserts",
"input_type": "u32, u256, u64",
"output_type": "()",
"description": "Asserts that explicit asset_id and amount at the specified output index equal the expected u256 and u64 values.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_output_asset_id_with_amount",
"section": "AssetId and Amount asserts",
"input_type": "u32, Confidential1, Confidential1",
"output_type": "()",
"description": "Asserts that confidential asset_id and amount at the specified output index equal the expected Confidential1 values.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_current_asset_id_with_amount",
"section": "AssetId and Amount asserts",
"input_type": "u256, u64",
"output_type": "()",
"description": "Asserts that explicit input asset_id and amount at the current_index equal the expected u256 and u64 values.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_current_asset_id_with_amount",
"section": "AssetId and Amount asserts",
"input_type": "Confidential1, Confidential1",
"output_type": "()",
"description": "Asserts that confidential input asset_id and amount at the current_index equal the expected Confidential1 values.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_asset_id",
"section": "AssetId asserts",
"input_type": "u32, bool, u256",
"output_type": "()",
"description": "Asserts that the explicit asset_id at the specified input or output index equals the expected u256 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_asset_id",
"section": "AssetId asserts",
"input_type": "u32, bool, Confidential1",
"output_type": "()",
"description": "Asserts that the confidential asset_id at the specified input or output index equals the expected Confidential1 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_input_asset_id",
"section": "AssetId asserts",
"input_type": "u32, u256",
"output_type": "()",
"description": "Asserts that the explicit asset_id at the specified input index equals the expected u256 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_input_asset_id",
"section": "AssetId asserts",
"input_type": "u32, Confidential1",
"output_type": "()",
"description": "Asserts that the confidential asset_id at the specified input index equals the expected Confidential1 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_output_asset_id",
"section": "AssetId asserts",
"input_type": "u32, u256",
"output_type": "()",
"description": "Asserts that the explicit asset_id at the specified output index equals the expected u256 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_output_asset_id",
"section": "AssetId asserts",
"input_type": "u32, Confidential1",
"output_type": "()",
"description": "Asserts that the confidential asset_id at the specified output index equals the expected Confidential1 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_explicit_current_asset_id",
"section": "AssetId asserts",
"input_type": "u256",
"output_type": "()",
"description": "Asserts that the explicit input asset_id at the current_index equals the expected u256 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "assert_confidential_current_asset_id",
"section": "AssetId asserts",
"input_type": "Confidential1",
"output_type": "()",
"description": "Asserts that the confidential input asset_id at the current_index equals the expected Confidential1 value.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "get_explicit_amount",
"section": "Amount getters",
Expand Down Expand Up @@ -1410,7 +1578,7 @@
"simplicityhl_name": "div_mod_256_64",
"section": "`u256` arithmetic",
"input_type": "u256, u64",
"output_type": "(u256, u64)",
"output_type": "()",
"description": "Divide a `u256` value by a `u64` value, returning the `u256` quotient and the `u64` remainder.\n\n## Panics\nPanics if the divisor is zero."
},
{
Expand Down
81 changes: 81 additions & 0 deletions simf/lib/utxo/asserts/amount.simf
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use crate::lib::utxo::getters::amount::{
get_explicit_amount,
get_confidential_amount,
get_explicit_input_amount,
get_confidential_input_amount,
get_explicit_output_amount,
get_confidential_output_amount,
get_explicit_current_amount,
get_confidential_current_amount
};
use crate::lib::asserts::{assert_eq_1, assert_eq_64, assert_eq_256};

/// Asserts that the explicit amount at the specified input or output equals the expected u64 value
///
/// Warning: using this incurs the overhead, and should be used only when the input/output selection
/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly.
pub fn assert_explicit_amount(index: u32, is_input_index: bool, expected: u64) {
let amount: u64 = get_explicit_amount(index, is_input_index);

assert_eq_64(amount, expected);
}

/// Asserts that the confidential amount at the specified input or output equals the expected Confidential1 value
///
/// Warning: using this incurs the overhead, and should be used only when the input/output selection
/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly.
pub fn assert_confidential_amount(index: u32, is_input_index: bool, expected: Confidential1) {
let (parity_bit, amount): Confidential1 = get_confidential_amount(index, is_input_index);
let (expected_parity_bit, expected_amount): Confidential1 = expected;

assert_eq_1(parity_bit, expected_parity_bit);
assert_eq_256(amount, expected_amount);
}

/// Asserts that the explicit amount at the specified input equals the expected u64 value
pub fn assert_explicit_input_amount(index: u32, expected: u64) {
let amount: u64 = get_explicit_input_amount(index);

assert_eq_64(amount, expected);
}

/// Asserts that the confidential amount at the specified input equals the expected Confidential1 value
pub fn assert_confidential_input_amount(index: u32, expected: Confidential1) {
let (parity_bit, amount): Confidential1 = get_confidential_input_amount(index);
let (expected_parity_bit, expected_amount): Confidential1 = expected;

assert_eq_1(parity_bit, expected_parity_bit);
assert_eq_256(amount, expected_amount);
}

/// Asserts that the explicit amount at the specified output equals the expected u64 value
pub fn assert_explicit_output_amount(index: u32, expected: u64) {
let amount: u64 = get_explicit_output_amount(index);

assert_eq_64(amount, expected);
}

/// Asserts that the confidential amount at the specified output equals the expected Confidential1 value
pub fn assert_confidential_output_amount(index: u32, expected: Confidential1) {
let (parity_bit, amount): Confidential1 = get_confidential_output_amount(index);
let (expected_parity_bit, expected_amount): Confidential1 = expected;

assert_eq_1(parity_bit, expected_parity_bit);
assert_eq_256(amount, expected_amount);
}

/// Asserts that the explicit input amount at the current_index equals the expected u64 value
pub fn assert_explicit_current_amount(expected: u64) {
let amount: u64 = get_explicit_current_amount();

assert_eq_64(amount, expected);
}

/// Asserts that the confidential input amount at the current_index equals the expected Confidential1 value
pub fn assert_confidential_current_amount(expected: Confidential1) {
let (parity_bit, amount): Confidential1 = get_confidential_current_amount();
let (expected_parity_bit, expected_amount): Confidential1 = expected;

assert_eq_1(parity_bit, expected_parity_bit);
assert_eq_256(amount, expected_amount);
}
81 changes: 81 additions & 0 deletions simf/lib/utxo/asserts/asset_id.simf
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use crate::lib::utxo::getters::asset_id::{
get_explicit_asset_id,
get_confidential_asset_id,
get_explicit_input_asset_id,
get_confidential_input_asset_id,
get_explicit_output_asset_id,
get_confidential_output_asset_id,
get_explicit_current_asset_id,
get_confidential_current_asset_id
};
use crate::lib::asserts::{assert_eq_1, assert_eq_256};

/// Asserts that the explicit asset_id at the specified input or output equals the expected u256 value
///
/// Warning: using this incurs the overhead, and should be used only when the input/output selection
/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly.
pub fn assert_explicit_asset_id(index: u32, is_input_index: bool, expected: u256) {
let asset_id: u256 = get_explicit_asset_id(index, is_input_index);

assert_eq_256(asset_id, expected);
}

/// Asserts that the confidential asset_id at the specified input or output equals the expected Confidential1 value
///
/// Warning: using this incurs the overhead, and should be used only when the input/output selection
/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly.
pub fn assert_confidential_asset_id(index: u32, is_input_index: bool, expected: Confidential1) {
let (parity_bit, asset_id): Confidential1 = get_confidential_asset_id(index, is_input_index);
let (expected_parity_bit, expected_asset_id): Confidential1 = expected;

assert_eq_1(parity_bit, expected_parity_bit);
assert_eq_256(asset_id, expected_asset_id);
}

/// Asserts that the explicit asset_id at the specified input equals the expected u256 value
pub fn assert_explicit_input_asset_id(index: u32, expected: u256) {
let asset_id: u256 = get_explicit_input_asset_id(index);

assert_eq_256(asset_id, expected);
}

/// Asserts that the confidential asset_id at the specified input equals the expected Confidential1 value
pub fn assert_confidential_input_asset_id(index: u32, expected: Confidential1) {
let (parity_bit, asset_id): Confidential1 = get_confidential_input_asset_id(index);
let (expected_parity_bit, expected_asset_id): Confidential1 = expected;

assert_eq_1(parity_bit, expected_parity_bit);
assert_eq_256(asset_id, expected_asset_id);
}

/// Asserts that the explicit asset_id at the specified output equals the expected u256 value
pub fn assert_explicit_output_asset_id(index: u32, expected: u256) {
let asset_id: u256 = get_explicit_output_asset_id(index);

assert_eq_256(asset_id, expected);
}

/// Asserts that the confidential asset_id at the specified output equals the expected Confidential1 value
pub fn assert_confidential_output_asset_id(index: u32, expected: Confidential1) {
let (parity_bit, asset_id): Confidential1 = get_confidential_output_asset_id(index);
let (expected_parity_bit, expected_asset_id): Confidential1 = expected;

assert_eq_1(parity_bit, expected_parity_bit);
assert_eq_256(asset_id, expected_asset_id);
}

/// Asserts that the explicit input asset_id at the current_index equals the expected u256 value
pub fn assert_explicit_current_asset_id(expected: u256) {
let asset_id: u256 = get_explicit_current_asset_id();

assert_eq_256(asset_id, expected);
}

/// Asserts that the confidential input asset_id at the current_index equals the expected Confidential1 value
pub fn assert_confidential_current_asset_id(expected: Confidential1) {
let (parity_bit, asset_id): Confidential1 = get_confidential_current_asset_id();
let (expected_parity_bit, expected_asset_id): Confidential1 = expected;

assert_eq_1(parity_bit, expected_parity_bit);
assert_eq_256(asset_id, expected_asset_id);
}
Loading
Loading