#Race Conditions In Smart Contracts State Update

1 messages · Page 1 of 1 (latest)

simple hill
#

Consider the following smart contract:

class HelloWorld extends SmartContract {
    @state(Field) x = State<Field>();
  
    @method increment() {
      // read state
      const x = this.x.get();
      this.x.assertEquals(x);
  
      // write state
      this.x.set(x.add(1));
    }
  }

Let's say that the current on-chain value of x is 1. If two users execute this at exactly the same time, then one of those excutions will fail, as both will generate the proof with const x = 1, but for one of the verifier will attempt to assert this.x.assertEquals(1), while the value of this.xw ill be 2.

Is my understanding correct?

Thank you.

clear ravine
#

You are correct 👍