Skip to content

Commit 43cb563

Browse files
authored
AVM: Provide access to some more block header values (#6107)
1 parent 0da0e99 commit 43cb563

File tree

13 files changed

+86
-26
lines changed

13 files changed

+86
-26
lines changed

data/transactions/logic/TEAL_opcodes_v10.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ Fields
16381638

16391639
| Index | Name | Type | Notes |
16401640
| - | ------ | -- | --------- |
1641-
| 0 | BlkSeed | []byte | |
1641+
| 0 | BlkSeed | [32]byte | |
16421642
| 1 | BlkTimestamp | uint64 | |
16431643

16441644

data/transactions/logic/TEAL_opcodes_v7.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,6 @@ Fields
14761476

14771477
| Index | Name | Type | Notes |
14781478
| - | ------ | -- | --------- |
1479-
| 0 | BlkSeed | []byte | |
1479+
| 0 | BlkSeed | [32]byte | |
14801480
| 1 | BlkTimestamp | uint64 | |
14811481

data/transactions/logic/TEAL_opcodes_v8.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,6 @@ Fields
16351635

16361636
| Index | Name | Type | Notes |
16371637
| - | ------ | -- | --------- |
1638-
| 0 | BlkSeed | []byte | |
1638+
| 0 | BlkSeed | [32]byte | |
16391639
| 1 | BlkTimestamp | uint64 | |
16401640

data/transactions/logic/TEAL_opcodes_v9.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,6 @@ Fields
16351635

16361636
| Index | Name | Type | Notes |
16371637
| - | ------ | -- | --------- |
1638-
| 0 | BlkSeed | []byte | |
1638+
| 0 | BlkSeed | [32]byte | |
16391639
| 1 | BlkTimestamp | uint64 | |
16401640

data/transactions/logic/assembler_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,11 +1700,21 @@ global AssetCreateMinBalance
17001700
global AssetOptInMinBalance
17011701
global GenesisHash
17021702
pushint 1
1703+
block BlkBranch
1704+
pushint 1
1705+
block BlkFeeSink
1706+
pushint 1
1707+
block BlkProtocol
1708+
pushint 1
1709+
block BlkTxnCounter
1710+
pushint 1
17031711
block BlkProposer
17041712
pushint 1
17051713
block BlkFeesCollected
17061714
pushint 1
17071715
block BlkBonus
1716+
pushint 1
1717+
block BlkProposerPayout
17081718
global PayoutsEnabled
17091719
global PayoutsGoOnlineFee
17101720
global PayoutsPercent

data/transactions/logic/eval.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5771,12 +5771,24 @@ func opBlock(cx *EvalContext) error {
57715771
return fmt.Errorf("block(%d) timestamp %d < 0", round, hdr.TimeStamp)
57725772
}
57735773
cx.Stack[last] = stackValue{Uint: uint64(hdr.TimeStamp)}
5774+
5775+
case BlkBranch:
5776+
cx.Stack[last].Bytes = hdr.Branch[:]
5777+
case BlkFeeSink:
5778+
cx.Stack[last].Bytes = hdr.FeeSink[:]
5779+
case BlkProtocol:
5780+
cx.Stack[last].Bytes = []byte(hdr.CurrentProtocol)
5781+
case BlkTxnCounter:
5782+
cx.Stack[last] = stackValue{Uint: hdr.TxnCounter}
5783+
57745784
case BlkProposer:
57755785
cx.Stack[last].Bytes = hdr.Proposer[:]
57765786
case BlkFeesCollected:
57775787
cx.Stack[last] = stackValue{Uint: hdr.FeesCollected.Raw}
57785788
case BlkBonus:
57795789
cx.Stack[last] = stackValue{Uint: hdr.Bonus.Raw}
5790+
case BlkProposerPayout:
5791+
cx.Stack[last] = stackValue{Uint: hdr.ProposerPayout.Raw}
57805792
default:
57815793
return fmt.Errorf("invalid block field %s", fs.field)
57825794
}

data/transactions/logic/fields.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,16 @@ const (
997997
BlkFeesCollected
998998
// BlkBonus is the extra amount to be paid for the given block (from FeeSink)
999999
BlkBonus
1000+
// BlkBranch is the hash of the previous block
1001+
BlkBranch
1002+
// BlkFeeSink is the fee sink for the given round
1003+
BlkFeeSink
1004+
// BlkProtocol is the ConsensusVersion of the block.
1005+
BlkProtocol
1006+
// BlkTxnCounter is the number of the next transaction after the block
1007+
BlkTxnCounter
1008+
// BlkProposerPayout is the actual amount moved from feesink to proposer
1009+
BlkProposerPayout
10001010

10011011
invalidBlockField // compile-time constant for number of fields
10021012
)
@@ -1010,11 +1020,16 @@ type blockFieldSpec struct {
10101020
}
10111021

10121022
var blockFieldSpecs = [...]blockFieldSpec{
1013-
{BlkSeed, StackBytes, randomnessVersion},
1023+
{BlkSeed, StackBytes32, randomnessVersion},
10141024
{BlkTimestamp, StackUint64, randomnessVersion},
10151025
{BlkProposer, StackAddress, incentiveVersion},
10161026
{BlkFeesCollected, StackUint64, incentiveVersion},
10171027
{BlkBonus, StackUint64, incentiveVersion},
1028+
{BlkBranch, StackBytes32, incentiveVersion},
1029+
{BlkFeeSink, StackAddress, incentiveVersion},
1030+
{BlkProtocol, StackBytes, incentiveVersion},
1031+
{BlkTxnCounter, StackUint64, incentiveVersion},
1032+
{BlkProposerPayout, StackUint64, incentiveVersion},
10181033
}
10191034

10201035
func blockFieldSpecByField(r BlockField) (blockFieldSpec, bool) {

data/transactions/logic/fields_string.go

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data/transactions/logic/langspec_v10.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4601,7 +4601,7 @@
46014601
"BlkTimestamp"
46024602
],
46034603
"ArgEnumTypes": [
4604-
"[]byte",
4604+
"[32]byte",
46054605
"uint64"
46064606
],
46074607
"DocCost": "1",

data/transactions/logic/langspec_v7.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4249,7 +4249,7 @@
42494249
"BlkTimestamp"
42504250
],
42514251
"ArgEnumTypes": [
4252-
"[]byte",
4252+
"[32]byte",
42534253
"uint64"
42544254
],
42554255
"DocCost": "1",

0 commit comments

Comments
 (0)