Skip to content

Instantly share code, notes, and snippets.

View sanket1729's full-sized avatar
💭
Bitcoin Minimalist

Sanket Kanjalkar sanket1729

💭
Bitcoin Minimalist
View GitHub Profile
trait ScriptContext<Pk: MiniscriptKey>{
fn is_valid(&self, node: decode::Terminal<Pk>) -> Result<(), Error>{
}
}
struct Legacy{
}
# entail(A,B) A |- B
entail(false,_) = true
entail(_,true) = true
entail(true, _) = false
entail(_, false) = false
Let C = set of pks, timelocks and haslocks in A
C = x:C'; A1 = A with x set to true, A2 = A with x set to false
entail(A,B) = entail (A1,B1) and entail(A2,B2)

This document proposes new opcodes to be added to the elements network along with the taproot upgrade. The new tapscript OP_SUCCESS opcodes allow introducing new opcodes more cleanly than through OP_NOP. In this document, we propose modifying the following OP_SUCCESS to have the additional semantics. We use opcodes serially OP_SUCCESS200, 201... in order to avoid conflict with bitcoin potentially using OP_SUCESSSx(assuming bitcoin uses those serially based on availability).

Resource Limits

Changes in Taproot(Including Standardness Policy Changes)

Taproot already increases a lot of resource limitations from segwitv0, so there is no additional need to alter any of those. In particular, from BIP 342

  • Script size limit: the maximum script size of 10000 bytes does not apply. Their size is only implicitly bounded by the block weight limit.

TODO: Rust-miniscript behaviour for resource limitations:

Safe vs Valid vs Analyzable/Liftable

This document refers to bitcoin consensus and standardness rules as of bitcoin core release 0.20.

One of miniscript’s goals are to make advanced Script functionality accommodate both machine and human analysis. However such a analysis is not possible in all cases.

  • Validity: Validity refers to whether the miniscript tree constructions follows the grammer rules. For eg: Top level must be B, or thresh must have all of it's arguments being dissatifyable.
  • Safety: Whether all satisfactions of miniscript require a digital signature.
  • Analyzable/Liftable: Even if the given is valid and safe, it does not imply that miniscript is consensus and standardness complete. That is, there may exist some semantics implied by the lifted miniscript which cannot be realized in bitcoin network rules. This maybe because of two main reasons
pub trait ScriptContext:
fmt::Debug + Clone + Ord + PartialOrd + Eq + PartialEq + private::Sealed
{
/// Depending on ScriptContext, fragments can be malleable. For Example,
/// under Legacy context, PkH is malleable because it is possible to
/// estimate the cost of satisfaction because of compressed keys
/// This is currently only used in compiler code for removing malleable
/// compilations.
/// This does NOT recursively check if the children of the fragment are
/// valid or not. Since the compilation proceeds in a leaf to root fashion,
@sanket1729
sanket1729 / temp.rs
Created November 2, 2020 10:43
Sorted Multi
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct SortedMultiVec<Pk: MiniscriptKey, Ctx: ScriptContext>{
/// public keys inside sorted Multi
pub pks: Vec<Pk>,
/// The current ScriptContext for sortedmulti
pub(crate) phantom: PhantomData<Ctx>
}
impl SortedMultiVec{
fn new(pks: &[Pk]) -> Result<Self, Error>{
@sanket1729
sanket1729 / Descriptor
Created November 17, 2020 17:33
Descriptor_design
Descriptor{
Sh(ShInner),
Wsh(WshInner),
Bare(Miniscript),
Pk,
Pkh,
Wpkh,
}
def normalize(sign, v, modulus):
"""Compute sign*v mod modulus, where v in (-2*modulus,modulus); output in [0,modulus)."""
ans = (sign*v) % modulus
v += modulus & (v >> 256) # I think this line is wrong when v has 257th bit set and 256 unset
c = (sign - 1) >> 1
v = (v ^ c) - c
v += modulus & (v >> 256)
assert ans == (v % modulus), print(ans, v)
return v
@sanket1729
sanket1729 / temp.rs
Last active December 21, 2020 21:17
fn witness_script<ToPkCtx: Copy>(&self, to_pk_ctx: ToPkCtx) -> BtcScript
where
Pk: ToPublicKey<ToPkCtx>,
{
let tweak = self.desc.witness_script(to_pk_ctx).into_bytes();
let mut builder = script::Builder::new()
.push_opcode(opcodes::all::OP_DEPTH)
.push_int(self.fed_k as i64 + 1)
.push_opcode(opcodes::all::OP_EQUAL)
// Miniscript
// Written in 2018 by
// Andrew Poelstra <apoelstra@wpsoftware.net>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication