Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions contracts/src/levels/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SimpleMath from './SimpleMath';

export const levels = [
...previousLevels,
{
name: "Simple Math",
contract: SimpleMath,
description: "Overflow the multiplication to solve the contract!"
}
];
14 changes: 14 additions & 0 deletions contracts/test/levels/SimpleMath.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleMath {
uint8 public result;

function multiply(uint8 a, uint8 b) public {
result = a * b; // players will try to overflow
}

function isSolved() public view returns (bool) {
return result < 255; // simple check for overflow
}
}
17 changes: 17 additions & 0 deletions contracts/test/levels/SimpleMath.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { expect } = require("chai");

describe("SimpleMath Level", function () {
let contract;

beforeEach(async function () {
const SimpleMath = await ethers.getContractFactory("SimpleMath");
contract = await SimpleMath.deploy();
await contract.deployed();
});

it("should overflow the result", async function () {
await contract.multiply(20, 13); // 20*13 = 260 > uint8 max 255
const result = await contract.result();
expect(result).to.be.lt(260); // overflow happened
});
});
Loading