Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
emit Predicate events, remove networkId from predicates and resolve s…
Browse files Browse the repository at this point in the history
…ome review comments
  • Loading branch information
atvanguard committed Jun 4, 2019
1 parent 40084b3 commit 1f164c6
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 29 deletions.
24 changes: 14 additions & 10 deletions contracts/common/Registry.sol
Expand Up @@ -19,7 +19,7 @@ contract Registry is Ownable {
mapping(address => bool) public proofValidatorContracts;
mapping(address => bool) public isERC721;

enum Type { Invalid, ERC20, ERC721 }
enum Type { Invalid, ERC20, ERC721, Custom }
struct Predicate {
Type _type;
}
Expand All @@ -28,6 +28,8 @@ contract Registry is Ownable {
event TokenMapped(address indexed rootToken, address indexed childToken);
event ProofValidatorAdded(address indexed validator, address indexed from);
event ProofValidatorRemoved(address indexed validator, address indexed from);
event PredicateAdded(address indexed predicate, address indexed from);
event PredicateRemoved(address indexed predicate, address indexed from);
event ContractMapUpdated(
bytes32 indexed key,
address indexed previousContract,
Expand Down Expand Up @@ -73,15 +75,17 @@ contract Registry is Ownable {
proofValidatorContracts[_validator] = true;
}

function whitelistPredicate(address predicate, uint8 _type) public onlyOwner {
require(predicates[predicate]._type == Type.Invalid, "Predicate already added");
predicates[predicate] = Predicate(Type.Invalid);
if (_type == 1) {
predicates[predicate]._type = Type.ERC20;
} else if (_type == 2) {
predicates[predicate]._type = Type.ERC721;
}
// @todo emit event
function addPredicate(address predicate, Type _type) public onlyOwner
{
require(predicates[predicate]._type == Type.Invalid, "Predicate already added");
predicates[predicate]._type = _type;
emit PredicateAdded(predicate, msg.sender);
}

function removePredicate(address predicate) public onlyOwner
{
delete predicates[predicate];
emit PredicateRemoved(predicate, msg.sender);
}

function removeProofValidator(address _validator) public onlyOwner {
Expand Down
3 changes: 1 addition & 2 deletions contracts/root/predicates/ERC20Predicate.sol
Expand Up @@ -20,7 +20,6 @@ contract ERC20Predicate is IErcPredicate {
bytes4 constant WITHDRAW_FUNC_SIG = 0x2e1a7d4d;
// 0xa9059cbb = keccak256('transfer(address,uint256)').slice(0, 4)
bytes4 constant TRANSFER_FUNC_SIG = 0xa9059cbb;
bytes constant public networkId = "\x0d";

constructor(address _withdrawManager) public IErcPredicate(_withdrawManager) {}

Expand Down Expand Up @@ -239,7 +238,7 @@ contract ERC20Predicate is IErcPredicate {
RLPReader.RLPItem[] memory txList = exitTx.toRlpItem().toList();
require(txList.length == 9, "MALFORMED_WITHDRAW_TX");
childToken = RLPReader.toAddress(txList[3]); // corresponds to "to" field in tx
(participant, txHash) = getAddressFromTx(txList, networkId);
(participant, txHash) = getAddressFromTx(txList, withdrawManager.networkId());
// if (participant == msg.sender) { // exit tx is signed by exitor himself
if (participant == msg.sender) { // exit tx is signed by exitor himself
(exitAmount, burnt) = processExitTxSender(RLPReader.toBytes(txList[5]));
Expand Down
4 changes: 1 addition & 3 deletions contracts/root/predicates/ERC721Predicate.sol
Expand Up @@ -6,7 +6,6 @@ import { RLPEncode } from "../../common/lib/RLPEncode.sol";
import { RLPReader } from "solidity-rlp/contracts/RLPReader.sol";
import { IErcPredicate } from "./IPredicate.sol";
import { Registry } from "../../common/Registry.sol";
// import { WithdrawManager } from "../withdrawManager/WithdrawManager.sol";

contract ERC721Predicate is IErcPredicate {
using RLPReader for bytes;
Expand All @@ -19,7 +18,6 @@ contract ERC721Predicate is IErcPredicate {
bytes4 constant WITHDRAW_FUNC_SIG = 0x2e1a7d4d;
// 0x23b872dd = keccak256('transferFrom(address,address,uint256)').slice(0, 4)
bytes4 constant TRANSFER_FROM_FUNC_SIG = 0x23b872dd;
bytes constant public networkId = "\x0d";

constructor(address _withdrawManager) public IErcPredicate(_withdrawManager) {}

Expand Down Expand Up @@ -191,7 +189,7 @@ contract ERC721Predicate is IErcPredicate {
RLPReader.RLPItem[] memory txList = exitTx.toRlpItem().toList();
require(txList.length == 9, "MALFORMED_WITHDRAW_TX");
childToken = RLPReader.toAddress(txList[3]); // corresponds to "to" field in tx
(participant, txHash) = getAddressFromTx(txList, networkId);
(participant, txHash) = getAddressFromTx(txList, withdrawManager.networkId());
if (participant == msg.sender) { // exit tx is signed by exitor himself
(tokenId, burnt) = processExitTxSender(RLPReader.toBytes(txList[5]));
} else {
Expand Down
1 change: 0 additions & 1 deletion contracts/root/predicates/IPredicate.sol
Expand Up @@ -2,7 +2,6 @@ pragma solidity ^0.5.2;

import { BytesLib } from "../../common/lib/BytesLib.sol";
import { Common } from "../../common/lib/Common.sol";
// import { MerklePatriciaProof } from "../../common/lib/MerklePatriciaProof.sol";
import { RLPEncode } from "../../common/lib/RLPEncode.sol";
import { RLPReader } from "solidity-rlp/contracts/RLPReader.sol";
import { IWithdrawManager } from "../withdrawManager/IWithdrawManager.sol";
Expand Down
4 changes: 3 additions & 1 deletion contracts/root/withdrawManager/IWithdrawManager.sol
@@ -1,8 +1,8 @@
pragma solidity ^0.5.2;

contract IWithdrawManager {
function verifyInclusion(bytes calldata data, uint8 offset, bool verifyTxInclusion) external returns (uint256 age);
function createExitQueue(address token) external;
function verifyInclusion(bytes calldata data, uint8 offset, bool verifyTxInclusion) external returns (uint256 age);
function addExitToQueue(
address exitor,
address childToken,
Expand All @@ -14,4 +14,6 @@ contract IWithdrawManager {
external;
function addInput(uint256 exitId, uint256 age, address signer) external;
function challengeExit(uint256 exitId, uint256 inputId, bytes calldata challengeData) external;
// overridden by inheriting contract
bytes public networkId;
}
25 changes: 15 additions & 10 deletions contracts/root/withdrawManager/WithdrawManager.sol
Expand Up @@ -22,6 +22,13 @@ contract WithdrawManager is WithdrawManagerStorage, IWithdrawManager {
using RLPReader for RLPReader.RLPItem;
using Merkle for bytes32;

function createExitQueue(address token)
external
{
require(msg.sender == address(registry), "UNAUTHORIZED_REGISTRY_ONLY");
exitsQueues[token] = address(new PriorityQueue());
}

function verifyInclusion(bytes calldata data, uint8 offset, bool verifyTxInclusion)
external
returns (uint256 age)
Expand Down Expand Up @@ -74,13 +81,6 @@ contract WithdrawManager is WithdrawManagerStorage, IWithdrawManager {
);
}

function createExitQueue(address token)
external
{
require(msg.sender == address(registry), "UNAUTHORIZED_REGISTRY_ONLY");
exitsQueues[token] = address(new PriorityQueue());
}

modifier isPredicateAuthorized(address rootToken) {
(Registry.Type _type) = registry.predicates(msg.sender);
if (_type == Registry.Type.ERC20) {
Expand Down Expand Up @@ -150,11 +150,16 @@ contract WithdrawManager is WithdrawManagerStorage, IWithdrawManager {
emit ExitStarted(exitor, priority, rootToken, exitAmountOrTokenId, burnt);
}

function addInput(uint256 exitId, uint256 age, address signer) external {
function addInput(uint256 exitId, uint256 age, address signer)
external
{
PlasmaExit storage exitObject = exits[exitId];
// Checks both that
// 1. Exit at the particular exitId exists
// 2. Only the predicate that started the exit is authorized to addInput
require(
exitObject.token != address(0x0),
"EXIT_DOES_NOT_EXIST"
exitObject.predicate == msg.sender,
"EXIT_DOES_NOT_EXIST OR NOT_AUTHORIZED"
);
exitObject.inputs[age] = Input(signer);
emit ExitUpdated(exitId, age, signer);
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/deployer.js
Expand Up @@ -96,13 +96,13 @@ class Deployer {

async deployErc20Predicate() {
const ERC20Predicate = await contracts.ERC20Predicate.new(this.withdrawManagerProxy.address)
await this.registry.whitelistPredicate(ERC20Predicate.address, 1 /* Type.ERC20 */)
await this.registry.addPredicate(ERC20Predicate.address, 1 /* Type.ERC20 */)
return ERC20Predicate
}

async deployErc721Predicate() {
const ERC721Predicate = await contracts.ERC721Predicate.new(this.withdrawManagerProxy.address)
await this.registry.whitelistPredicate(ERC721Predicate.address, 2 /* Type.ERC721 */)
await this.registry.addPredicate(ERC721Predicate.address, 2 /* Type.ERC721 */)
return ERC721Predicate
}

Expand Down

0 comments on commit 1f164c6

Please sign in to comment.