feat(stack): implement control flow and checktimelock#2217
Closed
tmpolaczyk wants to merge 10 commits intowitnet:scriptingfrom
Closed
feat(stack): implement control flow and checktimelock#2217tmpolaczyk wants to merge 10 commits intowitnet:scriptingfrom
tmpolaczyk wants to merge 10 commits intowitnet:scriptingfrom
Conversation
5665504 to
2ea8b33
Compare
aesedepece
requested changes
Jun 8, 2022
2ea8b33 to
65e183e
Compare
Member
|
This is looking great. Let's address the TODOs and go for it. |
lrubiorod
reviewed
Jun 9, 2022
6d0d530 to
0ff9da4
Compare
aesedepece
reviewed
Jun 16, 2022
Comment on lines
+941
to
+992
| // 2 can spend with secret | ||
| let s = vec![ | ||
| // Witness script | ||
| Item::Value(MyValue::Signature(ks_2.to_pb_bytes().unwrap())), | ||
| Item::Value(MyValue::Bytes(secret)), | ||
| Item::Value(MyValue::Boolean(false)), | ||
| // Redeem script | ||
| Item::Operator(MyOperator::If), | ||
| Item::Value(MyValue::Integer(10_000)), | ||
| Item::Operator(MyOperator::CheckTimeLock), | ||
| Item::Operator(MyOperator::Verify), | ||
| Item::Value(MyValue::Bytes(pk_1.pkh().bytes().to_vec())), | ||
| Item::Operator(MyOperator::CheckSig), | ||
| Item::Operator(MyOperator::Verify), | ||
| Item::Operator(MyOperator::Else), | ||
| Item::Operator(MyOperator::Sha256), | ||
| Item::Value(MyValue::Bytes(hash_secret.as_ref().to_vec())), | ||
| Item::Operator(MyOperator::Equal), | ||
| Item::Operator(MyOperator::Verify), | ||
| Item::Value(MyValue::Bytes(pk_2.pkh().bytes().to_vec())), | ||
| Item::Operator(MyOperator::CheckSig), | ||
| Item::Operator(MyOperator::Verify), | ||
| Item::Operator(MyOperator::EndIf), | ||
| ]; | ||
| assert!(execute_script(s, &ScriptContext { block_timestamp: 0 })); | ||
|
|
||
| // 2 cannot spend with a wrong secret | ||
| let s = vec![ | ||
| // Witness script | ||
| Item::Value(MyValue::Signature(ks_2.to_pb_bytes().unwrap())), | ||
| Item::Value(MyValue::Bytes(vec![0, 0, 0, 0])), | ||
| Item::Value(MyValue::Boolean(false)), | ||
| // Redeem script | ||
| Item::Operator(MyOperator::If), | ||
| Item::Value(MyValue::Integer(10_000)), | ||
| Item::Operator(MyOperator::CheckTimeLock), | ||
| Item::Operator(MyOperator::Verify), | ||
| Item::Value(MyValue::Bytes(pk_1.pkh().bytes().to_vec())), | ||
| Item::Operator(MyOperator::CheckSig), | ||
| Item::Operator(MyOperator::Verify), | ||
| Item::Operator(MyOperator::Else), | ||
| Item::Operator(MyOperator::Sha256), | ||
| Item::Value(MyValue::Bytes(hash_secret.as_ref().to_vec())), | ||
| Item::Operator(MyOperator::Equal), | ||
| Item::Operator(MyOperator::Verify), | ||
| Item::Value(MyValue::Bytes(pk_2.pkh().bytes().to_vec())), | ||
| Item::Operator(MyOperator::CheckSig), | ||
| Item::Operator(MyOperator::Verify), | ||
| Item::Operator(MyOperator::EndIf), | ||
| ]; | ||
| assert!(!execute_script(s, &ScriptContext { block_timestamp: 0 })); | ||
| } |
Member
There was a problem hiding this comment.
Should we check that 2 cannot spend after timelock even if the right secret is provided? 🤔
Contributor
Author
There was a problem hiding this comment.
With this script they can, if that's a requirement we can add another test for that case.
Member
There was a problem hiding this comment.
I think that, ideally, they shouldn't. It is a sort of assumption for an atomic swap that only 1 party can spend at a time.
aesedepece
requested changes
Jun 20, 2022
stack/src/lib.rs
Outdated
| ]; | ||
| assert!(!execute_script(s, &ScriptContext { block_timestamp: 0 })); | ||
|
|
||
| // 2 cannot spend before timelock |
Member
There was a problem hiding this comment.
Suggested change
| // 2 cannot spend before timelock | |
| // 2 cannot spend after timelock |
Contributor
Author
|
Now the tests are failing because of a |
378e5ad to
b557090
Compare
Contributor
Author
|
Closing, will continue in #2240. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.