madara
madara copied to clipboard
feat: Sync from L1
Enable Madara to Sync it's state from L1.
As Starknet is a Validity Rollup on top of an L1 (Ethereum) we can query the base chain to retrieve all of the information needed to recompute the last proved
state of Starknet.
The information needed to recompute the state is known as a StateDiff and it includes pertinent changes to the Starknet State per block:
- deployed contracts
- storage updates
- declared(+deprecated) classes
- nonce updates
- replaced classes
This information is encoded by the Starknet OS as calldata, encoding defined here. This calldata is PUBLISHED AND LOGGED to the L1 Core Contracts and checked against the verifier's fact registry in the following function updateState
/**
Updates the state of the StarkNet, based on a proof of the
StarkNet OS that the state transition is valid.
Arguments:
programOutput - The main part of the StarkNet OS program output.
data_availability_fact - An encoding of the on-chain data associated
with the 'programOutput'.
*/
function updateState(
uint256[] calldata programOutput,
uint256 onchainDataHash,
uint256 onchainDataSize
) external onlyOperator {
Each state update is tied to a Fact
which is a hash represents the output of the StarknetOS and its program hash and serves as an attestation of the block verification(simple fact hash example). These facts can be registered as mulitple MemoryPages in the verifier fact registry.
Syncing
The implementation will involve(w/ python examples):
- SN Genesis defs
- from genesis fetch the state update logs and the state transition fact logs
- fetch the memory page logs for that block(or in bulk)
- Fetch all
LogMemoryPageFactContinuous
events from the MemoryPageFactRegistry - decode the function input tied to this memory page fact which will correspond to the encoded DA output described above
- parse the DA and apply the relevant changes to your aggregated state via mapping sync
- repeat until you reach to current head
There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a 👍 Because this issue is marked as stale, it will be closed and locked in 7 days if no further activity occurs. Thank you for your contributions!
Our team has essentially implemented this feature. This is our PR: https://github.com/keep-starknet-strange/madara/pull/1296
There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a 👍 Because this issue is marked as stale, it will be closed and locked in 7 days if no further activity occurs. Thank you for your contributions!
repository archived in favor of https://github.com/madara-alliance/madara