BitVM and sCrypt

original: https://gist.github.com/msinkec/5827d5285a18de8930324f67b880841e

Invitation to Bitcoin Developers: Utilize sCrypt for Advanced BitVM Implementations

To the Bitcoin Development Community,

In light of the recent advancements in BTC's computational capabilities introduced by BitVM, we are extending an open invitation to explore the integration of sCrypt as a language for developing BitVM scripts. BitVM represents a significant advancement in Bitcoin's scripting capabilities, enabling Turing-complete contracts within the existing BTC framework.

Technical Overview:

BitVM facilitates off-chain computation, essential for complex contract execution while maintaining Bitcoin's on-chain efficiency. While Assembly (ASM) scripts are so far used to express contracts for BitVM, they present certain limitations in terms of readability and broader accessibility.

sCrypt, a high-level language based on TypeScript tailored for Bitcoin smart contracts, offers a more efficient and streamlined approach for developers. The language's design aligns with traditional programming paradigms, enhancing understandability and maintainability of scripts.

Example of Gate Commitment in sCrypt:

type HashPair = {
    hash0: Ripemd160
    hash1: Ripemd160
}

export class DemoBitVM extends SmartContract {
    @prop()
    hashPairA: HashPair

    @prop()
    hashPairB: HashPair

    @prop()
    hashPairE: HashPair

    constructor(
        hashPairA: HashPair,
        hashPairB: HashPair,
        hashPairE: HashPair,
    ) {
        super(...arguments)
        this.hashPairA = hashPairA
        this.hashPairB = hashPairB
        this.hashPairE = hashPairE
    }

    @method()
    public openGateCommit(
        preimageA: ByteString,
        preimageB: ByteString,
        preimageE: ByteString,
    ) {
        const bitA = this.bitValueCommit(this.hashPairA, preimageA)
        const bitB = this.bitValueCommit(this.hashPairB, preimageB)
        const bitE = this.bitValueCommit(this.hashPairE, preimageE)
        assert(this.nand(bitA, bitB) == bitE)
    }

    @method()
    bitValueCommit(hashPair: HashPair, preimage: ByteString): boolean {
        const h = hash160(preimage)
        assert (h == hashPair.hash0 || h == hashPair.hash1)
        return h == hashPair.hash1
    }

    @method()
    nand(A: boolean, B: boolean): boolean {
        return !(A && B)
    }

}

The code above represents a simple gate commitment for BitVM. It has a single entry point, i.e. the public function "openGateCommit", which can be unlocked by providing the apporpriate hash preimages of the commitments.

The code compiles into a bitcoin script, the function of which is analogous to the script described in the BitVM whitepaper (Figure 2):

// Reveal Preimage of hashE0 or hashE1
<hashE0/1>
OP_BITCOMMITMENT
OP_TOALTSTACK
// Now the bit value of "E" is on the stack
// Reveal Preimage of hashB0 or hashB1
<hashB0/1>
OP_BITCOMMITMENT
OP_TOALTSTACK
// Now the bit value of "B" is on the stack
// Reveal Preimage of hashA0 or hashA1
<hashA0/1>
OP_BITCOMMITMENT
OP_TOALTSTACK
// Now the bit value of "A" is on the stack
//
// Verify that "A NAND B == E"
//
// Read "B" from alt stack
OP_FROMALTSTACK
// Compute A NAND B
OP_NAND
// Read "E" from alt stack
OP_FROMALTSTACK
// Check A NAND B == E
OP_EQUALVERIFY

The equivalent is expressed in sCrypt as:

const bitA = this.bitValueCommit(this.hashPairA, preimageA)
const bitB = this.bitValueCommit(this.hashPairB, preimageB)
const bitE = this.bitValueCommit(this.hashPairE, preimageE)
assert(this.nand(bitA, bitB) == bitE)

For more information about sCrypt, please refer to the official documentation.

Invitation and Objectives:

  1. Examination of sCrypt: We encourage the exploration of sCrypt's features and syntax. Its alignment with conventional programming languages positions it as a viable candidate for BitVM script development.

  2. Contribution Using sCrypt: Contributions in sCrypt to the BitVM ecosystem are highly encouraged. Such endeavors would ease the utilization of BTC's full scripting capabilities.

  3. Technical Exchange and Collaboration: The advancement of BitVM and sCrypt requires collective efforts in knowledge exchange and technical collaboration. We welcome insights from both experienced and emerging developers in the Bitcoin community.

Sincerely,

Mihael Šinkec, sCrypt Inc.

Last updated