0
0
Blockchain / Solidityprogramming~10 mins

Sidechains in Blockchain / Solidity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Sidechains
User locks coins on Mainchain
Mainchain records lock
Sidechain verifies lock proof
Sidechain issues equivalent coins
User transacts on Sidechain
User requests withdrawal
Sidechain burns coins
Sidechain provides proof of burn
Mainchain verifies burn proof
Mainchain releases locked coins back to user
Sidechains let users move coins from the main blockchain to a separate chain and back by locking and unlocking coins with proofs.
Execution Sample
Blockchain / Solidity
lockCoinsOnMainchain(user, amount)
verifyLockOnSidechain(lockProof)
issueCoinsOnSidechain(user, amount)
burnCoinsOnSidechain(user, amount)
verifyBurnOnMainchain(burnProof)
unlockCoinsOnMainchain(user, amount)
This code shows the main steps to move coins between mainchain and sidechain using lock, verify, issue, burn, verify, and unlock.
Execution Table
StepActionInputState ChangeOutput/Result
1lockCoinsOnMainchainuser=Alice, amount=10Mainchain locks 10 coins from AlicelockProof generated
2verifyLockOnSidechainlockProofSidechain confirms lock is validlockProof verified
3issueCoinsOnSidechainuser=Alice, amount=10Sidechain credits 10 coins to AliceAlice balance on sidechain = 10
4User transacts on SidechainAlice sends 5 coins to BobAlice balance=5, Bob balance=5Transaction success
5burnCoinsOnSidechainuser=Alice, amount=5Sidechain burns 5 coins from AliceburnProof generated
6verifyBurnOnMainchainburnProofMainchain confirms burn is validburnProof verified
7unlockCoinsOnMainchainuser=Alice, amount=5Mainchain releases 5 coins back to AliceAlice balance on mainchain increased by 5
8EndN/ANo further actionsProcess complete
💡 Process stops after coins are unlocked back on mainchain to user
Variable Tracker
VariableStartAfter Step 3After Step 4After Step 5After Step 7Final
Alice_mainchain_balance10090 (locked 10)909095 (unlocked 5)95
Alice_sidechain_balance010 (issued)5 (sent 5 to Bob)0 (burned 5)00
Bob_sidechain_balance005 (received 5)555
Key Moments - 3 Insights
Why does Alice's mainchain balance decrease before she can use coins on the sidechain?
Because coins are locked on the mainchain first (see Step 1 and variable 'Alice_mainchain_balance' after Step 3), so they can't be spent there until unlocked.
How does the sidechain know it can safely issue coins to Alice?
It verifies the lock proof from the mainchain (Step 2), ensuring coins are locked and not double-spent.
Why must coins be burned on the sidechain before unlocking on the mainchain?
Burning coins on the sidechain (Step 5) prevents double spending by destroying sidechain coins before mainchain coins are released (Step 7).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is Alice's sidechain balance after Step 4?
A10
B5
C0
D15
💡 Hint
Check the 'State Change' column at Step 4 showing Alice sends 5 coins to Bob.
At which step does the mainchain release coins back to Alice?
AStep 5
BStep 6
CStep 7
DStep 3
💡 Hint
Look for 'unlockCoinsOnMainchain' action in the execution table.
If Alice did not burn coins on the sidechain, what would happen in the process?
AMainchain would not verify burn proof and not unlock coins
BSidechain would issue more coins
CMainchain would still unlock coins
DAlice's mainchain balance would increase
💡 Hint
Refer to Step 6 where mainchain verifies burn proof before unlocking coins.
Concept Snapshot
Sidechains let users move coins between blockchains.
Coins are locked on mainchain, then issued on sidechain.
Users transact on sidechain freely.
To return coins, sidechain coins are burned.
Mainchain verifies burn proof and unlocks coins.
This prevents double spending across chains.
Full Transcript
Sidechains are a way to move coins from a main blockchain to a separate blockchain and back. The process starts when a user locks coins on the mainchain, which means those coins cannot be spent there anymore. The mainchain creates a proof of this lock. The sidechain checks this proof and then issues the same amount of coins to the user on the sidechain. The user can then use these coins on the sidechain, for example sending some to another user. When the user wants to move coins back, they burn coins on the sidechain, destroying them. The sidechain creates a proof of this burn. The mainchain verifies this burn proof and then unlocks the original coins back to the user. This process ensures coins are never spent twice and keeps both chains in sync.