Bitcoin Forum
July 22, 2018, 07:54:51 AM *
News: Latest stable version of Bitcoin Core: 0.16.1  [Torrent]. (New!)
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Why OP_CAT is disabled and why OP_ADD is only a 32-bit op?  (Read 917 times)
abhvious
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
January 28, 2015, 09:12:34 AM
 #1

(1) Can anyone explain why the OP_CAT operation is disabled?


(2) Alternatively, can anyone explain why the OP_ADD (and other numeric operations) are 32-bit operations that throw an exception if the stack has a number that is larger than 32 bits?

https://github.com/libbitcoin/libbitcoin/blob/master/src/math/script_number.cpp#L91-L97

bool script_number::set_data(const data_chunk& data)
{
    if (data.size() > max_script_number_size)
        return false;
    value_ = script_number_deserialize(data);
    return true;
}

I ask because I would like to "mix" two values that are on the stack (eg. two hashes) and then take a hash of the result.  The mixing can be accomplished with either a string concatenate or an addition operation.  Any insight would be appreciated; if there are no serious reasons, I would like to consider drafting a BIP to change the behavior of one of the two operations (the most palatable one).

Thanks!

abhi
1532246091
Hero Member
*
Offline Offline

Posts: 1532246091

View Profile Personal Message (Offline)

Ignore
1532246091
Reply with quote  #2

1532246091
Report to moderator
1532246091
Hero Member
*
Offline Offline

Posts: 1532246091

View Profile Personal Message (Offline)

Ignore
1532246091
Reply with quote  #2

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

Posts: 1532246091

View Profile Personal Message (Offline)

Ignore
1532246091
Reply with quote  #2

1532246091
Report to moderator
TierNolan
Legendary
*
Offline Offline

Activity: 1190
Merit: 1001


View Profile
January 28, 2015, 11:09:44 AM
 #2

(1) Can anyone explain why the OP_CAT operation is disabled?

It allows you to quickly use up all of a node's memory.

<32 bytes of data> OP_DUP OP_CAT OP_DUP OP_CAT ... OP_DUP OP_CAT OP_DUP OP_CAT

The OP_DUP/OP_CAT combination makes a copy of the data and then combine the 2 parts into one array.  This doubles the memory required.

Every 10 doublings, the memory usage increases 1024 times.  After 40 doublings, the node would require 32 TB of RAM (and 32 PB after 50 doublings).

This would allow nodes to be easily crashed no matter how much RAM they had.

Instead of setting a limit on total RAM usage for scripts, they just disabled the opcodes.

Quote
(2) Alternatively, can anyone explain why the OP_ADD (and other numeric operations) are 32-bit operations that throw an exception if the stack has a number that is larger than 32 bits?

That is what the opcode does.  It means that a node doesn't need a large integer library to do the addition.

Quote
I ask because I would like to "mix" two values that are on the stack (eg. two hashes) and then take a hash of the result.  The mixing can be accomplished with either a string concatenate or an addition operation.  Any insight would be appreciated; if there are no serious reasons, I would like to consider drafting a BIP to change the behavior of one of the two operations (the most palatable one).

This would be a hard fork change.  It is unlikely to be accepted unless it adds a large amount of value to the system.

1LxbG5cKXzTwZg9mjL3gaRE835uNQEteWF
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!