Starknet-As-ComputeEngine

SNIP Proposal - Starknet-As-Compute

  • Introduction

    • As the on-chain ecosystem matures, CEFI products fail, alot of off-chain activity moves on-chain, demand for trustless blockspace or computation is at an all time high
    • Most applications desire a trustless compute engine and not necessarily a blockchain
    • In this proposal, I will try to showcase how Starknet can actually be the best at being the “compute layer” for applications on EthL1, L2s like Optimism, Arbitrum and even Alt-L1s like BSC, Avax and Solana.
  • Lets stark it

    • I am not the first one to think about this btw, overtime I have seen several people think about it and leverage this, for eg this tweet thread by Sacha(YearnFinance) using SHARP to perform off-chain computation is basically exactly what I try to highlight in this post
    • Lets take the example of searching the largest number in a set of 1000 numbers as the problem here for which we want to outsource compute. The general idea then is the following
      • You first write a program in cairo that takes in 1000 numbers and via a very dumb and compute heavy algorithm(lets say by pure iteration over the set) finds the largest number
      • You can now write a smart contract on L1 that can “request_result” for a set of 1000 numbers by calling the cairo program from L1 via the sendMessageToL2 function as outlined here
      • The smart contract on L1 also defines a callbackWithResult function which expects the index of the largest number in the set. So if the 4th number in the set is the biggest one, the function callbackWithResult will be called with the result 3
      • The cairo program then runs and does the heavy computation, once done it attempts to call callbackWithResult with the output via the method outlined here
      • Starknet sequencer sends the state update back to L1 with the proof which guarantees correct execution.
      • Post which our requester contract on L1 can consume the message via the consumeMessageFromL2 method.
      • Fin, well that was simple. Now, we can simply extend this to supply computation output to other L2s connected to L1 by leveraging their native message bridges.
    • Infact, we can even do the same thing via other L1s and things will still be trustless, lets see how
      • Consider someone wanting to outsource computation from Avalanche, same problem i.e greatest of 10000 numbers.
      • We write a contract on Avax that takes in the input of 10000 number, hashes it and stores it. Lets call this variable the input_hash
      • A generic relayer, relays the input of 10k numbers to our cairo program that computes the greatest and spits out the state-update and proof back to EthL1, just like in our prev example
      • A generic relayer now, relays the proof to Avax for validation
      • The callbackWithResult function on Avax, takes 10000 numbers as input, validates the input with input_hash
        • Supplies the proof, input to the verifier to reveal the output
      • Which the contract now accepts to be correct
      • Completely trustless, bridgeless, safe.
    • Conclusion

      • This is an extremely powerful way to leverage Starknet and hope applications embrace async trustless computation, we(Socket.tech) are building infrastructure that becomes the transport layer to make applications like these possible.
12 Likes

This is pretty relevant in the “coprocessor” meme thats going through Crypto Twitter past few months. We should be more active in discussing Starknet from this PoV as well.