Question on smart contract TEAL code size and global state readings

  1. I am building a smart contract with the code of approval program around 40KB. The server is giving me the error of reaching the max size, and the error screenshot is listed below.

This error information is kind of confusing to me. I would like to know whether the problem is the size of the program code is too large, or the stack of the smart contract is overflowed.

  1. Suppose one global state records 0 as its initial value.
    There is one call application transaction, where this transaction first write value 1 into the global state, then read this global state, then write another value 2 into this global state. I am wondering about the value read from the gloabl state in the middle. What should be the value returning in reading, 0 or 1 or 2?
  1. The approval contract (once compiled) must be at most 1kB. Your approval program is too large.
  2. I believe when you write a value using app_global_put, you should read the value you just wrote when calling app_global_get afterwards. @JasonW Can you confirm?

Thank you for the reply @fabrice

In my estimation, the code size should be at least 20KB large, but now the upper bound of the contract code is too small. Is it possible to extend the max size of program in smart contract?

You can split the code and put some of it in stateless smart contracts or in other stateful smart contracts.
Then the main stateful smart contract can require to be run inside a group that is also calling the other stateful smart contracts or requiring 0-Algo transaction from stateless smart contracts to themselves.

You may also want to consider Reach ( that is doing that automatically.

Thanks @fabrice for your response.

I think I am interested in Reach since I am focused on a larger smart contract program. Is it possible to have an extended size of the compiled program in Reach?

Reach has no real size limitation to my knowledge, as they will compile in multiple TEAL contracts if needed.

Thanks @fabrice .

Does Reach support Python language, or have any python APIs? I look through the tutorial but it is only written in JavaScript.

There are two parts of Reach:

  • the “smart contract”/computational part which I understand will always be in a language that looks like JavaScript
  • the “backend” part that calls the smart contract. This part currently only supports JavaScript but that could be extended to other languages in the future: 3.10 What are Reach's limitations and its future roadmap

@cswenor Don’t hesitate to add details / correct me.

Reach is a platform, and part of that platform is the Reach Language.

Reach Language is a subset of JavaScript, and the compiler outputs both Teal, and the middleware layer of the client. We started with only allowing you to write your interface in JavaScript as well, but recently(this week) we started making it available to write your interface in Python or Go as well. We don’t have the documentation written for this new feature yet, but I invite you to come over to our Discord channel and ask any questions that you would like.

Thank @fabrice and @cswenor for the help.

  1. It is better for me to improve my code following the instruction of @fabrice . Here I meet another question on contract computation limit.

What does the “resource intensive” in this error mean? Any suggestions on how to improve?

  1. Also, is it possible for a stateful smart contract to run more than 2 programs at the same time? If possible, how to create that kind of contract?
  1. Each smart contract operation has a cost. There is a limit on the total cost of a smart contract. See Algorand Developer Docs
  2. No, but you can create multiple applications.