Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: bigphoenixman on November 30, 2017, 02:46:02 AM



Title: confused at CScriptCompressor::Decompress()
Post by: bigphoenixman on November 30, 2017, 02:46:02 AM
bool CScriptCompressor::Decompress(unsigned int nSize, const std::vector<unsigned char> &in)
{
    switch(nSize) {
    case 0x00:
        script.resize(25);
        script[0] = OP_DUP;
        script[1] = OP_HASH160;
        script[2] = 20;
        memcpy(&script[3], in.data(), 20);
        script[23] = OP_EQUALVERIFY;
        script[24] = OP_CHECKSIG;
        return true;
    case 0x01:
        script.resize(23);
        script[0] = OP_HASH160;
        script[1] = 20;
        memcpy(&script[2], in.data(), 20);
        script[22] = OP_EQUAL;
        return true;
    case 0x02:
    case 0x03:
        script.resize(35);
        script[0] = 33;
        script[1] = nSize;
        memcpy(&script[2], in.data(), 32);
        script[34] = OP_CHECKSIG;
        return true;
    case 0x04:
    case 0x05:
        unsigned char vch[33] = {};
        vch[0] = nSize - 2;
        memcpy(&vch[1], in.data(), 32);
        CPubKey pubkey(&vch[0], &vch[33]);
        if (!pubkey.Decompress())
            return false;
        assert(pubkey.size() == 65);
        script.resize(67);
        script[0] = 65;
        memcpy(&script[1], pubkey.begin(), 65);
        script[66] = OP_CHECKSIG;
        return true;
    }
    return false;
}


I know a common TX is a UTXO,  in case 0x00:
push/out/op following in stack.
SIG, PUBkey, OP_DUP, OP_HASH160, ADDRESS,  OP_EQUALVERIFY, OP_CHECKSIG.
that meaning is
OP_DUP, copy PUBKEY
OP_HASH160, calculate this pubkey's address
OP_EQUALVERIFY, make sure this pubkey's address equal sender's address
OP_CHECKSIG, make sure SIG correct

but , i do not understand case 0x01:
I think there less a op_checksig?
is that meaning everyone can do spend another one's bitcoin, because do not need OP_CHECKSIG.

and aslo i do not understand case 0x02,03, 04,05 ??
what is it designed for ?

Thanks a lot!



Title: Re: confused at CScriptCompressor::Decompress()
Post by: achow101 on November 30, 2017, 05:45:54 AM
Case 0 (0x00) is the standard Pay to pubkey hash scriptPubKey type.
Case 1 is the standard Pay to Script Hash scriptPubKey type.
Cases 2 and 3 are for Pay to Pubkey scriptPubKey types with compressed pubkeys. Compressed pubkeys begin with a 2 or a 3, hence there are two types here.
Cases 4 and 5 are for Pay to Pubkey scriptPubKey types with uncompressed pubkeys. Uncompressed pubkeys begin with a 4. Because uncompressed pubkeys are compressed for storage, they need to be decompressed for the script. 4 means that the Y coordinate of the public key was even so the even one is calculated and used. 5 means that the Y coordinate was odd so the odd one is calculated and used.