aboutsummaryrefslogtreecommitdiff
path: root/src/script.h
Commit message (Collapse)AuthorAgeFilesLines
* Remove timing-based signature cache unit testGavin Andresen2014-06-251-1/+1
| | | | | | | | | | | | | | | | | Two changes: First removes a unit test that fails in my development environment (OSX, compiled -g3 with clang). sipa says that's not terribly surprising; the CMutableTransaction change makes signing a little more expensive but verification quicker. The unit test timed sign+verify-uncached versus verify-cached-five-times. He also says the test will be invalid when libsec256kp1 is integrated (because validation is super-optimized over signing). core.h change fixes a compiler warning (clang -Wall : CMutableTransaction defined as struct, declared as class in script.h).
* Avoid undefined behavior using CFlatData in CScript serializationWladimir J. van der Laan2014-06-231-4/+4
| | | | | | | | | | | | | | | `&vch[vch.size()]` and even `&vch[0]` on vectors can cause assertion errors with VC in debug mode. This is the problem mentioned in #4239. The deeper problem with this is that we rely on undefined behavior. - Add `begin_ptr` and `end_ptr` functions that get the beginning and end pointer of vector in a reliable way that copes with empty vectors and doesn't reference outside the vector (see https://stackoverflow.com/questions/1339470/how-to-get-the-address-of-the-stdvector-buffer-start-most-elegantly/1339767#1339767). - Add a convenience constructor to CFlatData that wraps a vector. I added `begin_ptr` and `end_ptr` as separate functions as I imagine they will be useful in more places.
* Add CMutableTransaction and make CTransaction immutable.Pieter Wuille2014-06-211-2/+3
| | | | | In addition, introduce a cached hash inside CTransaction, to prevent recalculating it over and over again.
* Remove unused Print/PrintHex functionsWladimir J. van der Laan2014-06-101-11/+0
| | | | | You can just use HexStr(script) or script.ToString() for debugging, no need for these extra functions.
* Remove redundant c_strR E Broadley2014-05-221-1/+1
|
* Merge pull request #3637Wladimir J. van der Laan2014-05-091-1/+1
|\ | | | | | | 6fd7ef2 Also switch the (unused) verification code to low-s instead of even-s. (Pieter Wuille)
| * Also switch the (unused) verification code to low-s instead of even-s.Pieter Wuille2014-03-101-1/+1
| | | | | | | | | | | | | | | | a81cd968 introduced a malleability breaker for signatures (using an even value for S). In e0e14e43 this was changed to the lower of two potential values, rather than the even one. Only the signing code was changed though, the (for now unused) verification code wasn't adapted.
* | Merge pull request #3843Wladimir J. van der Laan2014-05-091-0/+20
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | 787ee0c Check redeemScript size does not exceed 520 byte limit (Peter Todd) 4d79098 Increase IsStandard() scriptSig length (Peter Todd) f80cffa Do not trigger a DoS ban if SCRIPT_VERIFY_NULLDUMMY fails (Peter Todd) 6380180 Add rejection of non-null CHECKMULTISIG dummy values (Peter Todd) 29c1749 Let tx (in)valid tests use any SCRIPT_VERIFY flag (Peter Todd) 68f7d1d Create (MANDATORY|STANDARD)_SCRIPT_VERIFY_FLAGS constants (Peter Todd)
| * | Do not trigger a DoS ban if SCRIPT_VERIFY_NULLDUMMY failsPeter Todd2014-05-081-0/+6
| | |
| * | Add rejection of non-null CHECKMULTISIG dummy valuesPeter Todd2014-05-081-1/+3
| | | | | | | | | | | | | | | | | | This is a source of transaction mutability as the dummy value was previously not checked and could be modified to something other than the usual OP_0 value.
| * | Create (MANDATORY|STANDARD)_SCRIPT_VERIFY_FLAGS constantsPeter Todd2014-05-051-0/+12
| |/
* | script: remove bignum dependencyCory Fields2014-04-221-8/+0
| |
* | script: switch to CScriptNum usage for scriptsCory Fields2014-04-221-40/+11
| |
* | script: add CScriptNum classCory Fields2014-04-221-0/+149
|/ | | | | This class holds an int64_t and replaces the use of CBigInt for script integrals.
* script: reduce OP_RETURN standard relay bytes to 40Jeff Garzik2014-02-261-0/+1
| | | | Per mailing list discussion.
* Add HasCanonicalPushes(), and use it in IsStandardTxPieter Wuille2014-02-111-1/+4
|
* Move IsPushOnly() to script.cppPieter Wuille2014-02-111-17/+1
|
* Cleanup code using forward declarations.Brandon Dahler2013-11-101-25/+30
| | | | | | | | | Use misc methods of avoiding unnecesary header includes. Replace int typedefs with int##_t from stdint.h. Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h. Normalize QT_VERSION ifs where possible. Resolve some indirect dependencies as direct ones. Remove extern declarations from .cpp files.
* Merge pull request #2738 from jgarzik/op_returnGavin Andresen2013-10-211-1/+3
|\ | | | | Relay OP_RETURN data TxOut as standard transaction type.
| * Relay OP_RETURN data TxOut as standard transaction typeJeff Garzik2013-10-021-1/+3
| |
* | Bump Year Number to 2013super32013-10-201-1/+1
|/
* Merge pull request #2791 from sipa/provepruneGavin Andresen2013-09-231-0/+7
|\ | | | | Prune provably-unspendable outputs
| * Prune provably-unspendable outputsPieter Wuille2013-07-101-0/+7
| |
* | Replace printf with LogPrintf / LogPrintGavin Andresen2013-09-181-2/+2
| |
* | Document and test OP_RESERVED weirdnessPeter Todd2013-08-251-0/+4
| | | | | | | | | | | | Seems it was forgotten about when IsPushOnly() and the unittests were written. A particular oddity is that OP_RESERVED doesn't count towards the >201 opcode limit unlike every other named opcode.
* | Only create signatures with even S, and verification mode to check.Pieter Wuille2013-08-161-5/+6
|/ | | | | | | | | | | | | | | | | To fix a minor malleability found by Sergio Lerner (reported here: https://bitcointalk.org/index.php?topic=8392.msg1245898#msg1245898) The problem is that if (R,S) is a valid ECDSA signature for a given message and public key, (R,-S) is also valid. Modulo N (the order of the secp256k1 curve), this means that both (R,S) and (R,N-S) are valid. Given that N is odd, S and N-S have a different lowest bit. We solve the problem by forcing signatures to have an even S value, excluding one of the alternatives. This commit just changes the signing code to always produce even S values, and adds a verification mode to check it. This code is not enabled anywhere yet. Existing tests in key_tests.cpp verify that the produced signatures are still valid.
* Add ExtractAffectedKeys to scriptPieter Wuille2013-06-221-0/+1
| | | | | | This function finds all keys affected by a particular output script, supporting everything ExtractDestinations supports (pay-to-pubkey, pay-to-pubkeyhash, multisig) and recurses into subscripts (P2SH).
* Removed AcceptToMemoryPool method from CTransaction. This method belongs to ↵Eric Lombrozo2013-06-051-1/+1
| | | | | | | | | | | | | | | | | the mempool instance. Removed AreInputsStandard from CTransaction, made it a regular function in main. Moved CTransaction::GetOutputFor to CCoinsViewCache. Moved GetLegacySigOpCount and GetP2SHSigOpCount out of CTransaction into regular functions in main. Moved GetValueIn and HaveInputs from CTransaction into CCoinsViewCache. Moved AllowFree, ClientCheckInputs, CheckInputs, UpdateCoins, and CheckTransaction out of CTransaction and into main. Moved IsStandard and IsFinal out of CTransaction and put them in main as IsStandardTx and IsFinalTx. Moved GetValueOut out of CTransaction into main. Moved CTxIn, CTxOut, and CTransaction into core. Added minimum fee parameter to CTxOut::IsDust() temporarily until CTransaction is moved to core.h so that CTxOut needn't know about CTransaction.
* CSecret/CKey -> CKey/CPubKey split/refactorPieter Wuille2013-05-301-2/+2
|
* Make CPubKey statically allocatedPieter Wuille2013-05-301-2/+4
|
* Replace 520 constant with MAX_SCRIPT_ELEMENT_SIZEMatt Corallo2013-01-181-0/+2
|
* Merge pull request #2060 from sipa/parallelGavin Andresen2013-01-171-3/+2
|\ | | | | Parallel script verification
| * Remove contention on signature cache during block validationPieter Wuille2013-01-081-0/+1
| | | | | | | | | | | | | | | | Since block validation happens in parallel, multiple threads may be accessing the signature cache simultaneously. To prevent contention: * Turn the signature cache lock into a shared mutex * Make reading from the cache only acquire a shared lock * Let block validations not store their results in the cache
| * Move VerifySignature to mainPieter Wuille2013-01-081-3/+1
| |
* | Fix clang warningsGavin Andresen2013-01-151-2/+2
|/
* Introduce script verification flagsPieter Wuille2012-11-151-3/+10
| | | | | | | | These flags select features to be enabled/disabled during script evaluation/checking, instead of several booleans passed along. Currently these flags are defined: * SCRIPT_VERIFY_P2SH: enable BIP16-style subscript evaluation * SCRIPT_VERIFY_STRICTENC: enforce strict adherence to pubkey/sig encoding standards.
* UltraprunePieter Wuille2012-10-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This switches bitcoin's transaction/block verification logic to use a "coin database", which contains all unredeemed transaction output scripts, amounts and heights. The name ultraprune comes from the fact that instead of a full transaction index, we only (need to) keep an index with unspent outputs. For now, the blocks themselves are kept as usual, although they are only necessary for serving, rescanning and reorganizing. The basic datastructures are CCoins (representing the coins of a single transaction), and CCoinsView (representing a state of the coins database). There are several implementations for CCoinsView. A dummy, one backed by the coins database (coins.dat), one backed by the memory pool, and one that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock, DisconnectBlock, ... now operate on a generic CCoinsView. The block switching logic now builds a single cached CCoinsView with changes to be committed to the database before any changes are made. This means no uncommitted changes are ever read from the database, and should ease the transition to another database layer which does not support transactions (but does support atomic writes), like LevelDB. For the getrawtransaction() RPC call, access to a txid-to-disk index would be preferable. As this index is not necessary or even useful for any other part of the implementation, it is not provided. Instead, getrawtransaction() uses the coin database to find the block height, and then scans that block to find the requested transaction. This is slow, but should suffice for debug purposes.
* Compact serialization for scriptsPieter Wuille2012-10-201-0/+71
| | | | | | | | | | | Special serializers for script which detect common cases and encode them much more efficiently. 3 special cases are defined: * Pay to pubkey hash (encoded as 21 bytes) * Pay to script hash (encoded as 21 bytes) * Pay to pubkey starting with 0x02, 0x03 or 0x04 (encoded as 33 bytes) Other scripts up to 121 bytes require 1 byte + script length. Above that, scripts up to 16505 bytes require 2 bytes + script length.
* Check for canonical public keys and signaturesPieter Wuille2012-09-211-4/+5
| | | | Only enabled inside tests for now.
* Update Warning-strings to use a standard-formatPhilip Kaufmann2012-08-011-1/+1
| | | | | | | | | - ensure warnings always start with "Warning:" and that the first character after ":" is written uppercase - ensure the first sentence in warnings ends with an "!" - remove unneeded spaces from Warning-strings - add missing Warning-string translation - remove a "\n" and replace with untranslatable "<br><br>"
* Implement raw transaction RPC callsGavin Andresen2012-07-051-0/+4
| | | | | | Implement listunspent / getrawtransaction / createrawtransaction / signrawtransaction, to support creation and signing-on-multiple-device multisignature transactions.
* Refactor: SignSignature/VerifyScriptGavin Andresen2012-07-051-0/+3
| | | | | | Minor refactor to support signrawtx signing/verifying transactions when it might only have the previous transaction's txid and txOut.
* Fix signed/unsigned warnings in {script,serialize}.h (fixes #1541)Matt Corallo2012-07-021-1/+1
|
* Refactor: split CKeyID/CScriptID/CTxDestination from CBitcoinAddressPieter Wuille2012-05-241-11/+27
| | | | | | | | | | | | | | | | | This introduces internal types: * CKeyID: reference (hash160) of a key * CScriptID: reference (hash160) of a script * CTxDestination: a boost::variant of the former two CBitcoinAddress is retrofitted to be a Base58 encoding of a CTxDestination. This allows all internal code to only use the internal types, and only have RPC and GUI depend on the base58 code. Furthermore, the header dependencies are a lot saner now. base58.h is at the top (right below rpc and gui) instead of at the bottom. For the rest: wallet -> script -> keystore -> key. Only keystore still requires a forward declaration of CScript. Solving that would require splitting script into two layers.
* Encapsulate public keys in CPubKeyPieter Wuille2012-05-241-0/+6
|
* Update License in File HeadersFordy2012-05-181-1/+1
| | | | | | I originally created a pull to replace the "COPYING" in crypter.cpp and crypter.h, but it turned out that COPYING was actually the correct file.
* Add casts for unavoidable signed/unsigned comparisonsJeff Garzik2012-04-231-1/+1
| | | | | At these code sites, it is preferable to cast rather than change a variable's type.
* SigOp and orphan-tx constants and counts are always unsigned.Jeff Garzik2012-04-231-2/+2
| | | | Fixes several sign-comparison warnings.
* Add explicit numeric constant value for all opcodesWladimir J. van der Laan2012-04-211-115/+115
| | | | | - Easier for debugging (what opcode was 0x... again?) - Clarifies that the opcodes are set in stone in the protocol, and signals that it is impossible to insert opcodes in between.
* Fix bugs on 'unsigned char' platforms.Dwayne C. Litzenberger2012-04-181-2/+4
| | | | | | | | | | | | | | | | | | In ISO C++, the signedness of 'char' is undefined. On some platforms (e.g. ARM), 'char' is an unsigned type, but some of the code relies on 'char' being signed (as it is on x86). This is indicated by compiler warnings like this: bignum.h: In constructor 'CBigNum::CBigNum(char)': bignum.h:81:59: warning: comparison is always true due to limited range of data type [-Wtype-limits] util.cpp: In function 'bool IsHex(const string&)': util.cpp:427:28: warning: comparison is always false due to limited range of data type [-Wtype-limits] In particular, IsHex erroneously returned true regardless of the input characters, as long as the length of the string was a positive multiple of 2. Note: For testing, it's possible using GCC to force char to be unsigned by adding the -funsigned-char parameter to xCXXFLAGS.