Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enforce vault input index of 0 #10

Merged
merged 1 commit into from
Sep 27, 2024
Merged

Conversation

monlovesmango
Copy link
Contributor

@monlovesmango monlovesmango commented Aug 23, 2024

update trigger and cancel scripts to force vault input to be first. otherwise if the fee paying transaction is the first input the vault can be drained to fees. (resolves #2 )

if you would like to test this fix you can use my fee-drain branch which creates a new action for draining via a trigger transaction and draining via a cancel transaction. (there is also a drain via complete transaction but it doesn't work and I don't think it can work).

@monlovesmango monlovesmango changed the title enforce vault input index of 0 (resolves #2) enforce vault input index of 0 Aug 23, 2024
@rot13maxi
Copy link
Contributor

Thanks for taking a look!

Copy link
Contributor

@rot13maxi rot13maxi left a comment

Choose a reason for hiding this comment

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

looks good! if you dont mind adding the todo I suggested, we can go ahead and merge this. Thanks for the contributions!

@@ -26,6 +26,10 @@ pub(crate) fn vault_trigger_withdrawal() -> ScriptBuf {
// start with encoded leaf hash
.push_opcode(OP_CAT) // encoded leaf hash
.push_opcode(OP_CAT) // encoded leaf hash
.push_opcode(OP_SWAP) // bring input index to top of stack
.push_opcode(OP_DROP) // remove input index
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.push_opcode(OP_DROP) // remove input index
// TODO: add an `index` field to the CommitmentSpec so that we can exclude it and remove the OP_SWAP and OP_DROP here
.push_opcode(OP_DROP) // remove input index

Copy link
Contributor

Choose a reason for hiding this comment

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

just add this little TODO so in the future we can remove these two opcodes and save a little witness space :)

@monlovesmango
Copy link
Contributor Author

ok I think I completed the todo correctly. please verify.

@rot13maxi
Copy link
Contributor

Looks good! thanks for the contribution!

@rot13maxi rot13maxi merged commit 48b7ee9 into taproot-wizards:main Sep 27, 2024
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.

enforce input index on trigger and complete transactions
2 participants