From f256d9d35121aba29357271815a898fcf1b06f09 Mon Sep 17 00:00:00 2001 From: DevOps Service Date: Mon, 22 May 2023 15:19:56 +0000 Subject: [PATCH 1/8] Update the Version, BuildNumber, genesistimestamp.data --- buildnumber.dat | 1 + genesistimestamp.dat | 1 + 2 files changed, 2 insertions(+) create mode 100644 buildnumber.dat create mode 100644 genesistimestamp.dat diff --git a/buildnumber.dat b/buildnumber.dat new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/buildnumber.dat @@ -0,0 +1 @@ +0 diff --git a/genesistimestamp.dat b/genesistimestamp.dat new file mode 100644 index 0000000000..c72c6a7795 --- /dev/null +++ b/genesistimestamp.dat @@ -0,0 +1 @@ +1558657885 From 926306631635aa49739a3122f9d211ec86d2e2ef Mon Sep 17 00:00:00 2001 From: Will Winder Date: Mon, 5 Jun 2023 17:04:25 -0400 Subject: [PATCH 2/8] api: Fix errFailedRetrievingStateDelta response. (#5452) --- daemon/algod/api/server/v2/handlers.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/daemon/algod/api/server/v2/handlers.go b/daemon/algod/api/server/v2/handlers.go index a8699c37c0..05aa4ed913 100644 --- a/daemon/algod/api/server/v2/handlers.go +++ b/daemon/algod/api/server/v2/handlers.go @@ -22,7 +22,6 @@ import ( "encoding/base64" "errors" "fmt" - "github.com/algorand/go-algorand/ledger/eval" "io" "math" "net/http" @@ -46,6 +45,7 @@ import ( "github.com/algorand/go-algorand/data/bookkeeping" "github.com/algorand/go-algorand/data/transactions" "github.com/algorand/go-algorand/data/transactions/logic" + "github.com/algorand/go-algorand/ledger/eval" "github.com/algorand/go-algorand/ledger/ledgercore" "github.com/algorand/go-algorand/ledger/simulation" "github.com/algorand/go-algorand/logging" @@ -1721,7 +1721,7 @@ func (v2 *Handlers) GetLedgerStateDeltaForTransactionGroup(ctx echo.Context, id } delta, err := tracer.GetDeltaForID(idDigest) if err != nil { - return notFound(ctx, err, errFailedRetrievingStateDelta, v2.Log) + return notFound(ctx, err, fmt.Sprintf(errFailedRetrievingStateDelta, err), v2.Log) } data, err := encode(handle, delta) if err != nil { @@ -1743,7 +1743,7 @@ func (v2 *Handlers) GetTransactionGroupLedgerStateDeltasForRound(ctx echo.Contex } deltas, err := tracer.GetDeltasForRound(basics.Round(round)) if err != nil { - return notFound(ctx, err, errFailedRetrievingStateDelta, v2.Log) + return notFound(ctx, err, fmt.Sprintf(errFailedRetrievingStateDelta, err), v2.Log) } response := struct { Deltas []eval.TxnGroupDeltaWithIds From 4e99d62a842fd07b59d6f259aef9c03472ed50a9 Mon Sep 17 00:00:00 2001 From: John Lee Date: Tue, 6 Jun 2023 11:58:54 -0400 Subject: [PATCH 3/8] Bump buildnumber.dat. --- buildnumber.dat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildnumber.dat b/buildnumber.dat index 573541ac97..d00491fd7e 100644 --- a/buildnumber.dat +++ b/buildnumber.dat @@ -1 +1 @@ -0 +1 From 01a8931305591242dc476d0294c304ffa287b202 Mon Sep 17 00:00:00 2001 From: Pavel Zbitskiy <65323360+algorandskiy@users.noreply.github.com> Date: Wed, 7 Jun 2023 14:07:34 -0400 Subject: [PATCH 4/8] algod: adjust numeric version encoding (#5457) --- config/version.go | 2 +- config/version_test.go | 60 ++++++++++++++++++++++++++++++++++++++++ util/s3/s3Helper_test.go | 1 + 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 config/version_test.go diff --git a/config/version.go b/config/version.go index e4c5f57df8..2e274a552d 100644 --- a/config/version.go +++ b/config/version.go @@ -72,7 +72,7 @@ func (v Version) AsUInt64() (versionInfo uint64) { versionInfo = uint64(v.Major) versionInfo <<= 16 versionInfo |= uint64(v.Minor) - versionInfo <<= 16 + versionInfo <<= 24 versionInfo |= uint64(v.BuildNumber) return } diff --git a/config/version_test.go b/config/version_test.go new file mode 100644 index 0000000000..1a37cf185b --- /dev/null +++ b/config/version_test.go @@ -0,0 +1,60 @@ +// Copyright (C) 2019-2023 Algorand, Inc. +// This file is part of go-algorand +// +// go-algorand is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// go-algorand is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with go-algorand. If not, see . + +package config + +import ( + "fmt" + "testing" + + "github.com/algorand/go-algorand/test/partitiontest" + "github.com/algorand/go-algorand/util/s3" + "github.com/stretchr/testify/require" +) + +func TestAlgodVsUpdatedVersions(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() + + tests := []struct { + major int + minor int + build int + }{ + {major: 1, minor: 1, build: 32111}, + {major: 2, minor: 0, build: 0}, + {major: 3, minor: 13, build: 170018}, + {major: 3, minor: 15, build: 157}, + {major: 3, minor: 16, build: 0}, + {major: 3, minor: 16, build: 100}, + } + + for _, tt := range tests { + t.Run(fmt.Sprintf("%d.%d.%d", tt.major, tt.minor, tt.build), func(t *testing.T) { + version := Version{Major: tt.major, Minor: tt.minor, BuildNumber: tt.build} + str := version.String() + ver, err := s3.GetVersionFromName("_" + str) + require.NoError(t, err) + require.Equal(t, version.AsUInt64(), ver) + major, minor, patch, err := s3.GetVersionPartsFromVersion(ver) + require.NoError(t, err) + require.Equal(t, uint64(tt.major), major) + require.Equal(t, uint64(tt.minor), minor) + require.Equal(t, uint64(tt.build), patch) + + }) + } +} diff --git a/util/s3/s3Helper_test.go b/util/s3/s3Helper_test.go index 89cf091881..8ba636c2a1 100644 --- a/util/s3/s3Helper_test.go +++ b/util/s3/s3Helper_test.go @@ -231,6 +231,7 @@ func TestGetPartsFromVersion(t *testing.T) { {name: "test 4 (minor)", version: 1*1<<40 + 2*1<<24, expMajor: 1, expMinor: 2, expPatch: 0}, {name: "test 5 (patch)", version: 1*1<<40 + 1, expMajor: 1, expMinor: 0, expPatch: 1}, {name: "test 6 (patch)", version: 1*1<<40 + 2, expMajor: 1, expMinor: 0, expPatch: 2}, + {name: "test 6 (patch)", version: 3298803318784, expMajor: 3, expMinor: 16, expPatch: 0}, } for _, test := range tests { From dfda9e9f8231c55adb2a9d9a64d15e9807af202b Mon Sep 17 00:00:00 2001 From: chris erway Date: Tue, 6 Jun 2023 12:51:18 -0400 Subject: [PATCH 5/8] eval: update endOfBlock --- ledger/eval/eval.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ledger/eval/eval.go b/ledger/eval/eval.go index 914d7cdca2..0607f5a384 100644 --- a/ledger/eval/eval.go +++ b/ledger/eval/eval.go @@ -1323,8 +1323,30 @@ func (eval *BlockEvaluator) endOfBlock() error { if !eval.block.StateProofTracking[protocol.StateProofBasic].StateProofVotersCommitment.IsEqual(expectedVoters) { return fmt.Errorf("StateProofVotersCommitment wrong: %v != %v", eval.block.StateProofTracking[protocol.StateProofBasic].StateProofVotersCommitment, expectedVoters) } - if eval.block.StateProofTracking[protocol.StateProofBasic].StateProofOnlineTotalWeight != expectedVotersWeight { - return fmt.Errorf("StateProofOnlineTotalWeight wrong: %v != %v", eval.block.StateProofTracking[protocol.StateProofBasic].StateProofOnlineTotalWeight, expectedVotersWeight) + if eval.proto.ExcludeExpiredCirculation { + if eval.block.StateProofTracking[protocol.StateProofBasic].StateProofOnlineTotalWeight != expectedVotersWeight { + return fmt.Errorf("StateProofOnlineTotalWeight wrong: %v != %v", eval.block.StateProofTracking[protocol.StateProofBasic].StateProofOnlineTotalWeight, expectedVotersWeight) + } + } else { + if eval.block.StateProofTracking[protocol.StateProofBasic].StateProofOnlineTotalWeight != expectedVotersWeight { + actualVotersWeight := eval.block.StateProofTracking[protocol.StateProofBasic].StateProofOnlineTotalWeight + var highWeight, lowWeight basics.MicroAlgos + if expectedVotersWeight.LessThan(actualVotersWeight) { + highWeight = actualVotersWeight + lowWeight = expectedVotersWeight + } else { + highWeight = expectedVotersWeight + lowWeight = actualVotersWeight + } + const stakeDiffusionFactor = 5 + allowedDelta, overflowed := basics.Muldiv(expectedVotersWeight.Raw, stakeDiffusionFactor, 100) + if overflowed { + return fmt.Errorf("StateProofOnlineTotalWeight overflow: %v != %v", actualVotersWeight, expectedVotersWeight) + } + if (highWeight.Raw - lowWeight.Raw) > allowedDelta { + return fmt.Errorf("StateProofOnlineTotalWeight wrong: %v != %v greater than %d", actualVotersWeight, expectedVotersWeight, allowedDelta) + } + } } if eval.block.StateProofTracking[protocol.StateProofBasic].StateProofNextRound != eval.state.GetStateProofNextRound() { return fmt.Errorf("StateProofNextRound wrong: %v != %v", eval.block.StateProofTracking[protocol.StateProofBasic].StateProofNextRound, eval.state.GetStateProofNextRound()) From 72d2d375f0e5cf4b92d21acc277091bd4fecb43e Mon Sep 17 00:00:00 2001 From: John Jannotti Date: Wed, 14 Jun 2023 11:26:32 -0400 Subject: [PATCH 6/8] AVM: proper cross product check for app put and del (#5467) --- data/transactions/logic/eval.go | 16 ++++++++- data/transactions/logic/evalStateful_test.go | 4 +++ data/transactions/logic/resources_test.go | 36 ++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/data/transactions/logic/eval.go b/data/transactions/logic/eval.go index e5e55525e5..4fe94f80f9 100644 --- a/data/transactions/logic/eval.go +++ b/data/transactions/logic/eval.go @@ -4590,6 +4590,13 @@ func opAppLocalPut(cx *EvalContext) error { return err } + // The version check is overkill, but makes very clear we don't change old + // programs. The test here is to ensure that we didn't get access to the + // address from another txn, but don't have access to the local state. + if cx.version >= sharedResourcesVersion && !cx.allowsLocals(addr, cx.appID) { + return fmt.Errorf("unavailable Local State %s x %d", addr, cx.appID) + } + // if writing the same value, don't record in EvalDelta, matching ledger // behavior with previous BuildEvalDelta mechanism etv, ok, err := cx.Ledger.GetLocal(addr, cx.appID, key, accountIdx) @@ -4678,6 +4685,13 @@ func opAppLocalDel(cx *EvalContext) error { return err } + // The version check is overkill, but makes very clear we don't change old + // programs. The test here is to ensure that we didn't get access to the + // address from another txn, but don't have access to the local state. + if cx.version >= sharedResourcesVersion && !cx.allowsLocals(addr, cx.appID) { + return fmt.Errorf("unavailable Local State %s x %d", addr, cx.appID) + } + // if deleting a non-existent value, don't record in EvalDelta, matching // ledger behavior with previous BuildEvalDelta mechanism if _, ok, err := cx.Ledger.GetLocal(addr, cx.appID, key, accountIdx); ok { @@ -4792,7 +4806,7 @@ func (cx *EvalContext) resolveApp(ref uint64) (aid basics.AppIndex, err error) { // and the App, taking access rules into account. It has the funny side job of // also reporting which "slot" the address appears in, if it is in txn.Accounts // (or is the Sender, which yields 0). But it only needs to do this funny side -// job in certainly old versions that need the slot index while doing a lookup. +// job in certain old versions that need the slot index while doing a lookup. func (cx *EvalContext) localsReference(account stackValue, ref uint64) (basics.Address, basics.AppIndex, uint64, error) { if cx.version >= sharedResourcesVersion { addr, _, err := cx.resolveAccount(account) diff --git a/data/transactions/logic/evalStateful_test.go b/data/transactions/logic/evalStateful_test.go index 3899cdaebb..90e0c38632 100644 --- a/data/transactions/logic/evalStateful_test.go +++ b/data/transactions/logic/evalStateful_test.go @@ -446,6 +446,10 @@ func testAppsBytes(t *testing.T, programs [][]byte, ep *EvalParams, expected ... } else { testAppFull(t, program, i, appID, ep) } + } else { + if len(expected) > 0 && expected[0].l == i { + require.Failf(t, "testAppsBytes used incorrectly.", "No error can happen in txn %d. Not an app.", i) + } } } } diff --git a/data/transactions/logic/resources_test.go b/data/transactions/logic/resources_test.go index 4437f11837..d0112d9ac7 100644 --- a/data/transactions/logic/resources_test.go +++ b/data/transactions/logic/resources_test.go @@ -58,6 +58,12 @@ func TestAppSharing(t *testing.T) { Sender: basics.Address{1, 2, 3, 4}, } + pay1 := txntest.Txn{ + Type: protocol.PaymentTx, + Sender: basics.Address{5, 5, 5, 5}, + Receiver: basics.Address{6, 6, 6, 6}, + } + getSchema := "int 500; app_params_get AppGlobalNumByteSlice; !; assert; pop; int 1" // In v8, the first tx can read app params of 500, because it's in its // foreign array, but the second can't @@ -127,6 +133,11 @@ func TestAppSharing(t *testing.T) { noop := `int 1` sources := []string{noop, putLocal} appl1.ApplicationArgs = [][]byte{appl0.Sender[:]} // tx1 will try to modify local state exposed in tx0 + // appl0.Sender is available, but 901's local state for it isn't (only 900 is, since 900 was called in tx0) + logic.TestApps(t, sources, txntest.Group(&appl0, &appl1), 9, ledger, + logic.Exp(1, "unavailable Local State "+appl0.Sender.String())) + // Add 901 to tx0's ForeignApps, and it works + appl0.ForeignApps = append(appl0.ForeignApps, 901) // well, it will after we opt in logic.TestApps(t, sources, txntest.Group(&appl0, &appl1), 9, ledger, logic.Exp(1, "account "+appl0.Sender.String()+" is not opted into 901")) ledger.NewLocals(appl0.Sender, 901) // opt in @@ -153,6 +164,31 @@ func TestAppSharing(t *testing.T) { sources = []string{"", "", "gtxn 1 Accounts 1; gtxn 0 Applications 0; byte 0xAA; app_local_get_ex"} logic.TestApps(t, sources, txntest.Group(&appl0, &appl1, &appl2), 9, nil, logic.Exp(2, "unavailable Local State")) // note that the error message is for Locals, not specialized + + // try to do a put on local state of the account in tx1, but tx0 ought not have access to that local state + ledger.NewAccount(pay1.Receiver, 200_000) + ledger.NewLocals(pay1.Receiver, 900) // opt in + sources = []string{`gtxn 1 Receiver; byte "key"; byte "val"; app_local_put; int 1`} + logic.TestApps(t, sources, txntest.Group(&appl0, &pay1), 9, ledger, + logic.Exp(0, "unavailable Local State "+pay1.Receiver.String())) + + // same for app_local_del + sources = []string{`gtxn 1 Receiver; byte "key"; app_local_del; int 1`} + logic.TestApps(t, sources, txntest.Group(&appl0, &pay1), 9, ledger, + logic.Exp(0, "unavailable Local State "+pay1.Receiver.String())) + + // now, use an app call in tx1, with 900 in the foreign apps, so the local state is available + appl1.ForeignApps = append(appl1.ForeignApps, 900) + ledger.NewLocals(appl1.Sender, 900) // opt in + sources = []string{`gtxn 1 Sender; byte "key"; byte "val"; app_local_put; int 1`} + logic.TestApps(t, sources, txntest.Group(&appl0, &appl1), 9, ledger) + logic.TestApps(t, sources, txntest.Group(&appl0, &appl1), 8, ledger, // 8 doesn't share the account + logic.Exp(0, "invalid Account reference "+appl1.Sender.String())) + // same for app_local_del + sources = []string{`gtxn 1 Sender; byte "key"; app_local_del; int 1`} + logic.TestApps(t, sources, txntest.Group(&appl0, &appl1), 9, ledger) + logic.TestApps(t, sources, txntest.Group(&appl0, &appl1), 8, ledger, // 8 doesn't share the account + logic.Exp(0, "invalid Account reference "+appl1.Sender.String())) } // TestBetterLocalErrors confirms that we get specific errors about the missing From 3d2a628bcc92b08da12795b8e76161f2bc9d1fc4 Mon Sep 17 00:00:00 2001 From: John Lee Date: Wed, 14 Jun 2023 11:39:08 -0400 Subject: [PATCH 7/8] Bump buildnumber.dat --- buildnumber.dat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildnumber.dat b/buildnumber.dat index d00491fd7e..0cfbf08886 100644 --- a/buildnumber.dat +++ b/buildnumber.dat @@ -1 +1 @@ -1 +2 From 9d425e33c23b4a5cba29bf8e730208ef8ad95974 Mon Sep 17 00:00:00 2001 From: DevOps Service Date: Tue, 20 Jun 2023 15:42:31 +0000 Subject: [PATCH 8/8] Bump Version, Remove buildnumber.dat and genesistimestamp.dat files. --- buildnumber.dat | 1 - config/version.go | 2 +- genesistimestamp.dat | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 buildnumber.dat delete mode 100644 genesistimestamp.dat diff --git a/buildnumber.dat b/buildnumber.dat deleted file mode 100644 index 0cfbf08886..0000000000 --- a/buildnumber.dat +++ /dev/null @@ -1 +0,0 @@ -2 diff --git a/config/version.go b/config/version.go index 2e274a552d..c99256a2f4 100644 --- a/config/version.go +++ b/config/version.go @@ -33,7 +33,7 @@ const VersionMajor = 3 // VersionMinor is the Minor semantic version number (x.#.z) - changed when backwards-compatible features are introduced. // Not enforced until after initial public release (x > 0). -const VersionMinor = 16 +const VersionMinor = 17 // Version is the type holding our full version information. type Version struct { diff --git a/genesistimestamp.dat b/genesistimestamp.dat deleted file mode 100644 index c72c6a7795..0000000000 --- a/genesistimestamp.dat +++ /dev/null @@ -1 +0,0 @@ -1558657885