Bitcoin Forum
May 01, 2024, 09:44:29 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Why OP_CAT is disabled and why OP_ADD is only a 32-bit op?  (Read 1032 times)
abhvious (OP)
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
1714599869
Hero Member
*
Offline Offline

Posts: 1714599869

View Profile Personal Message (Offline)

Ignore
1714599869
Reply with quote  #2

1714599869
Report to moderator
1714599869
Hero Member
*
Offline Offline

Posts: 1714599869

View Profile Personal Message (Offline)

Ignore
1714599869
Reply with quote  #2

1714599869
Report to moderator
I HATE TABLES I HATE TABLES I HA(╯°□°)╯︵ ┻━┻ TABLES I HATE TABLES I HATE TABLES
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714599869
Hero Member
*
Offline Offline

Posts: 1714599869

View Profile Personal Message (Offline)

Ignore
1714599869
Reply with quote  #2

1714599869
Report to moderator
1714599869
Hero Member
*
Offline Offline

Posts: 1714599869

View Profile Personal Message (Offline)

Ignore
1714599869
Reply with quote  #2

1714599869
Report to moderator
1714599869
Hero Member
*
Offline Offline

Posts: 1714599869

View Profile Personal Message (Offline)

Ignore
1714599869
Reply with quote  #2

1714599869
Report to moderator
TierNolan
Legendary
*
Offline Offline

Activity: 1232
Merit: 1083


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:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!