Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into rename-internal-eval
Browse files Browse the repository at this point in the history
  • Loading branch information
cce committed Jul 21, 2022
2 parents f22768d + 2a933eb commit b529186
Show file tree
Hide file tree
Showing 34 changed files with 848 additions and 408 deletions.
2 changes: 1 addition & 1 deletion cmd/opdoc/opdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func buildLanguageSpec(opGroups map[string][]string) *LanguageSpec {
records[i].Returns = typeString(spec.Return.Types)
records[i].Size = spec.OpDetails.Size
records[i].ArgEnum, records[i].ArgEnumTypes = argEnums(spec.Name)
records[i].Doc = logic.OpDoc(spec.Name)
records[i].Doc = strings.ReplaceAll(logic.OpDoc(spec.Name), "<br />", "\n")
records[i].DocExtra = logic.OpDocExtra(spec.Name)
records[i].ImmediateNote = logic.OpImmediateNote(spec.Name)
records[i].Groups = opGroups[spec.Name]
Expand Down
2 changes: 1 addition & 1 deletion cmd/tealdbg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Local debugger supports setting the execution context: consensus protocol, trans

### Protocol

Used to determine execution parameters and limits such as TEAL version, max program size and cost and so on.
Used to determine execution parameters and limits such as program version, max program size and cost and so on.
```
$ tealdbg debug --proto https://github.com/algorandfoundation/specs/tree/e5f565421d720c6f75cdd186f7098495caf9101f
$ tealdbg debug --proto future
Expand Down
10 changes: 10 additions & 0 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,14 @@ type ConsensusParams struct {

// EnableOnlineAccountCatchpoints specifies when to re-enable catchpoints after the online account table migration has occurred.
EnableOnlineAccountCatchpoints bool

// UnfundedSenders ensures that accounts with no balance (so they don't even
// "exist") can still be a transaction sender by avoiding updates to rewards
// state for accounts with no algos. The actual change implemented to allow
// this is to avoid updating an account if the only change would have been
// the rewardsLevel, but the rewardsLevel has no meaning because the account
// has fewer than RewardUnit algos.
UnfundedSenders bool
}

// PaysetCommitType enumerates possible ways for the block header to commit to
Expand Down Expand Up @@ -1168,6 +1176,8 @@ func initConsensusProtocols() {
vFuture.EnableSHA256TxnCommitmentHeader = true
vFuture.EnableOnlineAccountCatchpoints = true

vFuture.UnfundedSenders = true

Consensus[protocol.ConsensusFuture] = vFuture
}

Expand Down
3 changes: 1 addition & 2 deletions data/account/participationRegistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ import (
"fmt"
"time"

"github.com/algorand/go-deadlock"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/crypto/merklesignature"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/util/db"
"github.com/algorand/go-deadlock"
)

const defaultTimeout = 5 * time.Second
Expand Down
13 changes: 11 additions & 2 deletions data/accountManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,20 @@ func (manager *AccountManager) HasLiveKeys(from, to basics.Round) bool {
// AddParticipation adds a new account.Participation to be managed.
// The return value indicates if the key has been added (true) or
// if this is a duplicate key (false).
func (manager *AccountManager) AddParticipation(participation account.PersistedParticipation) bool {
// if ephemeral is true then the key is not stored in the internal hashmap and
// will not be deleted by DeleteOldKeys()
func (manager *AccountManager) AddParticipation(participation account.PersistedParticipation, ephemeral bool) bool {
// Tell the ParticipationRegistry about the Participation. Duplicate entries
// are ignored.
pid, err := manager.registry.Insert(participation.Participation)
if err != nil && err != account.ErrAlreadyInserted {
manager.log.Warnf("Failed to insert participation key.")
}

if err == account.ErrAlreadyInserted {
return false
}

manager.log.Infof("Inserted key (%s) for account (%s) first valid (%d) last valid (%d)\n",
pid, participation.Parent, participation.FirstValid, participation.LastValid)

Expand All @@ -129,7 +136,9 @@ func (manager *AccountManager) AddParticipation(participation account.PersistedP
return false
}

manager.partKeys[partkeyID] = participation
if !ephemeral {
manager.partKeys[partkeyID] = participation
}

addressString := address.String()
manager.log.EventWithDetails(telemetryspec.Accounts, telemetryspec.PartKeyRegisteredEvent, telemetryspec.PartKeyRegisteredEventDetails{
Expand Down
3 changes: 2 additions & 1 deletion data/accountManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ func testAccountManagerKeys(t *testing.T, registry account.ParticipationRegistry
databaseFiles = append(databaseFiles, rootFilename)
databaseFiles = append(databaseFiles, partFilename)

acctManager.AddParticipation(part)
// Not ephemeral to be backwards compatible with the test
acctManager.AddParticipation(part, false)
}
if _, mocked := acctManager.Registry().(*mocks.MockParticipationRegistry); !mocked {
require.Len(t, acctManager.Keys(basics.Round(1)), numPartKeys, "incorrect number of keys, can happen if test crashes and leaves SQLite files")
Expand Down
31 changes: 16 additions & 15 deletions data/basics/userBalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,22 +436,23 @@ func PendingRewards(ot *OverflowTracker, proto config.ConsensusParams, microAlgo
func WithUpdatedRewards(
proto config.ConsensusParams, status Status, microAlgosIn MicroAlgos, rewardedMicroAlgosIn MicroAlgos, rewardsBaseIn uint64, rewardsLevelIn uint64,
) (MicroAlgos, MicroAlgos, uint64) {
if status != NotParticipating {
var ot OverflowTracker
rewardsUnits := microAlgosIn.RewardUnits(proto)
rewardsDelta := ot.Sub(rewardsLevelIn, rewardsBaseIn)
rewards := MicroAlgos{Raw: ot.Mul(rewardsUnits, rewardsDelta)}
microAlgosOut := ot.AddA(microAlgosIn, rewards)
if ot.Overflowed {
logging.Base().Panicf("AccountData.WithUpdatedRewards(): overflowed account balance when applying rewards %v + %d*(%d-%d)", microAlgosIn, rewardsUnits, rewardsLevelIn, rewardsBaseIn)
}
rewardsBaseOut := rewardsLevelIn
// The total reward over the lifetime of the account could exceed a 64-bit value. As a result
// this rewardAlgos counter could potentially roll over.
rewardedMicroAlgosOut := MicroAlgos{Raw: rewardedMicroAlgosIn.Raw + rewards.Raw}
return microAlgosOut, rewardedMicroAlgosOut, rewardsBaseOut
if status == NotParticipating {
return microAlgosIn, rewardedMicroAlgosIn, rewardsBaseIn
}
return microAlgosIn, rewardedMicroAlgosIn, rewardsBaseIn

var ot OverflowTracker
rewardsUnits := microAlgosIn.RewardUnits(proto)
rewardsDelta := ot.Sub(rewardsLevelIn, rewardsBaseIn)
rewards := MicroAlgos{Raw: ot.Mul(rewardsUnits, rewardsDelta)}
microAlgosOut := ot.AddA(microAlgosIn, rewards)
if ot.Overflowed {
logging.Base().Panicf("AccountData.WithUpdatedRewards(): overflowed account balance when applying rewards %v + %d*(%d-%d)", microAlgosIn, rewardsUnits, rewardsLevelIn, rewardsBaseIn)
}
rewardsBaseOut := rewardsLevelIn
// The total reward over the lifetime of the account could exceed a 64-bit value. As a result
// this rewardAlgos counter could potentially roll over.
rewardedMicroAlgosOut := MicroAlgos{Raw: rewardedMicroAlgosIn.Raw + rewards.Raw}
return microAlgosOut, rewardedMicroAlgosOut, rewardsBaseOut
}

// WithUpdatedRewards returns an updated number of algos in an AccountData
Expand Down
42 changes: 22 additions & 20 deletions data/transactions/logic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ programs, AVM code is versioned. When new opcodes are introduced, or
behavior is changed, a new version is introduced. Programs carrying
old versions are executed with their original semantics. In the AVM
bytecode, the version is an incrementing integer, currently 6, and
denoted vX throughout this document. User friendly version numbers
that correspond to programmer expectations, such as `AVM 1.0` map to
these integers. AVM 0.9 is v4. AVM 1.0 is v5. AVM 1.1 is v6.
denoted vX throughout this document.

## Execution Modes

Expand Down Expand Up @@ -323,12 +321,12 @@ return stack matches the name of the input value.
| `substring s e` | A range of bytes from A starting at S up to but not including E. If E < S, or either is larger than the array length, the program fails |
| `substring3` | A range of bytes from A starting at B up to but not including C. If C < B, or either is larger than the array length, the program fails |
| `extract s l` | A range of bytes from A starting at S up to but not including S+L. If L is 0, then extract to the end of the string. If S or S+L is larger than the array length, the program fails |
| `extract3` | A range of bytes from A starting at B up to but not including B+C. If B+C is larger than the array length, the program fails |
| `extract3` | A range of bytes from A starting at B up to but not including B+C. If B+C is larger than the array length, the program fails<br />`extract3` can be called using `extract` with no immediates. |
| `extract_uint16` | A uint16 formed from a range of big-endian bytes from A starting at B up to but not including B+2. If B+2 is larger than the array length, the program fails |
| `extract_uint32` | A uint32 formed from a range of big-endian bytes from A starting at B up to but not including B+4. If B+4 is larger than the array length, the program fails |
| `extract_uint64` | A uint64 formed from a range of big-endian bytes from A starting at B up to but not including B+8. If B+8 is larger than the array length, the program fails |
| `replace2 s` | Copy of A with the bytes starting at S replaced by the bytes of B. Fails if S+len(B) exceeds len(A) |
| `replace3` | Copy of A with the bytes starting at B replaced by the bytes of C. Fails if B+len(C) exceeds len(A) |
| `replace2 s` | Copy of A with the bytes starting at S replaced by the bytes of B. Fails if S+len(B) exceeds len(A)<br />`replace2` can be called using `replace` with 1 immediate. |
| `replace3` | Copy of A with the bytes starting at B replaced by the bytes of C. Fails if B+len(C) exceeds len(A)<br />`replace3` can be called using `replace` with no immediates. |
| `base64_decode e` | decode A which was base64-encoded using _encoding_ E. Fail if A is not base64 encoded with encoding E |
| `json_ref r` | return key B's value from a [valid](jsonspec.md) utf-8 encoded json object A |

Expand Down Expand Up @@ -403,12 +401,12 @@ Some of these have immediate data in the byte or bytes after the opcode.
| `args` | Ath LogicSig argument |
| `txn f` | field F of current transaction |
| `gtxn t f` | field F of the Tth transaction in the current group |
| `txna f i` | Ith value of the array field F of the current transaction |
| `txna f i` | Ith value of the array field F of the current transaction<br />`txna` can be called using `txn` with 2 immediates. |
| `txnas f` | Ath value of the array field F of the current transaction |
| `gtxna t f i` | Ith value of the array field F from the Tth transaction in the current group |
| `gtxna t f i` | Ith value of the array field F from the Tth transaction in the current group<br />`gtxna` can be called using `gtxn` with 3 immediates. |
| `gtxnas t f` | Ath value of the array field F from the Tth transaction in the current group |
| `gtxns f` | field F of the Ath transaction in the current group |
| `gtxnsa f i` | Ith value of the array field F from the Ath transaction in the current group |
| `gtxnsa f i` | Ith value of the array field F from the Ath transaction in the current group<br />`gtxnsa` can be called using `gtxns` with 2 immediates. |
| `gtxnsas f` | Bth value of the array field F from the Ath transaction in the current group |
| `global f` | global field F |
| `load i` | Ith scratch space value. All scratch spaces are 0 at program start. |
Expand All @@ -421,8 +419,8 @@ Some of these have immediate data in the byte or bytes after the opcode.
| `gaid t` | ID of the asset or application created in the Tth transaction of the current group |
| `gaids` | ID of the asset or application created in the Ath transaction of the current group |

**Transaction Fields**

#### Transaction Fields
##### Scalar Fields
| Index | Name | Type | In | Notes |
| - | ------ | -- | - | --------- |
| 0 | Sender | []byte | | 32 byte address |
Expand Down Expand Up @@ -451,9 +449,7 @@ Some of these have immediate data in the byte or bytes after the opcode.
| 23 | TxID | []byte | | The computed ID for this transaction. 32 bytes. |
| 24 | ApplicationID | uint64 | v2 | ApplicationID from ApplicationCall transaction |
| 25 | OnCompletion | uint64 | v2 | ApplicationCall transaction on completion action |
| 26 | ApplicationArgs | []byte | v2 | Arguments passed to the application in the ApplicationCall transaction |
| 27 | NumAppArgs | uint64 | v2 | Number of ApplicationArgs |
| 28 | Accounts | []byte | v2 | Accounts listed in the ApplicationCall transaction |
| 29 | NumAccounts | uint64 | v2 | Number of Accounts |
| 30 | ApprovalProgram | []byte | v2 | Approval program |
| 31 | ClearStateProgram | []byte | v2 | Clear state program |
Expand All @@ -473,27 +469,33 @@ Some of these have immediate data in the byte or bytes after the opcode.
| 45 | FreezeAsset | uint64 | v2 | Asset ID being frozen or un-frozen |
| 46 | FreezeAssetAccount | []byte | v2 | 32 byte address of the account whose asset slot is being frozen or un-frozen |
| 47 | FreezeAssetFrozen | uint64 | v2 | The new frozen value, 0 or 1 |
| 48 | Assets | uint64 | v3 | Foreign Assets listed in the ApplicationCall transaction |
| 49 | NumAssets | uint64 | v3 | Number of Assets |
| 50 | Applications | uint64 | v3 | Foreign Apps listed in the ApplicationCall transaction |
| 51 | NumApplications | uint64 | v3 | Number of Applications |
| 52 | GlobalNumUint | uint64 | v3 | Number of global state integers in ApplicationCall |
| 53 | GlobalNumByteSlice | uint64 | v3 | Number of global state byteslices in ApplicationCall |
| 54 | LocalNumUint | uint64 | v3 | Number of local state integers in ApplicationCall |
| 55 | LocalNumByteSlice | uint64 | v3 | Number of local state byteslices in ApplicationCall |
| 56 | ExtraProgramPages | uint64 | v4 | Number of additional pages for each of the application's approval and clear state programs. An ExtraProgramPages of 1 means 2048 more total bytes, or 1024 for each program. |
| 57 | Nonparticipation | uint64 | v5 | Marks an account nonparticipating for rewards |
| 58 | Logs | []byte | v5 | Log messages emitted by an application call (only with `itxn` in v5). Application mode only |
| 59 | NumLogs | uint64 | v5 | Number of Logs (only with `itxn` in v5). Application mode only |
| 60 | CreatedAssetID | uint64 | v5 | Asset ID allocated by the creation of an ASA (only with `itxn` in v5). Application mode only |
| 61 | CreatedApplicationID | uint64 | v5 | ApplicationID allocated by the creation of an application (only with `itxn` in v5). Application mode only |
| 62 | LastLog | []byte | v6 | The last message emitted. Empty bytes if none were emitted. Application mode only |
| 63 | StateProofPK | []byte | v6 | 64 byte state proof public key commitment |
| 64 | ApprovalProgramPages | []byte | v7 | Approval Program as an array of pages |
| 65 | NumApprovalProgramPages | uint64 | v7 | Number of Approval Program pages |
| 66 | ClearStateProgramPages | []byte | v7 | ClearState Program as an array of pages |
| 67 | NumClearStateProgramPages | uint64 | v7 | Number of ClearState Program pages |

##### Array Fields
| Index | Name | Type | In | Notes |
| - | ------ | -- | - | --------- |
| 26 | ApplicationArgs | []byte | v2 | Arguments passed to the application in the ApplicationCall transaction |
| 28 | Accounts | []byte | v2 | Accounts listed in the ApplicationCall transaction |
| 48 | Assets | uint64 | v3 | Foreign Assets listed in the ApplicationCall transaction |
| 50 | Applications | uint64 | v3 | Foreign Apps listed in the ApplicationCall transaction |
| 58 | Logs | []byte | v5 | Log messages emitted by an application call (only with `itxn` in v5). Application mode only |
| 64 | ApprovalProgramPages | []byte | v7 | Approval Program as an array of pages |
| 66 | ClearStateProgramPages | []byte | v7 | ClearState Program as an array of pages |


Additional details in the [opcodes document](TEAL_opcodes.md#txn) on the `txn` op.

Expand Down Expand Up @@ -680,7 +682,7 @@ The assembler parses line by line. Ops that only take stack arguments
appear on a line by themselves. Immediate arguments follow the opcode
on the same line, separated by whitespace.

The first line may contain a special version pragma `#pragma version X`, which directs the assembler to generate AVM bytecode targeting a certain version. For instance, `#pragma version 2` produces bytecode targeting TEAL v2. By default, the assembler targets TEAL v1.
The first line may contain a special version pragma `#pragma version X`, which directs the assembler to generate AVM bytecode targeting a certain version. For instance, `#pragma version 2` produces bytecode targeting AVM v2. By default, the assembler targets AVM v1.

Subsequent lines may contain other pragma declarations (i.e., `#pragma <some-specification>`), pertaining to checks that the assembler should perform before agreeing to emit the program bytes, specific optimizations, etc. Those declarations are optional and cannot alter the semantics as described in this document.

Expand Down Expand Up @@ -746,7 +748,7 @@ This requirement is enforced as follows:
all the fields and values in this transaction. For example, a
transaction with a nonzero RekeyTo field will be (at least) v2.

* Compute the largest version number across all the transactions in a group (of size 1 or more), call it `maxVerNo`. If any transaction in this group has a program with a version smaller than `maxVerNo`, then that TEAL program will fail.
* Compute the largest version number across all the transactions in a group (of size 1 or more), call it `maxVerNo`. If any transaction in this group has a program with a version smaller than `maxVerNo`, then that program will fail.

In addition, applications must be version 6 or greater to be eligible
for being called in an inner transaction.
Expand Down
14 changes: 7 additions & 7 deletions data/transactions/logic/README_in.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ programs, AVM code is versioned. When new opcodes are introduced, or
behavior is changed, a new version is introduced. Programs carrying
old versions are executed with their original semantics. In the AVM
bytecode, the version is an incrementing integer, currently 6, and
denoted vX throughout this document. User friendly version numbers
that correspond to programmer expectations, such as `AVM 1.0` map to
these integers. AVM 0.9 is v4. AVM 1.0 is v5. AVM 1.1 is v6.
denoted vX throughout this document.

## Execution Modes

Expand Down Expand Up @@ -277,9 +275,11 @@ Some of these have immediate data in the byte or bytes after the opcode.

@@ Loading_Values.md @@

**Transaction Fields**

#### Transaction Fields
##### Scalar Fields
@@ txn_fields.md @@
##### Array Fields
@@ txna_fields.md @@

Additional details in the [opcodes document](TEAL_opcodes.md#txn) on the `txn` op.

Expand Down Expand Up @@ -370,7 +370,7 @@ The assembler parses line by line. Ops that only take stack arguments
appear on a line by themselves. Immediate arguments follow the opcode
on the same line, separated by whitespace.

The first line may contain a special version pragma `#pragma version X`, which directs the assembler to generate AVM bytecode targeting a certain version. For instance, `#pragma version 2` produces bytecode targeting TEAL v2. By default, the assembler targets TEAL v1.
The first line may contain a special version pragma `#pragma version X`, which directs the assembler to generate AVM bytecode targeting a certain version. For instance, `#pragma version 2` produces bytecode targeting AVM v2. By default, the assembler targets AVM v1.

Subsequent lines may contain other pragma declarations (i.e., `#pragma <some-specification>`), pertaining to checks that the assembler should perform before agreeing to emit the program bytes, specific optimizations, etc. Those declarations are optional and cannot alter the semantics as described in this document.

Expand Down Expand Up @@ -436,7 +436,7 @@ This requirement is enforced as follows:
all the fields and values in this transaction. For example, a
transaction with a nonzero RekeyTo field will be (at least) v2.

* Compute the largest version number across all the transactions in a group (of size 1 or more), call it `maxVerNo`. If any transaction in this group has a program with a version smaller than `maxVerNo`, then that TEAL program will fail.
* Compute the largest version number across all the transactions in a group (of size 1 or more), call it `maxVerNo`. If any transaction in this group has a program with a version smaller than `maxVerNo`, then that program will fail.

In addition, applications must be version 6 or greater to be eligible
for being called in an inner transaction.
Expand Down
Loading

0 comments on commit b529186

Please sign in to comment.