Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic teal #2126

Merged
merged 19 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
check programs against last static version
  • Loading branch information
jannotti committed May 11, 2021
commit 4137ada98b8c5fa779cb6b7134674bf599a429ae
5 changes: 2 additions & 3 deletions ledger/apply/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func closeOutApplication(balances Balances, sender basics.Address, appIdx basics
return nil
}

func checkPrograms(ac *transactions.ApplicationCallTxnFields, evalParams *logic.EvalParams, maxCost int) error {
func checkPrograms(ac *transactions.ApplicationCallTxnFields, evalParams *logic.EvalParams) error {
err := logic.CheckStateful(ac.ApprovalProgram, *evalParams)
if err != nil {
return fmt.Errorf("check failed on ApprovalProgram: %v", err)
Expand Down Expand Up @@ -336,8 +336,7 @@ func ApplicationCall(ac transactions.ApplicationCallTxnFields, header transactio
// If this txn is going to set new programs (either for creation or
// update), check that the programs are valid and not too expensive
if ac.ApplicationID == 0 || ac.OnCompletion == transactions.UpdateApplicationOC {
maxCost := balances.ConsensusParams().MaxAppProgramCost
err = checkPrograms(&ac, evalParams, maxCost)
err = checkPrograms(&ac, evalParams)
if err != nil {
return err
}
Expand Down
24 changes: 14 additions & 10 deletions ledger/apply/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,32 +349,36 @@ func TestAppCallCheckPrograms(t *testing.T) {

var ac transactions.ApplicationCallTxnFields
var ep logic.EvalParams
proto := config.Consensus[protocol.ConsensusFuture]
// This check is for static costs. v26 is last with static cost checking
proto := config.Consensus[protocol.ConsensusV26]
ep.Proto = &proto

err := checkPrograms(&ac, &ep, 1)
proto.MaxAppProgramCost = 1
err := checkPrograms(&ac, &ep)
a.Error(err)
a.Contains(err.Error(), "check failed on ApprovalProgram")

program := []byte{2, 0x20, 1, 1, 0x22} // version, intcb, int 1
ac.ApprovalProgram = program
err = checkPrograms(&ac, &ep, 1)
a.Error(err)
a.Contains(err.Error(), "ApprovalProgram too resource intensive")
ac.ClearStateProgram = program

err = checkPrograms(&ac, &ep, 10)
err = checkPrograms(&ac, &ep)
a.Error(err)
a.Contains(err.Error(), "check failed on ClearStateProgram")
a.Contains(err.Error(), "check failed on ApprovalProgram")

proto.MaxAppProgramCost = 10
err = checkPrograms(&ac, &ep)
a.NoError(err)

ac.ClearStateProgram = append(ac.ClearStateProgram, program...)
ac.ClearStateProgram = append(ac.ClearStateProgram, program...)
ac.ClearStateProgram = append(ac.ClearStateProgram, program...)
err = checkPrograms(&ac, &ep, 10)
err = checkPrograms(&ac, &ep)
a.Error(err)
a.Contains(err.Error(), "ClearStateProgram too resource intensive")
a.Contains(err.Error(), "check failed on ClearStateProgram")

ac.ClearStateProgram = program
err = checkPrograms(&ac, &ep, 10)
err = checkPrograms(&ac, &ep)
a.NoError(err)
}

Expand Down