Soroban Quest : Reverse Engineer
yuzurush
Posted on March 25, 2023
Hi there! Welcome to my "Soroban Quest" blog post series. Soroban Quest is a gamified educational course where you’ll learn Soroban (new smart contract platform by Stellar Foundation) and earn badge rewards!. In this series, i will explain steps to complete every soroban quest and help you understand more about soroban smart contract itself.
The third quest is called "Reverse Engineer". This quite quest different from the two previous quest, i will explain more in examining README.md
section below.
Joining The Quest
To join the quest and get a Quest Account, use this command:
sq play 3
And dont forget to fund the quest account right away.
Examining README.md
After examining README.md
, I found that the tasks for the 3rd quest is to:
- Do reverse engineer to find a
contractID
ofReverseEngineerContract
, that already deployed by this specific accountGAC7HE4PQWI7H34JQN6QLQ7Y7NTAUZDWJZ4SJ6GXVC4K2DN7N65K5NLI
- Invoke
submit
function from that contractID
Finding Contract ID
For finding contract ID, we will user Stellar Laboratory and soroban lab xdr dec
command. Here's how :
- Open Stellar Laboratory
- Select Explore Endpoints -> Operations -> Operations for Account
- Fill "Account ID" with
GAC7HE4PQWI7H34JQN6QLQ7Y7NTAUZDWJZ4SJ6GXVC4K2DN7N65K5NLI
- Submit
- Scroll down find
footprint
xdr belowHostFunctionTypeHostFunctionTypeCreateContract
and copy it - Decode the
footprint
xdr using this command to extract the contractID:
soroban lab xdr dec \
--type LedgerFootprint \
--xdr AAAAAQAAAAcvYZs/BqiEyZduBaT0n+3vak84eWOTyBL5cZnR7S0VdQAAAAEAAAAGnPAdb0BshbRF3Yvo6RrkHJEg0GcybTF5Rpt/1jyB7dQAAAADAAAAAw== \
--output json | grep contract_id
Result :
"contract_id": "9cf01d6f406c85b445dd8be8e91ae41c9120d067326d3179469b7fd63c81edd4",
We already got our contract id,next we will examine the contract code.
The Contract Code
pub struct ReverseEngineerContract;
const SECRET : Symbol = symbol!("dancinRaph");
#[contractimpl]
impl ReverseEngineerContract {
pub fn submit(_: Env, secret: Symbol) -> bool{
secret == SECRET
}
}
The contract is located in lib.rs
and contains one functions:
- It defines a struct
ReverseEngineerContract
which represents the contract - It defines a constant
SECRET
which is aSymbol
with the valuedancinRaph
- It implements a
contractimpl
forReverseEngineerContract
- This contract has one function
submit
which takes an Env (the contract environment) and a Symbol secret - The function returns true if the passed in secret matches the SECRET constant, and false otherwise
So in summary, submit
function checks if a passed in secret matches a hardcoded constant. So we must invoke submit
function with dancinRaph
as value for secret
Invoking submit
Function
To invoke submit
function use this command :
soroban contract invoke --id 9cf01d6f406c85b445dd8be8e91ae41c9120d067326d3179469b7fd63c81edd4 -- submit --secret dancinRaph
Checking the Quest
We already completed every step to complete the quest and this is the last thing you need to do. Check your quest and claim your badge reward. To check use the following command :
sq check 3
Congratulations! You have already completed 3 out of 6 quests. You have 3 more to go.
Posted on March 25, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.