Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: zzkjliu on March 08, 2014, 07:01:13 AM



Title: Why is the maximum length of pubkey 120,not 100 or other?
Post by: zzkjliu on March 08, 2014, 07:01:13 AM
 IsStandard() function in script.cpp has the following code:

Code:
            // Template matching opcodes:
            if (opcode2 == OP_PUBKEYS)
            {
                while (vch1.size() >= 33 && vch1.size() <= 120)
                {

there,Why is the maximum size of pubkey 120,not 100 or other?



Title: Re: Why is the maximum length of pubkey 120,not 100 or other?
Post by: 12648430 on March 08, 2014, 09:22:36 AM
That was changed in a Feb 21 git commit (595b6d8); in the next release the maximum pubkey size will be 65. (Pubkeys are exactly 33 or 65 bytes, depending on whether they're "compressed").


Title: Re: Why is the maximum length of pubkey 120,not 100 or other?
Post by: zzkjliu on March 08, 2014, 10:11:01 AM
From v0.3.18 to v0.9.0rc2, this value has been 120.  The length of pubkey is 33 or 65, that is common sense, the developer is impossible not to know, but why take the 120? at that time must have their reasons, what is the reasons?

Code:
Solver() function in script.cpp in v0.3.18 has the following code:
bool Solver(const CScript& scriptPubKey, vector<pair<opcodetype, valtype> >& vSolutionRet)
{
    ......
    // Scan templates
    const CScript& script1 = scriptPubKey;
    foreach(const CScript& script2, vTemplates)
    {
       ......
        loop
        {
            ......
            if (opcode2 == OP_PUBKEY)
            {
                if (vch1.size() < 33 || vch1.size() > 120
                    break;
                vSolutionRet.push_back(make_pair(opcode2, vch1));
            }
            else if (opcode2 == OP_PUBKEYHASH)
            {
                if (vch1.size() != sizeof(uint160))
                    break;
                vSolutionRet.push_back(make_pair(opcode2, vch1));
            }
            else if (opcode1 != opcode2 || vch1 != vch2)
            {
                break;
            }
        }
    }

    vSolutionRet.clear();
    return false;
}