DEV Community

yuzurush
yuzurush

Posted on • Edited on

Soroban Quest : Reverse Engineer

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
Enter fullscreen mode Exit fullscreen mode

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 of ReverseEngineerContract, that already deployed by this specific account GAC7HE4PQWI7H34JQN6QLQ7Y7NTAUZDWJZ4SJ6GXVC4K2DN7N65K5NLI
  • 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 :

Stellar Lab

  1. Open Stellar Laboratory
  2. Select Explore Endpoints -> Operations -> Operations for Account
  3. Fill "Account ID" with GAC7HE4PQWI7H34JQN6QLQ7Y7NTAUZDWJZ4SJ6GXVC4K2DN7N65K5NLI
  4. Submit
  5. Scroll down find footprint xdr below HostFunctionTypeHostFunctionTypeCreateContract and copy it
  6. 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
Enter fullscreen mode Exit fullscreen mode

Result :

"contract_id": "9cf01d6f406c85b445dd8be8e91ae41c9120d067326d3179469b7fd63c81edd4",
Enter fullscreen mode Exit fullscreen mode

contract_id
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
    }
}
Enter fullscreen mode Exit fullscreen mode

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 a Symbol with the value dancinRaph
  • It implements a contractimpl for ReverseEngineerContract
  • 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Congratulations! You have already completed 3 out of 6 quests. You have 3 more to go.

Top comments (0)