Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into multiaddr-dns
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Warehime committed Jul 31, 2023
2 parents 5838813 + 1bf7a21 commit a6e67ba
Show file tree
Hide file tree
Showing 48 changed files with 1,356 additions and 1,179 deletions.
2 changes: 1 addition & 1 deletion agreement/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type message struct {

// this field is for backwards compatibility with crash state serialized using go-codec prior to explicit unexport.
// should be removed after the next consensus update.
MessageHandle msgp.Raw
MessageHandle msgp.Raw `codec:"MessageHandle,omitempty"`
// explicitly unexport this field since we can't define serializers for interface{} type
// the only implementation of this is gossip.messageMetadata which doesn't have exported fields to serialize.
messageHandle MessageHandle
Expand Down
2 changes: 2 additions & 0 deletions agreement/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func TestMessageBackwardCompatibility(t *testing.T) {
Tag: protocol.ProposalPayloadTag,
}

require.Containsf(t, string(encoded), "MessageHandle", "encoded message does not contain MessageHandle field")
var m1, m2, m3, m4 message
// Both msgp and reflection should decode the message containing old MessageHandle successfully
err = protocol.Decode(encoded, &m1)
Expand All @@ -123,6 +124,7 @@ func TestMessageBackwardCompatibility(t *testing.T) {
e1 := protocol.Encode(&m1)
e2 := protocol.EncodeReflect(&m2)
require.Equal(t, e1, e2)
require.NotContainsf(t, string(e1), "MessageHandle", "encoded message still contains MessageHandle field")
err = protocol.DecodeReflect(e1, &m3)
require.NoError(t, err)
err = protocol.Decode(e2, &m4)
Expand Down
80 changes: 46 additions & 34 deletions agreement/msgp_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions cmd/goal/clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ var sendCmd = &cobra.Command{
CurrentProtocol: proto,
},
}
groupCtx, err := verify.PrepareGroupContext([]transactions.SignedTxn{uncheckedTxn}, &blockHeader, nil)
groupCtx, err := verify.PrepareGroupContext([]transactions.SignedTxn{uncheckedTxn}, &blockHeader, nil, nil)
if err == nil {
err = verify.LogicSigSanityCheck(0, groupCtx)
}
Expand Down Expand Up @@ -852,7 +852,7 @@ var signCmd = &cobra.Command{
}
var groupCtx *verify.GroupContext
if lsig.Logic != nil {
groupCtx, err = verify.PrepareGroupContext(txnGroup, &contextHdr, nil)
groupCtx, err = verify.PrepareGroupContext(txnGroup, &contextHdr, nil, nil)
if err != nil {
// this error has to be unsupported protocol
reportErrorf("%s: %v", txFilename, err)
Expand Down Expand Up @@ -1124,7 +1124,6 @@ var dryrunCmd = &cobra.Command{
Long: "Test a TEAL program offline under various conditions and verbosity.",
Run: func(cmd *cobra.Command, args []string) {
stxns := decodeTxnsFromFile(txFilename)
txgroup := transactions.WrapSignedTxnsWithAD(stxns)
proto, params := getProto(protoVersion)
if dumpForDryrun {
// Write dryrun data to file
Expand All @@ -1145,15 +1144,14 @@ var dryrunCmd = &cobra.Command{
if timeStamp <= 0 {
timeStamp = time.Now().Unix()
}
for i, txn := range txgroup {
for i, txn := range stxns {
if txn.Lsig.Blank() {
continue
}
if uint64(txn.Lsig.Len()) > params.LogicSigMaxSize {
reportErrorf("program size too large: %d > %d", len(txn.Lsig.Logic), params.LogicSigMaxSize)
}
ep := logic.NewEvalParams(txgroup, &params, nil)
ep.SigLedger = logic.NoHeaderLedger{}
ep := logic.NewSigEvalParams(stxns, &params, logic.NoHeaderLedger{})
err := logic.CheckSignature(i, ep)
if err != nil {
reportErrorf("program failed Check: %s", err)
Expand Down
16 changes: 6 additions & 10 deletions cmd/tealdbg/debugger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,13 @@ func TestDebuggerSimple(t *testing.T) {
da := makeTestDbgAdapter(t)
debugger.AddAdapter(da)

ep := logic.NewEvalParams(make([]transactions.SignedTxnWithAD, 1), &proto, nil)
ep.Tracer = logic.MakeEvalTracerDebuggerAdaptor(debugger)
ep.SigLedger = logic.NoHeaderLedger{}

source := `int 0
int 1
+
`
ops, err := logic.AssembleStringWithVersion(source, 1)
ops, err := logic.AssembleStringWithVersion("int 0; int 1; +", 1)
require.NoError(t, err)
ep.TxnGroup[0].Lsig.Logic = ops.Program
txn := transactions.SignedTxn{}
txn.Lsig.Logic = ops.Program

ep := logic.NewSigEvalParams([]transactions.SignedTxn{txn}, &proto, logic.NoHeaderLedger{})
ep.Tracer = logic.MakeEvalTracerDebuggerAdaptor(debugger)

_, err = logic.EvalSignature(0, ep)
require.NoError(t, err)
Expand Down
30 changes: 12 additions & 18 deletions cmd/tealdbg/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ type evaluation struct {
states AppState
}

func (e *evaluation) eval(gi int, ep *logic.EvalParams) (pass bool, err error) {
func (e *evaluation) eval(gi int, sep *logic.EvalParams, aep *logic.EvalParams) (pass bool, err error) {
if e.mode == modeStateful {
pass, _, err = e.ba.StatefulEval(gi, ep, e.aidx, e.program)
pass, _, err = e.ba.StatefulEval(gi, aep, e.aidx, e.program)
return
}
ep.TxnGroup[gi].Lsig.Logic = e.program
return logic.EvalSignature(gi, ep)
sep.TxnGroup[gi].Lsig.Logic = e.program
return logic.EvalSignature(gi, sep)
}

// LocalRunner runs local eval
Expand Down Expand Up @@ -531,23 +531,17 @@ func (r *LocalRunner) RunAll() error {
return fmt.Errorf("no program to debug")
}

configureDebugger := func(ep *logic.EvalParams) {
// Workaround for Go's nil/empty interfaces nil check after nil assignment, i.e.
// r.debugger = nil
// ep.Debugger = r.debugger
// if ep.Debugger != nil // FALSE
if r.debugger != nil {
ep.Tracer = logic.MakeEvalTracerDebuggerAdaptor(r.debugger)
}
}

txngroup := transactions.WrapSignedTxnsWithAD(r.txnGroup)
failed := 0
start := time.Now()

ep := logic.NewEvalParams(txngroup, &r.proto, &transactions.SpecialAddresses{})
ep.SigLedger = logic.NoHeaderLedger{}
configureDebugger(ep)
sep := logic.NewSigEvalParams(r.txnGroup, &r.proto, &logic.NoHeaderLedger{})
aep := logic.NewAppEvalParams(txngroup, &r.proto, &transactions.SpecialAddresses{})
if r.debugger != nil {
t := logic.MakeEvalTracerDebuggerAdaptor(r.debugger)
sep.Tracer = t
aep.Tracer = t
}

var last error
for i := range r.runs {
Expand All @@ -556,7 +550,7 @@ func (r *LocalRunner) RunAll() error {
r.debugger.SaveProgram(run.name, run.program, run.source, run.offsetToLine, run.states)
}

run.result.pass, run.result.err = run.eval(int(run.groupIndex), ep)
run.result.pass, run.result.err = run.eval(int(run.groupIndex), sep, aep)
if run.result.err != nil {
failed++
last = run.result.err
Expand Down
2 changes: 1 addition & 1 deletion cmd/tealdbg/localLedger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int 2
a.NoError(err)

proto := config.Consensus[protocol.ConsensusCurrentVersion]
ep := logic.NewEvalParams([]transactions.SignedTxnWithAD{{SignedTxn: txn}}, &proto, &transactions.SpecialAddresses{})
ep := logic.NewAppEvalParams([]transactions.SignedTxnWithAD{{SignedTxn: txn}}, &proto, &transactions.SpecialAddresses{})
pass, delta, err := ba.StatefulEval(0, ep, appIdx, program)
a.NoError(err)
a.True(pass)
Expand Down
5 changes: 5 additions & 0 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ type ConsensusParams struct {
// rather than check each individual app call is within the budget.
EnableAppCostPooling bool

// EnableLogicSigCostPooling specifies LogicSig budgets are pooled across a
// group. The total available is len(group) * LogicSigMaxCost)
EnableLogicSigCostPooling bool

// RewardUnit specifies the number of MicroAlgos corresponding to one reward
// unit.
//
Expand Down Expand Up @@ -1356,6 +1360,7 @@ func initConsensusProtocols() {
vFuture.ApprovedUpgrades = map[protocol.ConsensusVersion]uint64{}

vFuture.LogicSigVersion = 10 // When moving this to a release, put a new higher LogicSigVersion here
vFuture.EnableLogicSigCostPooling = true

Consensus[protocol.ConsensusFuture] = vFuture

Expand Down
10 changes: 5 additions & 5 deletions daemon/algod/api/server/v2/dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ func doDryrunRequest(dr *DryrunRequest, response *model.DryrunResponse) {
proto := config.Consensus[protocol.ConsensusVersion(dr.ProtocolVersion)]
txgroup := transactions.WrapSignedTxnsWithAD(dr.Txns)
specials := transactions.SpecialAddresses{}
ep := logic.NewEvalParams(txgroup, &proto, &specials)
ep := logic.NewAppEvalParams(txgroup, &proto, &specials)
sep := logic.NewSigEvalParams(dr.Txns, &proto, &dl)

origEnableAppCostPooling := proto.EnableAppCostPooling
// Enable EnableAppCostPooling so that dryrun
Expand All @@ -421,11 +422,10 @@ func doDryrunRequest(dr *DryrunRequest, response *model.DryrunResponse) {
response.Txns = make([]model.DryrunTxnResult, len(dr.Txns))
for ti, stxn := range dr.Txns {
var result model.DryrunTxnResult
if len(stxn.Lsig.Logic) > 0 {
if !stxn.Lsig.Blank() {
var debug dryrunDebugReceiver
ep.Tracer = logic.MakeEvalTracerDebuggerAdaptor(&debug)
ep.SigLedger = &dl
pass, err := logic.EvalSignature(ti, ep)
sep.Tracer = logic.MakeEvalTracerDebuggerAdaptor(&debug)
pass, err := logic.EvalSignature(ti, sep)
var messages []string
result.Disassembly = debug.lines // Keep backwards compat
result.LogicSigDisassembly = &debug.lines // Also add to Lsig specific
Expand Down
1 change: 1 addition & 0 deletions daemon/algod/api/server/v2/dryrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func init() {
}

func checkLogicSigPass(t *testing.T, response *model.DryrunResponse) {
t.Helper()
if len(response.Txns) < 1 {
t.Error("no response txns")
} else if len(response.Txns) == 0 {
Expand Down
18 changes: 11 additions & 7 deletions data/transactions/logic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,17 @@ of a contract account.

The bytecode plus the length of all Args must add up to no more than
1000 bytes (consensus parameter LogicSigMaxSize). Each opcode has an
associated cost and the program cost must total no more than 20,000
(consensus parameter LogicSigMaxCost). Most opcodes have a cost of 1,
but a few slow cryptographic operations have a much higher cost. Prior
to v4, the program's cost was estimated as the static sum of all the
opcode costs in the program (whether they were actually executed or
not). Beginning with v4, the program's cost is tracked dynamically,
while being evaluated. If the program exceeds its budget, it fails.
associated cost, usually 1, but a few slow operations have higher
costs. Prior to v4, the program's cost was estimated as the static sum
of all the opcode costs in the program (whether they were actually
executed or not). Beginning with v4, the program's cost is tracked
dynamically, while being evaluated. If the program exceeds its budget,
it fails.

The total program cost of all Smart Signatures in a group must not
exceed 20,000 (consensus parameter LogicSigMaxCost) times the number
of transactions in the group.


## Execution Environment for Smart Contracts (Applications)

Expand Down
18 changes: 11 additions & 7 deletions data/transactions/logic/README_in.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,17 @@ of a contract account.

The bytecode plus the length of all Args must add up to no more than
1000 bytes (consensus parameter LogicSigMaxSize). Each opcode has an
associated cost and the program cost must total no more than 20,000
(consensus parameter LogicSigMaxCost). Most opcodes have a cost of 1,
but a few slow cryptographic operations have a much higher cost. Prior
to v4, the program's cost was estimated as the static sum of all the
opcode costs in the program (whether they were actually executed or
not). Beginning with v4, the program's cost is tracked dynamically,
while being evaluated. If the program exceeds its budget, it fails.
associated cost, usually 1, but a few slow operations have higher
costs. Prior to v4, the program's cost was estimated as the static sum
of all the opcode costs in the program (whether they were actually
executed or not). Beginning with v4, the program's cost is tracked
dynamically, while being evaluated. If the program exceeds its budget,
it fails.

The total program cost of all Smart Signatures in a group must not
exceed 20,000 (consensus parameter LogicSigMaxCost) times the number
of transactions in the group.


## Execution Environment for Smart Contracts (Applications)

Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2370,7 +2370,7 @@ func (ops *OpStream) resolveLabels() {
}

// AssemblerDefaultVersion what version of code do we emit by default
// AssemblerDefaultVersion is set to 1 on puprose
// AssemblerDefaultVersion is set to 1 on purpose
// to prevent accidental building of v1 official templates with version 2
// because these templates are not aware of rekeying.
const AssemblerDefaultVersion = 1
Expand Down

0 comments on commit a6e67ba

Please sign in to comment.