Skip to content

Batch design#118

Merged
paolocappelletti merged 3 commits intodevfrom
st/batch_design
Mar 25, 2026
Merged

Batch design#118
paolocappelletti merged 3 commits intodevfrom
st/batch_design

Conversation

@saratnt
Copy link
Copy Markdown
Contributor

@saratnt saratnt commented Mar 12, 2026


// WASM execution — can cause soft failure
appState := appData.GetAppState()
run WASM (Deposit if needed, then ProcessRequest)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should explicitly add that appData is NOT mutated by a deposit until the full request (deposit + process) succeeds

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

`GetPendingRequestsWithStateRoot` adds an `applicationId` parameter:

```
GetPendingRequestsWithStateRoot(applicationId uint64, maxCount uint64) ([]*common.Request, [32]byte, error)
Copy link
Copy Markdown
Contributor

@paolocappelletti paolocappelletti Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proposal: we could move in the contract the logic to loop through the applications' queues:

  • the contract knows the list of applicationId deployed, so can loop on every GetPendingRequestsWithStateRoot call
  • the applicationId is in the returned data of GetPendingRequestsWithStateRoot: every time it is called it returns the next non-empty app request list, in a loop style (ordered by deploy time) - method signature becomes:
    GetPendingRequestsWithStateRoot(maxCount uint64) (applicationId uint64, []*common.Request, [32]byte, error)

Pro: prevent manager censorship

what do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be a good idea. GetPendingRequestsWithStateRoot could use as algorithm to return the batch from the app with the oldest first request in the queue. This means we could have 2 or more consecutive batches from the same app but at least it's fair and everybody can verify its fainess. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved!

- **Single stateRoot storage write**: read `stateRoot` once at the start, chain through entries in memory, write once at the end — saves (N-1) warm `SSTORE` operations (~5,000 gas each)
- **State root chain validation**: only the first entry checks `prevStateRoot == stateRoot` from storage; subsequent entries validate `entries[i].prevStateRoot == entries[i-1].newStateRoot` in memory
- **Deduplicated `applicationId`**: passed once instead of per-entry
- **Optional batch signature**: verify one signature over the full batch instead of N individual `ecrecover` calls, saving (N-1) × ~3,000+ gas (individual per-request signatures can still be emitted in events for off-chain verifiability)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would implement immediately the batch signature - can save gas and computation time, and does not look to me too complex

@paolocappelletti paolocappelletti self-requested a review March 24, 2026 11:08
@paolocappelletti paolocappelletti merged commit 9d12c65 into dev Mar 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants