Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/navigation component #5

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# BANKEX Proof-of-skill CTF Contest

## About
We have 3 tasks which you need to solve. Every smart-contract have some backdoors that allow you to break it's logic.
We have leaderboard where you can find your progress.

## Tech info
Web3 + rinkeby + metamask.
We are using only frontend solution connected directly to Rinkeby.


## Live Demo:
https://bankex.github.io/proof-of-skill-hackathon-ctf/
Binary file added docs/assets/img/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/img/example2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 36 additions & 23 deletions docs/assets/js/CONTACT_DATA.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const contractName = "Root";
const contractAddress = "0x9dc03f5d2df4ff1d10f5963757ad480f74a86238";
const contractAddress = "0xc76e244bf79c72b02b2b98c7005785e2d4fca360";
const abi = [
{
"constant": true,
Expand Down Expand Up @@ -156,6 +156,29 @@
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "bytes32"
},
{
"name": "",
"type": "address"
}
],
"name": "solvedTimestamp",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
Expand Down Expand Up @@ -197,6 +220,18 @@
"name": "Solved",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "teamname",
"type": "string"
}
],
"name": "AddTeam",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -420,27 +455,5 @@
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "userAddress",
"type": "address"
},
{
"name": "taskName",
"type": "string"
},
{
"name": "amount",
"type": "uint256"
}
],
"name": "addSolution",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
];
29 changes: 13 additions & 16 deletions docs/assets/js/connection.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
async function initConnection(web3) {
let account, network;
if (!web3 || !web3.currentProvider) throw new Error('No Web3 provider found');
const accounts = await web3.eth.getAccounts();
if (!accounts) throw new Error('No Web3 provider found');
if (!accounts[0]) throw new Error('Web3 provider is locked');
account = accounts[0];
network = await web3.eth.net.getId();
return {account, network};
try {
let account, network;
if (!web3 || !web3.currentProvider) throw new Error('No Web3 provider found');
const accounts = await web3.eth.getAccounts();
if (!accounts) throw new Error('No Web3 provider found. Have you installed Metamask?');
if (!accounts[0]) throw new Error('Metamask is locked!');
account = accounts[0];
network = await web3.eth.net.getId();
return {account, network};
} catch(e) { alert((web3.currentProvider.host?'No Metamask found - connecting to local provider. Error: ':'')+e.message)}
}

