Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: alkurbatov97 on August 15, 2018, 02:52:48 PM



Title: Stack size
Post by: alkurbatov97 on August 15, 2018, 02:52:48 PM
What is the stack size in Bitcoin Script?


Title: Re: Stack size
Post by: bob123 on August 15, 2018, 03:01:04 PM
That's a weird question with no clear answer.
Do you get an error when signing a transaction (e.g. 'operation not valid with the current stack size'), or why are you asking this question ?

If you somehow encounter an error and want to get a detailed helpful reply, you should include every necessary information into your post.


In case of you getting 'operation not valid with the current stack size' when signing a transaction with core, you are somehow either missing private keys to sign the TX or the script verification failed for any other reason.
Are you trying to sign a multisig tx ?


Title: Re: Stack size
Post by: alkurbatov97 on August 15, 2018, 03:58:09 PM
Hi
Thank you for comment.
Just I read in one source that the stack size when using Bitcoin Script is limited to 16 values.
Is it so?


Title: Re: Stack size
Post by: amaclin1 on August 15, 2018, 06:00:45 PM
Hi
Thank you for comment.
Just I read in one source that the stack size when using Bitcoin Script is limited to 16 values.
Is it so?

No, this is definetely wrong


Title: Re: Stack size
Post by: HeRetiK on August 16, 2018, 10:09:03 AM
The maximum stack size for a Bitcoin script to be still considered valid is 1000:

Code:
// Maximum number of values on script interpreter stack
static const int MAX_STACK_SIZE = 1000;


Depending on your script you are more likely to run into the maximum script size in bytes though:

Code:
// Maximum script length in bytes
static const int MAX_SCRIPT_SIZE = 10000;


For reference:

https://github.com/bitcoin/bitcoin/blob/78dae8caccd82cfbfd76557f1fb7d7557c7b5edb/src/script/script.h

https://github.com/bitcoin/bitcoin/blob/78dae8caccd82cfbfd76557f1fb7d7557c7b5edb/src/script/interpreter.cpp