Skip to content

Clear State program does not include a return value #111

@CiottiGiorgio

Description

@CiottiGiorgio

This clearState function

  clearState(): void {
    this.votes_total.set(this.votes_total.get() - 1);
    if (this.in_favor.get(this.txn.sender))
      this.votes_in_favor.set(this.votes_in_favor.get() - 1);
  }

will produce this example.clear.teal

#pragma version 9
// smart_contracts/example.algo.ts:80
// this.votes_total.set(this.votes_total.get() - 1)
byte "votes_total"
byte "votes_total"
app_global_get
int 1
-
app_global_put
// if2_condition
// smart_contracts/example.algo.ts:81
// this.in_favor.get(this.txn.sender)
txn Sender
byte "in_favor"
app_local_get
int 0
getbit
bz if2_end
// if2_consequent
// smart_contracts/example.algo.ts:82
// this.votes_in_favor.set(this.votes_in_favor.get() - 1)
byte "votes_in_favor"
byte "votes_in_favor"
app_global_get
int 1
-
app_global_put

if2_end:

Making it so that the clear program will always fail and therefore never recording the global state delta.
Usually, the ABI router in the Approval program handles the success of the method but Clear State doesn't use one so it would be enough to append

int 1
return

in this case. Maybe this is true in general?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions