Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
attente committed Mar 4, 2018
1 parent 57227f8 commit b2068fb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 59 deletions.
21 changes: 16 additions & 5 deletions contracts/Arcadeum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ contract Arcadeum {
string private constant MESSAGE_PREFIX = 'Sign to play! This won\'t cost anything.\n';
string private constant PLAYER_PREFIX = '\nPlayer: 0x';

// XXX: https://github.com/ethereum/solidity/issues/3270
// *** THIS MUST MATCH DGame.sol ***
uint private constant PUBLIC_SEED_LENGTH = 1;
uint private constant META_STATE_DATA_LENGTH = 3;
uint private constant STATE_DATA_LENGTH = 1;

struct Match {
DGame game;
uint32 matchID;
Expand All @@ -27,7 +33,8 @@ contract Arcadeum {
SubkeySignature subkeySignature;
TimestampSignature timestampSignature;
uint32 seedRating;
bytes publicSeed;
// XXX: https://github.com/ethereum/solidity/issues/3270
bytes32[PUBLIC_SEED_LENGTH] publicSeed;
}

struct Move {
Expand Down Expand Up @@ -261,7 +268,8 @@ contract Arcadeum {
rewardClaimed(aMatch.game, aMatch.matchID, msg.sender);
}

function canReportCheater(Match aMatch, uint32 reporterSeedRating, bytes reporterPublicSeed, DGame.MetaState metaState, Move cheaterMove) public view returns (bool) {
// XXX: https://github.com/ethereum/solidity/issues/3270
function canReportCheater(Match aMatch, uint32 reporterSeedRating, bytes32[PUBLIC_SEED_LENGTH] reporterPublicSeed, DGame.MetaState metaState, Move cheaterMove) public view returns (bool) {
bytes24 gameMatchID;
address opponent;

Expand All @@ -288,7 +296,8 @@ contract Arcadeum {
return true;
}

function reportCheater(Match aMatch, uint32 reporterSeedRating, bytes reporterPublicSeed, DGame.MetaState metaState, Move cheaterMove) external {
// XXX: https://github.com/ethereum/solidity/issues/3270
function reportCheater(Match aMatch, uint32 reporterSeedRating, bytes32[PUBLIC_SEED_LENGTH] reporterPublicSeed, DGame.MetaState metaState, Move cheaterMove) external {
bytes24 gameMatchID;
address opponent;
uint value;
Expand Down Expand Up @@ -413,11 +422,13 @@ contract Arcadeum {
return subkeyParent(subkey, subkeySignature);
}

function matchHash(DGame game, uint32 matchID, uint timestamp, address[2] accounts, uint32[2] seedRatings, bytes[2] publicSeeds) public pure returns (bytes32) {
// XXX: https://github.com/ethereum/solidity/issues/3270
function matchHash(DGame game, uint32 matchID, uint timestamp, address[2] accounts, uint32[2] seedRatings, bytes32[PUBLIC_SEED_LENGTH][2] publicSeeds) public pure returns (bytes32) {
return keccak256(game, matchID, timestamp, accounts[0], accounts[1], seedRatings[0], seedRatings[1], publicSeeds[0], publicSeeds[1]);
}

function matchMaker(Match aMatch, address sender, uint32 senderSeedRating, bytes senderPublicSeed) private pure returns (address) {
// XXX: https://github.com/ethereum/solidity/issues/3270
function matchMaker(Match aMatch, address sender, uint32 senderSeedRating, bytes32[PUBLIC_SEED_LENGTH] senderPublicSeed) private pure returns (address) {
address opponent;
bytes32 hash;

Expand Down
51 changes: 27 additions & 24 deletions contracts/DGame.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ pragma solidity ^0.4.19;
pragma experimental ABIEncoderV2;

contract DGame {
// XXX: https://github.com/ethereum/solidity/issues/3270
// *** THIS MUST MATCH Arcadeum.sol ***
uint private constant PUBLIC_SEED_LENGTH = 1;
uint private constant META_STATE_DATA_LENGTH = 3;
uint private constant STATE_DATA_LENGTH = 1;

enum Winner {
NONE,
PLAYER_0,
Expand All @@ -26,13 +32,15 @@ contract DGame {
struct MetaState {
uint32 nonce;
MetaTag tag;
bytes data;
// XXX: https://github.com/ethereum/solidity/issues/3270
bytes32[META_STATE_DATA_LENGTH] data;
State state;
}

struct State {
uint32 tag;
bytes data;
// XXX: https://github.com/ethereum/solidity/issues/3270
bytes32[STATE_DATA_LENGTH] data;
}

struct Move {
Expand All @@ -56,8 +64,9 @@ contract DGame {
return 0;
}

function publicSeed(address /* account */, bytes /* secretSeed */) public view returns (bytes) {
return new bytes(0);
// XXX: https://github.com/ethereum/solidity/issues/3270
function publicSeed(address /* account */, bytes /* secretSeed */) public view returns (bytes32[PUBLIC_SEED_LENGTH]) {
return [bytes32(0)];
}

function initialState(bytes publicSeed0, bytes publicSeed1) public pure returns (MetaState);
Expand Down Expand Up @@ -105,8 +114,6 @@ contract DGame {
function isMoveLegal(MetaState metaState, Move move) public pure returns (bool) {
NextPlayers next;
bytes32 hash;
uint offset;
uint i;

next = nextPlayers(metaState);

Expand Down Expand Up @@ -136,12 +143,10 @@ contract DGame {
}

hash = keccak256(move.data);
offset = 1 + 32 * move.playerID;

for (i = 0; i < 32; i++) {
if (hash[i] != metaState.data[offset + i]) {
return false;
}
// XXX: https://github.com/ethereum/solidity/issues/3270
if (hash != metaState.data[1 + move.playerID]) {
return false;
}

return true;
Expand All @@ -151,12 +156,10 @@ contract DGame {

} else if (metaState.tag == MetaTag.REVEALING_SECRET) {
hash = keccak256(move.data);
offset = 32 * move.playerID;

for (i = 0; i < 32; i++) {
if (hash[i] != metaState.data[offset + i]) {
return false;
}
// XXX: https://github.com/ethereum/solidity/issues/3270
if (hash != metaState.data[move.playerID]) {
return false;
}

return true;
Expand Down Expand Up @@ -213,12 +216,12 @@ contract DGame {

} else {
next.tag = MetaTag.REVEALING_RANDOM;
next.data = new bytes(65);
next.data[0] = metaState.data[0];

// XXX: https://github.com/ethereum/solidity/issues/3270
for (i = 0; i < 32; i++) {
next.data[1 + i] = moves[0].data[i];
next.data[33 + i] = moves[1].data[i];
next.data[1] |= bytes32(moves[0].data[i]) << ((31 - i) * 8);
next.data[2] |= bytes32(moves[1].data[i]) << ((31 - i) * 8);
}

next.state = metaState.state;
Expand All @@ -245,11 +248,11 @@ contract DGame {

} else {
next.tag = MetaTag.REVEALING_SECRET;
next.data = new bytes(64);

// XXX: https://github.com/ethereum/solidity/issues/3270
for (i = 0; i < 32; i++) {
next.data[0 + i] = moves[0].data[i];
next.data[32 + i] = moves[1].data[i];
next.data[0] |= bytes32(moves[0].data[i]) << ((31 - i) * 8);
next.data[1] |= bytes32(moves[1].data[i]) << ((31 - i) * 8);
}

next.state = metaState.state;
Expand Down Expand Up @@ -307,8 +310,8 @@ contract DGame {
require(nBytes >= 8);

metaState.tag = MetaTag.COMMITTING_RANDOM;
metaState.data = new bytes(1);
metaState.data[0] = byte(nBytes);
// XXX: https://github.com/ethereum/solidity/issues/3270
metaState.data[0] = bytes32(nBytes);
metaState.state = state;

return metaState;
Expand Down
58 changes: 28 additions & 30 deletions contracts/TTT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,41 @@ contract TTT is DGame {
function initialState(bytes, bytes) public pure returns (MetaState) {
State memory state;

state.data = new bytes(9);

return meta(state);
}

function winnerImplementation(State state) internal pure returns (Winner) {
if (byte(0) != state.data[0] && state.data[0] == state.data[1] && state.data[1] == state.data[2]) {
return Winner(uint8(state.data[0]));
// XXX: https://github.com/ethereum/solidity/issues/3270
if (byte(0) != state.data[0][0] && state.data[0][0] == state.data[0][1] && state.data[0][1] == state.data[0][2]) {
return Winner(uint8(state.data[0][0]));

} else if (byte(0) != state.data[3] && state.data[3] == state.data[4] && state.data[4] == state.data[5]) {
return Winner(uint8(state.data[3]));
// XXX: https://github.com/ethereum/solidity/issues/3270
} else if (byte(0) != state.data[0][3] && state.data[0][3] == state.data[0][4] && state.data[0][4] == state.data[0][5]) {
return Winner(uint8(state.data[0][3]));

} else if (byte(0) != state.data[6] && state.data[6] == state.data[7] && state.data[7] == state.data[8]) {
return Winner(uint8(state.data[6]));
// XXX: https://github.com/ethereum/solidity/issues/3270
} else if (byte(0) != state.data[0][6] && state.data[0][6] == state.data[0][7] && state.data[0][7] == state.data[0][8]) {
return Winner(uint8(state.data[0][6]));

} else if (byte(0) != state.data[0] && state.data[0] == state.data[3] && state.data[3] == state.data[6]) {
return Winner(uint8(state.data[0]));
// XXX: https://github.com/ethereum/solidity/issues/3270
} else if (byte(0) != state.data[0][0] && state.data[0][0] == state.data[0][3] && state.data[0][3] == state.data[0][6]) {
return Winner(uint8(state.data[0][0]));

} else if (byte(0) != state.data[1] && state.data[1] == state.data[4] && state.data[4] == state.data[7]) {
return Winner(uint8(state.data[1]));
// XXX: https://github.com/ethereum/solidity/issues/3270
} else if (byte(0) != state.data[0][1] && state.data[0][1] == state.data[0][4] && state.data[0][4] == state.data[0][7]) {
return Winner(uint8(state.data[0][1]));

} else if (byte(0) != state.data[2] && state.data[2] == state.data[5] && state.data[5] == state.data[8]) {
return Winner(uint8(state.data[2]));
// XXX: https://github.com/ethereum/solidity/issues/3270
} else if (byte(0) != state.data[0][2] && state.data[0][2] == state.data[0][5] && state.data[0][5] == state.data[0][8]) {
return Winner(uint8(state.data[0][2]));

} else if (byte(0) != state.data[0] && state.data[0] == state.data[4] && state.data[4] == state.data[8]) {
return Winner(uint8(state.data[0]));
// XXX: https://github.com/ethereum/solidity/issues/3270
} else if (byte(0) != state.data[0][0] && state.data[0][0] == state.data[0][4] && state.data[0][4] == state.data[0][8]) {
return Winner(uint8(state.data[0][0]));

} else if (byte(0) != state.data[2] && state.data[2] == state.data[4] && state.data[4] == state.data[6]) {
return Winner(uint8(state.data[2]));
// XXX: https://github.com/ethereum/solidity/issues/3270
} else if (byte(0) != state.data[0][2] && state.data[0][2] == state.data[0][4] && state.data[0][4] == state.data[0][6]) {
return Winner(uint8(state.data[0][2]));

} else {
return Winner.NONE;
Expand All @@ -66,7 +72,8 @@ contract TTT is DGame {
return false;
}

if (state.data[uint(move.data[0])] != 0) {
// XXX: https://github.com/ethereum/solidity/issues/3270
if (state.data[0][uint(move.data[0])] != 0) {
return false;
}

Expand All @@ -77,17 +84,8 @@ contract TTT is DGame {
State memory next;

next.tag = state.tag + 1;
next.data = new bytes(9);
next.data[0] = state.data[0];
next.data[1] = state.data[1];
next.data[2] = state.data[2];
next.data[3] = state.data[3];
next.data[4] = state.data[4];
next.data[5] = state.data[5];
next.data[6] = state.data[6];
next.data[7] = state.data[7];
next.data[8] = state.data[8];
next.data[uint(move.data[0])] = byte(1 + move.playerID);
// XXX: https://github.com/ethereum/solidity/issues/3270
next.data[0] = state.data[0] | (bytes32(1 + move.playerID) << ((31 - uint(move.data[0])) * 8));

return meta(next);
}
Expand Down

0 comments on commit b2068fb

Please sign in to comment.