// Returns ready-to-go Web3 instacne
function checkAndInstantiateWeb3() {
// tslint:disable:max-line-length
// Checking if Web3 has been injected by the browser
if (typeof web3 != 'undefined') {
console.warn(
'Using web3 detected from external source. If you find that your accounts don\'t appear or you have 0 MetaCoin, ensure you\'ve configured that source properly. If using MetaMask, see the following link. Feel free to delete this warning. :) http://truffleframework.com/tutorials/truffle-and-metamask'
);
if (typeof web3 !== 'undefined') {
//console.info('Connected with Metamask');
return new Web3(web3.currentProvider);
} else {
console.warn(
'No web3 detected. Falling back to http://localhost:8545. You should remove this fallback when you deploy live, as it\'s inherently insecure. Consider switching to Metamask for development. More info here: http://truffleframework.com/tutorials/truffle-and-metamask'
);
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
console.info('No metamask detected. Falling back to http://localhost:8545.');
return new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
}
}
29 changes: 14 additions & 15 deletions docs/assets/js/leaderboard.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
const { Observable, Subject, ReplaySubject, from, of, range } = rxjs;
// const { map, filter, switchMap } = rxjs.operators;

const hackatonResults = new Subject();
const mockedResults = [
{userAddress: '0x1231235', timestamp1: Date.now(), timestamp2: undefined, timestamp3: Date.now()},
{userAddress: '0x1233123', timestamp1: Date.now(), timestamp2: Date.now(), timestamp3: Date.now()},
{userAddress: '0x4563257', timestamp1: undefined, timestamp2: Date.now(), timestamp3: undefined},
{userAddress: '0x1236456', timestamp1: Date.now(), timestamp2: Date.now(), timestamp3: undefined},
]

const messages = {
notReady: 'Не готова',
notRinkeby: 'Please use Rinkeby Test Network'
notRinkeby: 'Please use Rinkeby Test Network',
submitedAt: 'Результат получен в',
}

class Result {
static readyTasks(result) {
const count = Object.keys(result.tasks).length;
static countFinishedTasks(tasks, count = 0) {
Object.keys(tasks).forEach((key, index) => tasks[key] && (count +=1))
return count;
}
constructor( _userAddress = undefined) {
constructor( _userAddress) {
this.userAddress = _userAddress;
this.tasks = {};
this.tasks['JoiCasino'] = undefined;
this.tasks['LEGO'] = undefined;
this.tasks['FastFlow'] = undefined;
this.tasks['Yohoho and a bottle of rum'] = undefined;
this.tasks['Black pearl'] = undefined;
this.tasks['Jack the Sparrow'] = undefined;
this.tasks['Sir Henry Morgan'] = undefined;
this.score = undefined;
this.timestampScore = undefined;
this.tasks = {};
}
}

Expand All @@ -41,9 +41,8 @@ rnd = (len) => {
*/
date = (timestamp) => {
if (timestamp) {
let str;
let date = new Date(timestamp);
return `${('0'+date.getHours()).slice(-2)}:${('0'+date.getMinutes()).slice(-2)}:${('0'+date.getSeconds()).slice(-2)}`;
return `${messages.submitedAt+' '+('0'+date.getHours()).slice(-2)}:${('0'+date.getMinutes()).slice(-2)}:${('0'+date.getSeconds()).slice(-2)}`;
} else {
return messages.notReady;
}
Expand Down
30 changes: 22 additions & 8 deletions docs/assets/js/reg.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ const checkAuth = async () => {
if (auth) {
regButton.disabled = true;
teamName.innerHTML = await contract.methods.getTeamName().call({from: account});
setTimeout(() => {window.location.href = 'tasks1.html'}, 1000);
await new Promise(async (resolve) => {
setTimeout(() => {
window.location.href = 'tasks1.html';
resolve(null);
}, 1000);
});
} else return false;
};

Expand All @@ -32,15 +37,24 @@ const funcButton = () => {
const regSubmit = async () => {
try {
if (team.value === '') throw new Error('Введите название команды');
regButton.disabled = true;
await checkAuth();
const res = await contract.methods.signUp(team.value).send({from: account});
if (!res) {
regButton.disabled = false;
throw new Error('Registration failed');
}
regButton.disabled = true;
teamName.innerHTML = `Ожидайте, идет регистрация команды ${team.value}`;
setInterval(checkAuth, 2000);
try {
const res = await contract.methods.signUp(team.value).send({from: account});
if (!res) {
regButton.disabled = false;
throw new Error('Registration failed');
}
if (!await checkAuth()) setInterval(checkAuth, 2000);
} catch (e) {
if (e.message.indexOf('User denied transaction signature')!==-1) {
teamName.innerHTML = '';
regButton.disabled = false;
} else {
throw new Error(e);
}
}
} catch (e) {
alert(e);
console.log(e);
Expand Down
41 changes: 33 additions & 8 deletions docs/assets/js/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@ const checkDeployed = async () => {
taskCheck.disabled = false;
taskAddress.innerHTML = deployedAddress;
clearInterval(intDep);
}
return true;
} else return false;
};

const deployFunc = async () => {
const res = await contract.methods.createInstance(TASK).send({from: account});
if (!res) throw new Error('Deploy fail');
const oa = taskAddress.innerHTML;
taskAddress.innerHTML = '...ожидайте...';
intDep = setInterval(checkDeployed, 2000);
try {
const res = await contract.methods.createInstance(TASK).send({from: account});
if (!res) throw new Error('Deploy fail');
if (!await checkDeployed()) {
intDep = setInterval(checkDeployed, 2000);
}
} catch (e) {
if (e.message.indexOf('User denied transaction signature')!==-1) {
taskAddress.innerHTML = oa;
} else {
throw new Error(e);
}
}
};

const getSolved = async () => {
Expand All @@ -32,14 +44,27 @@ const getSolved = async () => {
taskSolved.style.display = 'block';
taskAddress.innerHTML = '----';
clearInterval(intSol);
}
return true;
} else false;
};

const sendSolve = async () => {
const res = await contract.methods.checkSolved(TASK).send({from: account});
if (!res) throw new Error('Check fail');
const oa = taskAddress.innerHTML;
taskAddress.innerHTML = '...ожидайте...';
intSol = setInterval(getSolved, 2000);
try{
const res = await contract.methods.checkSolved(TASK).send({from: account});
if (!res) throw new Error('Check fail');
if (!await getSolved()) {
alert('Задача не решена');
taskAddress.innerHTML = oa;
}
} catch (e) {
if (e.message.indexOf('User denied transaction signature')!==-1) {
taskAddress.innerHTML = oa;
} else {
throw new Error(e);
}
}
};

const start = async () => {
Expand Down
Empty file removed docs/assets/js/vendor/tasks.js
Empty file.
Loading