Is there any part of the Bitcoin protocol that established a limit on the maximum number of op_codes in a script.
Recently I have hit the limit for the bitcoin core client. In: https://github.com/bitcoin/bitcoin/blob/ce56f5621a94dcc2159ebe57e43da727eab18e6c/src/script/interpreter.cpp in line 276 you find:
if (opcode > OP_16 && ++nOpCount > 201) return set_error(serror, SCRIPT_ERR_OP_COUNT);*
I interpret this line as saying that, outside standard type of transactions, there is a limit to 201 operations beside pushing a number from 0 to 16 to the stack.
Is this defined in any part of the protocol or discussed in any BIP?
I know there are limits for multiscript transactions: https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#520byte_limitation_on_serialized_script_size and that the number of signatures should be limited to avoid certain attacks, but for lightweight operations (OP_ADD and the like) I cannot find any explanation on the limit and the exact 201 value.
P.S: I found the error when trying to spend the offending script. Curiously, I was allowed to send the transaction. It is when the client tries to verify the data for the next transaction when there is a problem.