Skip to content

Instantly share code, notes, and snippets.

@dz-root
Last active March 7, 2024 01:36
Show Gist options
  • Save dz-root/b4f2cf7719c29a1ac2bab10c6b6c3b5d to your computer and use it in GitHub Desktop.
Save dz-root/b4f2cf7719c29a1ac2bab10c6b6c3b5d to your computer and use it in GitHub Desktop.
DownUnderCTF 2022 - SolveMe

Solve Me

Aight warm up time. All you gotta do is call the solve function. You can do it! Goal: Call the solve function!

Author: @bluealder

Smart contract

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @title SolveMe
 * @author BlueAlder duc.tf
 */
contract SolveMe {
    bool public isSolved = false;

    function solveChallenge() external {
        isSolved = true;
    }
   
}

This Solidity smart contract is called SolveMe. It has a boolean state variable isSolved initialized to false. The contract provides a public function solveChallenge(), which when called, sets the isSolved variable to true.

Objective:

The objective of the challenge is to call the solveChallenge() function of the SolveMe contract to set the isSolved variable to true.

Solution:

The provided JavaScript code is the solution to the challenge. It utilizes the Web3 library to interact with the deployed smart contract.

const Web3 = require('web3');

// Challange data instance ----------------------------------------------------------------------------
const abi = [
    {
        "inputs": [],
        "name": "solveChallenge",
        "outputs": [],
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "isSolved",
        "outputs": [
            {
                "internalType": "bool",
                "name": "",
                "type": "bool"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    }
]

const node = 'https://blockchain-solveme-2c8728e3a336c617-eth.2022.ductf.dev/';
const static = {
    "player_wallet":{
        "address":"0xc8C7d843B1D4d365C6454aaAFc05D6C8b4b4C1AE",
        "private_key":"0xe59f54aa97fa5ee321d1ae26a5d58c3bd3a6f3591b13d6b5ea67f4a58b1bfe5b",
        "balance":"2.0 ETH"
    },
    "contract_address":[{"address":"0x6E4198C61C75D1B4D1cbcd00707aAC7d76867cF8","name":"SolveMe.sol"}]
}

// Set Provider -------------------------------------------------------------------------------

const provider = new Web3.providers.HttpProvider(node);

// Create contract instance
let web3 = new Web3(provider);
let contract = new web3.eth.Contract(abi, static.contract_address[0].address)

// Add wallet
web3.eth.accounts.wallet.add({
    privateKey: static.player_wallet.private_key,
    address: static.player_wallet.address
});

// Send Transaction (Call Solve Methode) -------------------------------------------------------
const attack = async() => {

    let solve = await contract.methods.solveChallenge().send({

        from: static.player_wallet.address, 
        gas:300000
        
    }).then(() => {
		contract.methods.isSolved().call()
        .then((state) => console.log(`Is it solved: ${state}`))
	})
    
}

attack();

Conclusion:

The provided solution demonstrates how to interact with a smart contract deployed on the Ethereum blockchain using Web3.js. By calling the solveChallenge() function, the participant can set the isSolved variable to true, thereby completing the challenge and obtaining the flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment