-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
Thanks for taking a look! |
There was a problem hiding this 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!
src/vault/script.rs
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.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 |
There was a problem hiding this comment.
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 :)
ok I think I completed the todo correctly. please verify. |
Looks good! thanks for the contribution! |
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).