Skip to content

Add Non interactive fee bumping example#109

Merged
apoelstra merged 2 commits intomasterfrom
sanket1729/nifb
Dec 30, 2024
Merged

Add Non interactive fee bumping example#109
apoelstra merged 2 commits intomasterfrom
sanket1729/nifb

Conversation

@sanket1729
Copy link
Copy Markdown
Member

Had to refactor some of the dummy_env stuff.

If I try to include change output in the default env, everything breaks and I did not want to spend time trying to fix all of tests. Instead, we create a new default with fee just for this one test case.

@apoelstra
Copy link
Copy Markdown
Contributor

In 8231b95: trailing whitespace on several lines.

@apoelstra
Copy link
Copy Markdown
Contributor

In 8231b95:

Looks like you're using left_pad in a couple places to widen integer types. You can just use <u64>::from or <u32>::into.

Your changes to the test environment seem fine to me.

@apoelstra
Copy link
Copy Markdown
Contributor

Done reviewing 16ebe74

Had to refactor some of the dummy_env stuff. If I try to include
change output in the default env, everything breaks and I did not want
to spend time trying to fix all of tests. Instead, we create a new
default with fee just for this one test case.
@sanket1729
Copy link
Copy Markdown
Member Author

Looks like you're using left_pad in a couple places to widen integer types. You can just use ::from or ::into.
Your changes to the test environment seem fine to me.

Can I do it. The casting table requires me to construct a tuple (u1, u1) to cast to u2. So I will need 6 of them to cast to u64?

@apoelstra
Copy link
Copy Markdown
Contributor

cc @uncomputable can you provide some guidance here? It doesn't seem right that the user has to call a jet explicitly for integer promotion.

@sanket1729
Copy link
Copy Markdown
Member Author

let v2 : u64 = <u1>::into(v1);
   |                    ^^^^^^^^^^^^^^ Cannot cast values of type `u1` as values of type `u64`


// Helper function to ensure the provided boolean value is not negative.
fn check_neg(v : bool) {
assert!(jet::eq_8(jet::left_pad_low_1_8(<bool>::into(v)), 0));
Copy link
Copy Markdown
Collaborator

@uncomputable uncomputable Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f2ccc62: <u1>::into(jet::complement_1(<bool>::into(v))) should be shorter to write and cheaper in fees. The casting <T>::into is free and doesn't appear in the Simplicity target code.

Simfony should have an in-built Boolean negation function.

Comment thread src/array.rs
}

impl<'a, A: Clone> BTreeSlice<'a, A> {
impl<A: Clone> BTreeSlice<'_, A> {
Copy link
Copy Markdown
Collaborator

@uncomputable uncomputable Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ab42d67: Are you using rust analyzer? clippy didn't show me these lints. I can integrate a better linker than clippy into my workflow if there is one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uncomputable I think that these lints showed up in a fairly recent version of nightly (maybe stable now?) and you just need to update your toolchain to see them.

@uncomputable
Copy link
Copy Markdown
Collaborator

Casting is possible when two Simfony types are based on the same Simplicity type. Casting is a NOP in terms of Simplicity. Integers with different bit width are different types in Simplicity, so there is no cast.

To convert u1 to u64, left_pad_low_1_64 can be called. That seems to be the cheapest and most concise way. Alternatively, a nested tuple of integers and Booleans can be cast into u64. The cast itself is free, but constructing the tuple is not.

let b: bool = true;
let x: u64 = <(u32, (u16, (u8, (u4, (u2, (u1, bool))))))>::into((0, (0, (0, (0, (0, (0, b)))))));
assert!(jet::eq_64(x, 1));

Copy link
Copy Markdown
Collaborator

@uncomputable uncomputable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ab42d67 Feel free to optimize the check_neg function.

@uncomputable
Copy link
Copy Markdown
Collaborator

I have code to dynamically generate witness data for most of the Simfony examples, so we can change the Elements environment without every test failing. I will make a PR when the API is ready and integrate the hotfix from this PR.

Copy link
Copy Markdown
Contributor

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ab42d67; successfully ran local tests

@apoelstra apoelstra merged commit 1424855 into master Dec 30, 2024
@apoelstra apoelstra deleted the sanket1729/nifb branch December 30, 2024 21:55
@sanket1729
Copy link
Copy Markdown
Member Author

I am planning to post this example on delving bitcoin to get some more attention to simphony and some cool applications. Let me know if you have any objections

@uncomputable
Copy link
Copy Markdown
Collaborator

That's a great idea. Make sure you hit the right spelling :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants