|
| 1 | +// Copyright (C) 2019-2025 Algorand, Inc. |
| 2 | +// This file is part of go-algorand |
| 3 | +// |
| 4 | +// go-algorand is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Affero General Public License as |
| 6 | +// published by the Free Software Foundation, either version 3 of the |
| 7 | +// License, or (at your option) any later version. |
| 8 | +// |
| 9 | +// go-algorand is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Affero General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Affero General Public License |
| 15 | +// along with go-algorand. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package bounds |
| 18 | + |
| 19 | +/* The bounds package is intended to hold conservative bounds on the sizes of |
| 20 | + various messages. Many cannot be static, because they depend on consensus |
| 21 | + parameters. They are set at runtime iterating over every consensus version |
| 22 | + and selecting the largest bound. This allows msgpack parsing to safely |
| 23 | + reject anything that NO consensus version would allow. |
| 24 | +*/ |
| 25 | + |
| 26 | +// MaxVoteThreshold is the largest threshold for a bundle over all supported |
| 27 | +// consensus protocols, used for decoding purposes. |
| 28 | +var MaxVoteThreshold int |
| 29 | + |
| 30 | +// MaxEvalDeltaAccounts is the largest number of accounts that may appear in an |
| 31 | +// eval delta, used for decoding purposes. |
| 32 | +var MaxEvalDeltaAccounts int |
| 33 | + |
| 34 | +// MaxStateDeltaKeys is the largest number of key/value pairs that may appear in |
| 35 | +// a StateDelta, used for decoding purposes. |
| 36 | +var MaxStateDeltaKeys int |
| 37 | + |
| 38 | +// MaxLogCalls is the highest allowable log messages that may appear in any |
| 39 | +// version, used only for decoding purposes. Never decrease this value. |
| 40 | +var MaxLogCalls int |
| 41 | + |
| 42 | +// MaxInnerTransactionsPerDelta is the maximum number of inner transactions in |
| 43 | +// one EvalDelta |
| 44 | +var MaxInnerTransactionsPerDelta int |
| 45 | + |
| 46 | +// MaxLogicSigMaxSize is the largest logical signature appear in any of the |
| 47 | +// supported protocols, used for decoding purposes. |
| 48 | +var MaxLogicSigMaxSize int |
| 49 | + |
| 50 | +// MaxTxnNoteBytes is the largest supported nodes field array size supported by |
| 51 | +// any of the consensus protocols. used for decoding purposes. |
| 52 | +var MaxTxnNoteBytes int |
| 53 | + |
| 54 | +// MaxTxGroupSize is the largest supported number of transactions per |
| 55 | +// transaction group supported by any of the consensus protocols. used for |
| 56 | +// decoding purposes. |
| 57 | +var MaxTxGroupSize int |
| 58 | + |
| 59 | +// MaxAppProgramLen is the largest supported app program size supported by any |
| 60 | +// of the consensus protocols. used for decoding purposes. |
| 61 | +var MaxAppProgramLen int |
| 62 | + |
| 63 | +// MaxBytesKeyValueLen is a maximum length of key or value across all protocols. |
| 64 | +// used for decoding purposes. |
| 65 | +var MaxBytesKeyValueLen int |
| 66 | + |
| 67 | +// MaxExtraAppProgramLen is the maximum extra app program length supported by |
| 68 | +// any of the consensus protocols. used for decoding purposes. |
| 69 | +var MaxExtraAppProgramLen int |
| 70 | + |
| 71 | +// MaxAvailableAppProgramLen is the largest supported app program size including |
| 72 | +// the extra pages supported by any of the consensus protocols. used for |
| 73 | +// decoding purposes. |
| 74 | +var MaxAvailableAppProgramLen int |
| 75 | + |
| 76 | +// MaxProposedExpiredOnlineAccounts is the maximum number of online accounts |
| 77 | +// that a proposer can take offline for having expired voting keys. |
| 78 | +var MaxProposedExpiredOnlineAccounts int |
| 79 | + |
| 80 | +// MaxMarkAbsent is the maximum number of online accounts that a proposer can |
| 81 | +// suspend for not proposing "lately" |
| 82 | +var MaxMarkAbsent int |
| 83 | + |
| 84 | +// MaxAppTotalArgLen is the maximum number of bytes across all arguments of an |
| 85 | +// application max sum([len(arg) for arg in txn.ApplicationArgs]) |
| 86 | +var MaxAppTotalArgLen int |
| 87 | + |
| 88 | +// MaxAssetNameBytes is the maximum asset name length in bytes |
| 89 | +var MaxAssetNameBytes int |
| 90 | + |
| 91 | +// MaxAssetUnitNameBytes is the maximum asset unit name length in bytes |
| 92 | +var MaxAssetUnitNameBytes int |
| 93 | + |
| 94 | +// MaxAssetURLBytes is the maximum asset URL length in bytes |
| 95 | +var MaxAssetURLBytes int |
| 96 | + |
| 97 | +// MaxAppBytesValueLen is the maximum length of a bytes value used in an |
| 98 | +// application's global or local key/value store |
| 99 | +var MaxAppBytesValueLen int |
| 100 | + |
| 101 | +// MaxAppBytesKeyLen is the maximum length of a key used in an application's |
| 102 | +// global or local key/value store |
| 103 | +var MaxAppBytesKeyLen int |
| 104 | + |
| 105 | +// StateProofTopVoters is a bound on how many online accounts get to participate |
| 106 | +// in forming the state proof, by including the top StateProofTopVoters accounts |
| 107 | +// (by normalized balance) into the vector commitment. |
| 108 | +var StateProofTopVoters int |
| 109 | + |
| 110 | +// MaxTxnBytesPerBlock determines the maximum number of bytes that transactions |
| 111 | +// can take up in a block. Specifically, the sum of the lengths of encodings of |
| 112 | +// each transaction in a block must not exceed MaxTxnBytesPerBlock. |
| 113 | +var MaxTxnBytesPerBlock int |
| 114 | + |
| 115 | +// MaxAppTxnForeignApps is the max number of foreign apps per txn across all consensus versions |
| 116 | +var MaxAppTxnForeignApps int |
| 117 | + |
| 118 | +// MaxEvalDeltaTotalLogSize is the maximum size of the sum of all log sizes in a single eval delta. |
| 119 | +const MaxEvalDeltaTotalLogSize = 1024 |
| 120 | + |
| 121 | +// MaxGenesisIDLen is the maximum length of the genesis ID set for purpose of |
| 122 | +// setting allocbounds on structs containing GenesisID and for purposes of |
| 123 | +// calculating MaxSize functions on those types. Current value is larger than |
| 124 | +// the existing network IDs and the ones used in testing |
| 125 | +const MaxGenesisIDLen = 128 |
| 126 | + |
| 127 | +// EncodedMaxAssetsPerAccount is the decoder limit of number of assets stored |
| 128 | +// per account. it's being verified by the unit test |
| 129 | +// TestEncodedAccountAllocationBounds to align with |
| 130 | +// config.Consensus[protocol.ConsensusCurrentVersion].MaxAssetsPerAccount; note |
| 131 | +// that the decoded parameter is used only for protecting the decoder against |
| 132 | +// malicious encoded account data stream. protocol-specific contents would be |
| 133 | +// tested once the decoding is complete. |
| 134 | +const EncodedMaxAssetsPerAccount = 1024 |
| 135 | + |
| 136 | +// EncodedMaxAppLocalStates is the decoder limit for number of opted-in apps in a single account. |
| 137 | +// It is verified in TestEncodedAccountAllocationBounds to align with |
| 138 | +// config.Consensus[protocol.ConsensusCurrentVersion].MaxAppsOptedIn |
| 139 | +const EncodedMaxAppLocalStates = 64 |
| 140 | + |
| 141 | +// EncodedMaxAppParams is the decoder limit for number of created apps in a single account. |
| 142 | +// It is verified in TestEncodedAccountAllocationBounds to align with |
| 143 | +// config.Consensus[protocol.ConsensusCurrentVersion].MaxAppsCreated |
| 144 | +const EncodedMaxAppParams = 64 |
| 145 | + |
| 146 | +// EncodedMaxKeyValueEntries is the decoder limit for the length of a key/value store. |
| 147 | +// It is verified in TestEncodedAccountAllocationBounds to align with |
| 148 | +// config.Consensus[protocol.ConsensusCurrentVersion].MaxLocalSchemaEntries and |
| 149 | +// config.Consensus[protocol.ConsensusCurrentVersion].MaxGlobalSchemaEntries |
| 150 | +const EncodedMaxKeyValueEntries = 1024 |
| 151 | + |
| 152 | +// MaxConsensusVersionLen must be larger than any URL length of any consensus |
| 153 | +// version (which is currently URL+hash=89) |
| 154 | +const MaxConsensusVersionLen = 128 |
0 commit comments