-
Notifications
You must be signed in to change notification settings - Fork 56
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
feat(stack): implement control flow and checktimelock #2217
Conversation
5665504
to
2ea8b33
Compare
2ea8b33
to
65e183e
Compare
This is looking great. Let's address the TODOs and go for it. |
6d0d530
to
0ff9da4
Compare
// 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 })); | ||
} |
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.
Should we check that 2 cannot spend after timelock even if the right secret is provided? 🤔
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.
With this script they can, if that's a requirement we can add another test for that case.
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.
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.
stack/src/lib.rs
Outdated
]; | ||
assert!(!execute_script(s, &ScriptContext { block_timestamp: 0 })); | ||
|
||
// 2 cannot spend before timelock |
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.
// 2 cannot spend before timelock | |
// 2 cannot spend after timelock |
Now the tests are failing because of a |
378e5ad
to
b557090
Compare
Closing, will continue in #2240. |
No description provided.