Bitcoin Forum
September 22, 2018, 09:40:04 PM *
News: ♦♦ New info! Bitcoin Core users absolutely must upgrade to previously-announced 0.16.3 [Torrent]. All Bitcoin users should temporarily trust confirmations slightly less. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: confused at CScriptCompressor::Decompress()  (Read 172 times)
bigphoenixman
Newbie
*
Offline Offline

Activity: 8
Merit: 0


View Profile
November 30, 2017, 02:46:02 AM
 #1

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!

1537652404
Hero Member
*
Offline Offline

Posts: 1537652404

View Profile Personal Message (Offline)

Ignore
1537652404
Reply with quote  #2

1537652404
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1537652404
Hero Member
*
Offline Offline

Posts: 1537652404

View Profile Personal Message (Offline)

Ignore
1537652404
Reply with quote  #2

1537652404
Report to moderator
1537652404
Hero Member
*
Offline Offline

Posts: 1537652404

View Profile Personal Message (Offline)

Ignore
1537652404
Reply with quote  #2

1537652404
Report to moderator
1537652404
Hero Member
*
Offline Offline

Posts: 1537652404

View Profile Personal Message (Offline)

Ignore
1537652404
Reply with quote  #2

1537652404
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 1526
Merit: 1650


3F1Y9yquzvY6RWvKbw2n2zeo9V5mvBhADU


View Profile WWW
November 30, 2017, 05:45:54 AM
 #2

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.

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!