Questions about TEE and offchain solutions

So very generally, I want to build a decentralized orderbook exchange. As i understand, this is not economically feasible on a regular network like ethereum because traders will have to pay tx fees every time they want to put in or update na order onchain. Ive heard that phala network leverages TEE for hteir network. Im not very familiar yet with TEE - does this provide a solution for my usecase where traders can submit and update orders offchain somehow without having to pay x fees? Ideally i would like for all the minor updates such as order submission/update/cancellation to happen in a 0 gas/tx fee offchain environment for speed and cost reasons and only the major updates such as order match/trade to be reported on chain and incur gas/tx fees. Is that possible on phala and how can i do that?

As for TEE, there’s quite some gaps in my knowledge I was hoping to understand. Here’s what I know so far: for all PCs with certain new enough cpu to support TEE, they can run a node for a blockchain/TEE hybrid protocol (ex Phala). Is that correct? So if theres storage in the TEE, lets say some user wants to store some data in there (ex. Orderbook state). So each node will have a copy of the orderbook state living inside the TEE. Is that correct so far? How do these copies of the storage stay in sync with each other when the state is updated?

for ref, my polkadot.js address: 16A23rq7FoL9XNHxVBvKCUjYk58QTogEL6ND13W83hnfXPRe

I got some helpful answers from the team on discord. Thought I’d share it on here in case it helps anyone else:

for all PCs with certain new enough cpu to support TEE, they can run a node for a blockchain/TEE hybrid protocol (ex. Phala)

Yes

So each node will have a copy of the orderbook state living inside the TEE. Is that correct so far?

This one is tricky. A Phala contract has onchain and offchain storage. The onchain storage is purely derived on the transactions on the blockchain (state = replay of all the historical tx). So all the TEE can run the same code and share the same storage. However it hasn’t to be. They are non-byzantine. So we can ask all the TEE to run different things in parallel. Thus throughputs+++.

The onchain storage is expensive and slow because you need to send tx, and the block latency is there. So in addition to that, we have offchain storage (or local storage), which is stored in the local TEE, and can be read / write by queries. Queries are handled by the TEE directly without involving the blockchain. So it can achieve native CPU speed. These local storage are not shared by TEEs, and that’s also the drawback: you get fast and free storage, but the cost is consistency and data availability. Think about the TEE is shutdown, and your data is gone.

So to fix it, you either don’t rely on the local storage, just use it for speed up instead of relaying on it for the correct execution of the contract, or we somehow replicate the local storage, just like traditional database replication.

How do these copies of the storage stay in sync with each other when the state is updated?
If my understanding is correct, that’s exactly the same question as I just mentioned

Thanks for the compilation. I’d love to apply for a beer on Khala for you :D