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
43 changes: 43 additions & 0 deletions src/std/src/assert.simf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pub fn assert_eq8(a: u8, b: u8) {
assert!(jet::eq_8(a, b));
}

pub fn assert_eq16(a: u16, b: u16) {
assert!(jet::eq_16(a, b));
}

pub fn assert_eq32(a: u32, b: u32) {
assert!(jet::eq_32(a, b));
}

pub fn assert_eq64(a: u64, b: u64) {
assert!(jet::eq_64(a, b));
}

pub fn assert_eq256(a: u256, b: u256) {
assert!(jet::eq_256(a, b));
}

pub fn assert_none8(val: Option<u8>) {
assert!(is_none::<u8>(val));
}

pub fn assert_none16(val: Option<u16>) {
assert!(is_none::<u16>(val));
}

pub fn assert_none32(val: Option<u32>) {
assert!(is_none::<u32>(val));
}

pub fn assert_none64(val: Option<u64>) {
assert!(is_none::<u64>(val));
}

pub fn assert_none128(val: Option<u128>) {
assert!(is_none::<u128>(val));
}

pub fn assert_none256(val: Option<u256>) {
assert!(is_none::<u256>(val));
}
18 changes: 18 additions & 0 deletions src/std/src/lib.simf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

pub fn not(bit: bool) -> bool {
<u1>::into(jet::complement_1(<bool>::into(bit)))
}


pub fn or(a: bool, b: bool) -> bool {
<u1>::into(jet::or_1(<bool>::into(a), <bool>::into(b)))
}

pub fn assert_false(b: bool) {
assert!(not(b));
}

pub fn check_sig_all_hash(pk: Pubkey, sig: Signature) {
let msg: u256 = jet::sig_all_hash();
jet::bip_0340_verify((pk, msg), sig);
}
49 changes: 49 additions & 0 deletions src/std/src/timelocks.simf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pub fn enforce_relative_distance(min_distance: Distance) {
// Assert that the current input is spent in a transaction that can
// only appear a distance of at least min_distance blocks after the input's
// UTXO. Panic otherwise.

// Transaction version must be at least 2.
assert!(jet::le_32(2, jet::version()));

// Fetch and parse sequence for current transaction
let parsed_seq: Option<Either<Distance, Duration>> = jet::parse_sequence(jet::current_sequence());

match parsed_seq {
// Failure condition
None => assert!(false),
// This is either a distance or a duration, but only a distance is
// acceptable here.
Some(actual_data: Either<Distance, Duration>) => match actual_data {
// Is the actual distance greater than or equal to the specified min_distance?
Left(actual_distance: Distance) => assert!(jet::le_16(min_distance, actual_distance)),
// A duration is not acceptable in this context.
Right(actual_duration: Duration) => assert!(false),
},
}
}

pub fn enforce_relative_duration(min_duration: Duration) {
// Assert that the current input is spent in a transaction that can only
// appear a duration of at least min_duration units of 512 seconds after
// the input's UTXO. Panic otherwise.

// Transaction version must be at least 2.
assert!(jet::le_32(2, jet::version()));

// Fetch and parse sequence for current transaction
let parsed_seq: Option<Either<Distance, Duration>> = jet::parse_sequence(jet::current_sequence());

match parsed_seq {
// Failure condition
None => assert!(false),
// This is either a distance or a duration, but only a duration is
// acceptable here.
Some(actual_data: Either<Distance, Duration>) => match actual_data {
// A distance is not acceptable in this context.
Left(actual_distance: Distance) => assert!(false),
// Is the actual duration greater than or equal to the specified min_duration?
Right(actual_duration: Duration) => assert!(jet::le_16(min_duration, actual_duration)),
},
}
}
Loading