Aight warm up time. All you gotta do is call the solve function. You can do it! Goal: Call the solve function!
Author: @bluealder
// 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.
The objective of the challenge is to call the solveChallenge() function of the SolveMe contract to set the isSolved variable to true.
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();
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.