-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Inclusion of Numeric Encoding in Operation Costs
The VM number format is designed to allow efficient manipulation of arbitrary-precision integers (Satoshi's initial VM implementation used the OpenSSL library's Multiple-Precision Integer format and operations), so sufficiently-optimized VM implementations can theoretically avoid the overhead of decoding and (re)encoding VM numbers. However, if this proposal were to assume zero operation cost for encoding/decoding, this optimization would be required of all performance-critical VM implementations to avoid divergence of real performance from measured operation cost.
Instead, this proposal increments the operation cost of all operations dealing with potentially-large numbers (greater than 2**32) by the byte length of their numeric output (in effect, doubling the cost of pushing the output). This approach fully accounts for the cost of re-encoding numerical results from another internal representation as VM numbers – regardless of the underlying arithmetic implementation. (Note that the cost of decoding VM number inputs is already accounted for (in advance) by the comprehensive limiting of pushed bytes. See Rationale: Limitation of Pushed Bytes.)
Because operation cost can be safely reduced - but not increased - in future upgrades without invalidating contracts1, this proposal's approach is considered more conservative than omitting a cost for re-encoding.