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

Renamed SafeCore to Anchor #549

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
24119cd
Renamed SafeCore contract and references of safecore to anchor
gulshanvasnani Dec 14, 2018
71a8f81
Modified the documentation
gulshanvasnani Dec 14, 2018
4116f54
Changed the name of the setCoCoreAddress method to setCoAnchorAddress…
gulshanvasnani Dec 15, 2018
f49e0df
Merge branch 'develop' into gulshan/gh_537_safecore_to_anchor
0xsarvesh Dec 17, 2018
cdf2b22
Changes done as per PR feedback
gulshanvasnani Dec 18, 2018
eb7934a
Merge branch 'gulshan/gh_537_safecore_to_anchor' of https://github.co…
gulshanvasnani Dec 18, 2018
e66da54
Changed all references of core in the constructor
gulshanvasnani Dec 18, 2018
8bf24fb
Changed all references of core in the constructor
gulshanvasnani Dec 18, 2018
ec32ef1
Merge remote-tracking branch 'upstream/develop' into gulshan/gh_537_s…
gulshanvasnani Dec 18, 2018
115d5a9
Merge branch 'develop' into gulshan/gh_537_safecore_to_anchor
0xsarvesh Dec 18, 2018
659132c
Merge remote-tracking branch 'upstream/develop' into gulshan/gh_537_s…
gulshanvasnani Dec 19, 2018
feee710
Merge branch 'gulshan/gh_537_safecore_to_anchor' of https://github.co…
gulshanvasnani Dec 19, 2018
ca4e4ae
Fixed styling
gulshanvasnani Dec 19, 2018
e5377c4
Added maxNumberStateRoots in the constructor and updated the unit tes…
gulshanvasnani Dec 19, 2018
8956788
Merge branch 'develop' into gulshan/gh_537_safecore_to_anchor
gulshanvasnani Dec 19, 2018
469088c
Merge remote-tracking branch 'upstream/develop' into gulshan/gh_537_s…
gulshanvasnani Dec 19, 2018
667c5fd
Deleting safe core unit test-cases
gulshanvasnani Dec 19, 2018
7626721
Renamed of variable to mockAnchor from mockSafeCore
gulshanvasnani Dec 19, 2018
6075fcc
Merge branch 'gulshan/gh_537_safecore_to_anchor' of https://github.co…
gulshanvasnani Dec 19, 2018
b7cbd2d
Changes done for introducing generic name for variable name for state…
gulshanvasnani Dec 19, 2018
8c04438
Merge branch 'develop' into gulshan/gh_537_safecore_to_anchor
Dec 19, 2018
630bcf6
Changes done to update unit test cases,documentation for stateRootInt…
gulshanvasnani Dec 19, 2018
a4db386
Merge branch 'gulshan/gh_537_safecore_to_anchor' of https://github.co…
gulshanvasnani Dec 19, 2018
34030e3
Changes done to update unit test cases messages and corrected js styling
gulshanvasnani Dec 19, 2018
8735258
Code cleanup and updated documentation as suggested in PR feedback
gulshanvasnani Dec 20, 2018
aff1bde
Added license in the contract and updated documentation
gulshanvasnani Dec 21, 2018
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
2 changes: 1 addition & 1 deletion .solcover.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/StateRootInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface StateRootInterface {
/**
* @notice Gets the block number of latest committed state root.
*
* @return uint256 Block height of the latest committed state root.
* @return height_ Block height of the latest committed state root.
*/
function getLatestStateRootBlockHeight()
external
Expand Down
58 changes: 29 additions & 29 deletions contracts/gateway/SafeCore.sol → contracts/gateway/Anchor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pragma solidity ^0.5.0;
//
// ----------------------------------------------------------------------------


import "./WorkersInterface.sol";
import "../StateRootInterface.sol";
import "../lib/CircularBufferUint.sol";
Expand All @@ -31,15 +30,15 @@ import "../lib/RLP.sol";
import "../lib/SafeMath.sol";

/**
* @title SafeCore contract which implements StateRootInterface.
* @title Anchor contract which implements StateRootInterface.
*
* @notice SafeCore stores another chain's state roots. It stores the address of
* the co-core, which will be the safe core on the other chain. State
* roots are exchanged bidirectionally between the core and the co-core
* by the workers that are registered as part of the `Organized`
* interface.
* @notice Anchor stores another chain's state roots. It stores the address of
* the co-anchor, which will be the anchor on the other chain. State
* roots are exchanged bidirectionally between the anchor and the
* co-anchor by the workers that are registered as part of the
* `Organized` interface.
*/
contract SafeCore is StateRootInterface, Organized, CircularBufferUint {
contract Anchor is StateRootInterface, Organized, CircularBufferUint {

/* Usings */

Expand All @@ -57,13 +56,13 @@ contract SafeCore is StateRootInterface, Organized, CircularBufferUint {
mapping (uint256 => bytes32) private stateRoots;

/**
* The remote chain ID is the remote chain id where core contract is
* The remote chain ID is the remote chain id where anchor contract is
* deployed.
*/
uint256 private remoteChainId;

/** Address of the core on the auxiliary chain. Can be zero. */
address public coCore;
/** Address of the anchor on the auxiliary chain. Can be zero. */
address public coAnchor;


/* Constructor */
Expand All @@ -72,7 +71,7 @@ contract SafeCore is StateRootInterface, Organized, CircularBufferUint {
* @notice Contract constructor.
*
* @param _remoteChainId The chain id of the chain that is tracked by this
* core.
* anchor.
* @param _blockHeight Block height at which _stateRoot needs to store.
* @param _stateRoot State root hash of given _blockHeight.
* @param _maxStateRoots The max number of state roots to store in the
Expand Down Expand Up @@ -105,27 +104,28 @@ contract SafeCore is StateRootInterface, Organized, CircularBufferUint {
/* External functions */

/**
* @notice The Co-Core address is the address of the core that is
* @notice The Co-Anchor address is the address of the anchor that is
* deployed on the other (origin/auxiliary) chain.
*
* @param _coCore Address of the Co-Core on auxiliary.
* @param _coAnchor Address of the Co-Anchor on auxiliary.
*/
function setCoCoreAddress(address _coCore)
function setCoAnchorAddress(address _coAnchor)
external
onlyOrganization
returns (bool success_)
{

require(
coCore == address(0),
"Co-Core has already been set and cannot be updated."
_coAnchor != address(0),
"Co-Anchor address must not be 0."
);

require(
_coCore != address(0),
"Co-Core address must not be 0."
coAnchor == address(0),
"Co-Anchor has already been set and cannot be updated."
);

coCore = _coCore;
coAnchor = _coAnchor;

success_ = true;
}
Expand All @@ -148,9 +148,9 @@ contract SafeCore is StateRootInterface, Organized, CircularBufferUint {
}

/**
* @notice Gets the block height of latest committed state root.
* @notice Gets the block height of latest anchored state root.
*
* @return uint256 Block height of the latest committed state root.
* @return uint256 Block height of the latest anchored state root.
*/
function getLatestStateRootBlockHeight()
external
Expand All @@ -161,18 +161,18 @@ contract SafeCore is StateRootInterface, Organized, CircularBufferUint {
}

/**
* @notice External function commitStateRoot.
* @notice External function anchorStateRoot.
*
* @dev commitStateRoot Called from game process.
* Commit new state root for a block height.
* @dev anchorStateRoot Called from game process.
* Anchor new state root for a block height.
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
*
* @param _blockHeight Block height for which stateRoots mapping needs to
* update.
* @param _stateRoot State root of input block height.
*
* @return bytes32 stateRoot
*/
function commitStateRoot(
function anchorStateRoot(
uint256 _blockHeight,
bytes32 _stateRoot
)
Expand All @@ -186,10 +186,10 @@ contract SafeCore is StateRootInterface, Organized, CircularBufferUint {
"State root must not be zero."
);

// Input block height should be valid
// Input block height should be valid.
require(
_blockHeight > CircularBufferUint.head(),
"Given block height is lower or equal to highest committed state root block height."
"Given block height is lower or equal to highest anchored state root block height."
);

stateRoots[_blockHeight] = _stateRoot;
Expand All @@ -202,7 +202,7 @@ contract SafeCore is StateRootInterface, Organized, CircularBufferUint {
}

/**
* @notice Get the remote chain id of this core.
* @notice Get the remote chain id of this anchor.
*
* @return remoteChainId_ The remote chain id.
*/
Expand Down
7 changes: 4 additions & 3 deletions contracts/gateway/EIP20CoGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ contract EIP20CoGateway is GatewayBase {
* @param _valueToken The value token contract address.
* @param _utilityToken The utility token address that will be used for
* minting the utility token.
* @param _core Core contract address.
* @param _stateRootProvider Contract address which implements
* StateRootInterface.
* @param _bounty The amount that facilitator stakes to initiate the stake
* process.
* @param _membersManager Address of a contract that manages workers.
Expand All @@ -214,14 +215,14 @@ contract EIP20CoGateway is GatewayBase {
constructor(
address _valueToken,
address _utilityToken,
StateRootInterface _core,
StateRootInterface _stateRootProvider,
uint256 _bounty,
IsMemberInterface _membersManager,
address _gateway,
address payable _burner
)
GatewayBase(
_core,
_stateRootProvider,
_bounty,
_membersManager
)
Expand Down
7 changes: 4 additions & 3 deletions contracts/gateway/EIP20Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ contract EIP20Gateway is GatewayBase {
* in auxiliary chain.
* @param _baseToken The ERC20 token address that will be used for
* staking bounty from the facilitators.
* @param _core Core contract address.
* @param _stateRootProvider Contract address which implements
* StateRootInterface.
* @param _bounty The amount that facilitator will stakes to initiate the
* stake process.
* @param _membersManager Address of a contract that manages workers.
Expand All @@ -240,13 +241,13 @@ contract EIP20Gateway is GatewayBase {
constructor(
EIP20Interface _token,
EIP20Interface _baseToken,
StateRootInterface _core,
StateRootInterface _stateRootProvider,
uint256 _bounty,
IsMemberInterface _membersManager,
address _burner
)
GatewayBase(
_core,
_stateRootProvider,
_bounty,
_membersManager
)
Expand Down
55 changes: 39 additions & 16 deletions contracts/gateway/GatewayBase.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
pragma solidity ^0.5.0;

// Copyright 2018 OpenST Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ----------------------------------------------------------------------------
// Origin Chain: Gateway Contract
//
// http://www.simpletoken.org/
//
// ----------------------------------------------------------------------------

import "./EIP20Interface.sol";
import "../lib/MessageBus.sol";
import "../StateRootInterface.sol";
Expand All @@ -8,7 +29,6 @@ import "../lib/IsMemberInterface.sol";
import "../lib/Organized.sol";
import "../lib/SafeMath.sol";


/**
* @title GatewayBase contract.
*
Expand Down Expand Up @@ -74,8 +94,10 @@ contract GatewayBase is Organized {
*/
MessageBus.MessageBox messageBox;

/** Address of core contract. */
StateRootInterface public core;
/**
* Address of contract which implements StateRootInterface.
*/
StateRootInterface public stateRootProvider;

/** Path to make Merkle account proof for Gateway/CoGateway contract. */
bytes public encodedGatewayPath;
Expand Down Expand Up @@ -128,40 +150,41 @@ contract GatewayBase is Organized {
/**
* @notice Initialize the contract and set default values.
*
* @param _core Core contract address.
* @param _stateRootProvider Contract address which implements
* StateRootInterface.
* @param _bounty The amount that facilitator will stakes to initiate the
* stake process.
* @param _membersManager Address of a contract that manages workers.
*/
constructor(
StateRootInterface _core,
StateRootInterface _stateRootProvider,
uint256 _bounty,
IsMemberInterface _membersManager
)
Organized(_membersManager)
public
{
require(
address(_core) != address(0),
"Core contract address must not be zero."
address(_stateRootProvider) != address(0),
"State root provider contract address must not be zero."
);

core = _core;
stateRootProvider = _stateRootProvider;

bounty = _bounty;
}


/* External functions */

/**
* @notice proveGateway can be called by anyone to verify merkle proof of
* @notice This can be called by anyone to verify merkle proof of
* gateway/co-gateway contract address. Trust factor is brought by
* stateRoots mapping. stateRoot is committed in commitStateRoot
* function by mosaic process which is a trusted decentralized system
* running separately. It's important to note that in replay calls of
* proveGateway bytes _rlpParentNodes variable is not validated. In
* this case input storage root derived from merkle proof account
* nodes is verified with stored storage root of given blockHeight.
* state roots of the contract which implements StateRootInterface.
* It's important to note that in replay calls of proveGateway
* bytes _rlpParentNodes variable is not validated. In this case
* input storage root derived from merkle proof account nodes is
* verified with stored storage root of given blockHeight.
* GatewayProven event has parameter wasAlreadyProved to
* differentiate between first call and replay calls.
*
Expand Down Expand Up @@ -192,7 +215,7 @@ contract GatewayBase is Organized {
"Length of RLP parent nodes is 0"
);

bytes32 stateRoot = core.getStateRoot(_blockHeight);
bytes32 stateRoot = stateRootProvider.getStateRoot(_blockHeight);

// State root should be present for the block height
require(
Expand Down
2 changes: 1 addition & 1 deletion contracts/lib/GatewayLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ library GatewayLib {

/**
* Verify the remote OpenST contract against the committed state
* root with the state trie Merkle proof
* root with the state trie Merkle proof.
*/
require(MerklePatriciaProof.verify(hashedAccount, _encodedPath,
_rlpParentNodes, _stateRoot), "Account proof is not verified.");
Expand Down
7 changes: 4 additions & 3 deletions contracts/test/TestEIP20CoGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ contract TestEIP20CoGateway is EIP20CoGateway {
* @param _valueToken The value token contract address.
* @param _utilityToken The utility token address that will be used for
* minting the utility token.
* @param _core Core contract address.
* @param _stateRootProvider Contract address which implements
* StateRootInterface.
* @param _bounty The amount that facilitator will stakes to initiate the
* staking process.
* @param _membersManager Address of a members manager contract.
Expand All @@ -48,7 +49,7 @@ contract TestEIP20CoGateway is EIP20CoGateway {
constructor(
address _valueToken,
address _utilityToken,
StateRootInterface _core,
StateRootInterface _stateRootProvider,
uint256 _bounty,
IsMemberInterface _membersManager,
address _gateway,
Expand All @@ -57,7 +58,7 @@ contract TestEIP20CoGateway is EIP20CoGateway {
EIP20CoGateway(
_valueToken,
_utilityToken,
_core,
_stateRootProvider,
_bounty,
_membersManager,
_gateway,
Expand Down
7 changes: 4 additions & 3 deletions contracts/test/TestEIP20Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ contract TestEIP20Gateway is EIP20Gateway {
* in auxiliary chain.
* @param _baseToken The ERC20 token address that will be used for
* staking bounty from the facilitators.
* @param _core Core contract address.
* @param _stateRootProvider Contract address which implements
* StateRootInterface.
* @param _bounty The amount that facilitator will stakes to initiate the
* stake process.
* @param _membersManager Address of a contract that manages workers.
Expand All @@ -45,15 +46,15 @@ contract TestEIP20Gateway is EIP20Gateway {
constructor(
EIP20Interface _token,
EIP20Interface _baseToken,
StateRootInterface _core,
StateRootInterface _stateRootProvider,
uint256 _bounty,
IsMemberInterface _membersManager,
address payable _burner
)
EIP20Gateway(
_token,
_baseToken,
_core,
_stateRootProvider,
_bounty,
_membersManager,
_burner
Expand Down
Loading