Skip to content

Commit 197cc22

Browse files
committed
Make config.MaxLogCalls dependant on some consensus param
* Commented some constants in teal evaluator and added a test enforcing their values and directing on how to change them if/when needed.
1 parent 58bc231 commit 197cc22

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

config/consensus.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ var MaxEvalDeltaAccounts int
423423
var MaxStateDeltaKeys int
424424

425425
// MaxLogCalls is the highest allowable log messages that may appear in
426-
// any version, used for decoding purposes. Never decrease this value.
427-
const MaxLogCalls = 32
426+
// any version, used only for decoding purposes. Never decrease this value.
427+
var MaxLogCalls int
428428

429429
// MaxLogicSigMaxSize is the largest logical signature appear in any of the supported
430430
// protocols, used for decoding purposes.
@@ -486,6 +486,9 @@ func checkSetAllocBounds(p ConsensusParams) {
486486
checkSetMax(p.MaxExtraAppProgramPages, &MaxExtraAppProgramLen)
487487
// MaxAvailableAppProgramLen is the max of supported app program size
488488
MaxAvailableAppProgramLen = MaxAppProgramLen * (1 + MaxExtraAppProgramLen)
489+
// There is no consensus parameter for MaxLogCalls and MaxAppProgramLen as an approximation
490+
// Its value is much larger than any possible reasonable MaxLogCalls value in future
491+
checkSetMax(p.MaxAppProgramLen, &MaxLogCalls)
489492
}
490493

491494
// SaveConfigurableConsensus saves the configurable protocols file to the provided data directory.

data/transactions/logic/backwardCompat_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,12 @@ done:`
404404
})
405405
}
406406
}
407+
408+
func TestExplicitConstants(t *testing.T) {
409+
partitiontest.PartitionTest(t)
410+
411+
require.Equal(t, 4096, MaxStringSize, "constant changed, move it to consensus params")
412+
require.Equal(t, 64, MaxByteMathSize, "constant changed, move it to consensus params")
413+
require.Equal(t, 1024, MaxLogSize, "constant changed, move it to consensus params")
414+
require.Equal(t, 32, MaxLogCalls, "constant changed, move it to consensus params")
415+
}

data/transactions/logic/eval.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ import (
4444
// EvalMaxVersion is the max version we can interpret and run
4545
const EvalMaxVersion = LogicVersion
4646

47-
// EvalMaxScratchSize is the maximum number of scratch slots.
48-
const EvalMaxScratchSize = 255
47+
// The constants below control TEAL opcodes evaluation and MAY NOT be changed
48+
// without moving them into consensus parameters.
4949

5050
// MaxStringSize is the limit of byte strings created by `concat`
5151
const MaxStringSize = 4096
@@ -57,7 +57,7 @@ const MaxByteMathSize = 64
5757
const MaxLogSize = 1024
5858

5959
// MaxLogCalls is the limit of total log calls during a program execution
60-
const MaxLogCalls = config.MaxLogCalls
60+
const MaxLogCalls = 32
6161

6262
// stackValue is the type for the operand stack.
6363
// Each stackValue is either a valid []byte value or a uint64 value.

data/transactions/logic/eval_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4764,7 +4764,7 @@ func TestLog(t *testing.T) {
47644764
loglen: 2,
47654765
},
47664766
{
4767-
source: fmt.Sprintf(`%s int 1`, strings.Repeat(`byte "a logging message"; log;`, config.MaxLogCalls)),
4767+
source: fmt.Sprintf(`%s int 1`, strings.Repeat(`byte "a logging message"; log;`, MaxLogCalls)),
47684768
loglen: MaxLogCalls,
47694769
},
47704770
{
@@ -4816,7 +4816,7 @@ func TestLog(t *testing.T) {
48164816
runMode: runModeApplication,
48174817
},
48184818
{
4819-
source: fmt.Sprintf(`%s; int 1`, strings.Repeat(`byte "a"; log;`, config.MaxLogCalls+1)),
4819+
source: fmt.Sprintf(`%s; int 1`, strings.Repeat(`byte "a"; log;`, MaxLogCalls+1)),
48204820
errContains: "too many log calls",
48214821
runMode: runModeApplication,
48224822
},

0 commit comments

Comments
 (0)