# Smart Contract Costs & Constraints

This page covers the costs and constraints specific to smart contract development on Algorand. For a complete list of all protocol parameters including transaction fees, minimum balances, and other network-wide settings, see the main protocol parameters page.

## Program Constraints

### Program Size Limits

| Type | Constraint |
| --- | --- |
| Logic Signatures | Max size: 1000 bytes for logic signatures (consensus parameter LogicSigMaxSize). Components: The bytecode plus the length of all arguments |
| Smart Contracts | Max size: 2048*(1+ExtraProgramPages) bytes Components: ApprovalProgram + ClearStateProgram |

### Application Call Arguments

| Parameter | Constraint |
| --- | --- |
| Number of Arguments | Maximum 16 arguments can be passed to an application call. This limit is defined by the consensus parameter `MaxAppArgs` |
| Combined Size of Arguments | The maximum combined size of arguments is 2048 bytes. This limit is defined by the consensus parameter `MaxAppTotalArgLen` |
| Max Size of Compiled TEAL Code | The maximum size of compiled TEAL code combined with arguments is 1000 bytes. This limit is defined by the consensus parameter `LogicSigMaxSize` |
| Max Cost of TEAL Code | The maximum cost of TEAL code is 20000 for logic signatures and 700 for smart contracts. These limits are defined by the consensus parameters `LogicSigMaxCost` and `MaxAppProgramCost` respectively |
| Argument Types | The arguments to pass to the ABI call can be one of the following types: `boolean`, `number`, `bigint`, `string`, `Uint8Array`, an array of one of the above types, `algosdk.TransactionWithSigner`, `TransactionToSign`, `algosdk.Transaction`, `Promise<SendTransactionResult>`. These types are used when specifying the ABIAppCallArgs for an application call |

## Opcode Constraints

In Algorand, the opcode budget measures the computational cost of executing a smart contract or logic signature. Each opcode (operation code) in the Algorand Virtual Machine (AVM) has an associated cost deducted from the opcode budget during execution.

| Parameter | Constraint |
| --- | --- |
| Cost of Opcodes | Most opcodes have a computational cost of 1. Some operations (e.g., SHA256, keccak256, sha512_256, ed25519verify) have larger costs. |
| Budget Constraints | Max opcode budget: Smart signatures: 20,000 units Smart contracts invoked by a single application transaction: 700 units. If invoked via a group: 700 * number of application transactions. |
| Clear State Programs | Initial pooled budget must be >= 700 units or higher. Execution limit: 700 units. |

> **Note:** Algorand Python provides a helper method for increasing the available opcode budget, see `algopy.ensure_budget`.

## Stack

In Algorand’s Algorand Virtual Machine (AVM), the stack is a key component of the execution environment.

| Parameter | Constraint |
| --- | --- |
| Maximum Stack Depth | 1000. If the stack depth is exceeded, the program fails. |
| Item Size Limits | The stack can contain values of either uint64 or byte-arrays. Byte-arrays may not exceed 4096 bytes in length. |
| Type Limitation | Every element of the stack is restricted to the types uint64 and bytes. |
| Item Size Limit | Maximum size for byte arrays is 4096 bytes. Maximum value uint64 is 18446744073709551615. |
| Operation Failure | Fails if an opcode accesses a position in the stack that does not exist. |

## Resources

In Algorand, the access and usage of resources such as account balance/state, application state, etc., by applications are subject to certain constraints and costs:

### Resource Access Limit

| Aspect | Constraint |
| --- | --- |
| Access Restrictions | Limited access to resources like account balance and application state to ensure efficient block evaluation. |
| Specification Requirement | Resources must be specified within the transaction for nodes to pre-fetch data. |

### Access Constraints

| Access Type | Constraint |
| --- | --- |
| Block Information | Programs cannot access information from previous blocks. |
| Transaction Information | Cannot access other transactions in the current block unless part of the same atomic transaction group. |

### Logic Signatures

| Parameter | Constraint |
| --- | --- |
| Transaction Commitment | Cannot determine the exact round or time of transaction commitment. |
| Stateless Programs | Cannot query account balances or asset holdings. Transactions must comply with standard accounting rules and may fail if rules are violated. |

## AVM Environment

| Parameter | Constraint |
| --- | --- |
| Indirect Jumps | Not supported; all jumps must reference specific addresses. |

## Storage Constraints

| Storage Structure | Key Length | Value Length | Unique Key Requirement | Additional Details | Safety from Unexpected Deletion |
| --- | --- | --- | --- | --- | --- |
| Local State Storage | Up to 64 bytes | Key + value ≤ 128 bytes | Yes | Larger datasets require partitioning | Not Safe — Can be cleared by users at any time using ClearState transactions |
| Box Storage | 1 to 64 bytes | Up to 32KB (32,768 bytes) | Yes | Key does not contribute to box size and values > 1,024 bytes need additional references | Boxes persist after app deletion but lock the minimum balance if not deleted beforehand |
| Global State Storage | Up to 64 bytes | Key + value ≤ 128 bytes | Yes | Larger datasets require partitioning | Safe — Deleted only with the application; otherwise, data is safe from unexpected deletion |
