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 19 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.

4 changes: 2 additions & 2 deletions contracts/StateRootInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ pragma solidity ^0.5.0;
interface StateRootInterface {

/**
* @notice Gets the block number of latest committed state root.
* @notice Gets the block number of latest anchored state root.
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
*
* @return uint256 Block height of the latest committed state root.
* @return uint256 Block height of the latest anchored state root.
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
*/
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
6 changes: 3 additions & 3 deletions contracts/gateway/EIP20CoGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ 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 _anchor Anchor contract address.
* @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 +214,14 @@ contract EIP20CoGateway is GatewayBase {
constructor(
address _valueToken,
address _utilityToken,
StateRootInterface _core,
StateRootInterface _anchor,
uint256 _bounty,
IsMemberInterface _membersManager,
address _gateway,
address payable _burner
)
GatewayBase(
_core,
_anchor,
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
_bounty,
_membersManager
)
Expand Down
6 changes: 3 additions & 3 deletions contracts/gateway/EIP20Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ 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 _anchor Anchor contract address.
* @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 +240,13 @@ contract EIP20Gateway is GatewayBase {
constructor(
EIP20Interface _token,
EIP20Interface _baseToken,
StateRootInterface _core,
StateRootInterface _anchor,
uint256 _bounty,
IsMemberInterface _membersManager,
address _burner
)
GatewayBase(
_core,
_anchor,
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
_bounty,
_membersManager
)
Expand Down
18 changes: 9 additions & 9 deletions contracts/gateway/GatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ contract GatewayBase is Organized {
*/
MessageBus.MessageBox messageBox;

/** Address of core contract. */
StateRootInterface public core;
/** Address of anchor contract. */
StateRootInterface public anchor;
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved

/** Path to make Merkle account proof for Gateway/CoGateway contract. */
bytes public encodedGatewayPath;
Expand Down Expand Up @@ -128,25 +128,25 @@ contract GatewayBase is Organized {
/**
* @notice Initialize the contract and set default values.
*
* @param _core Core contract address.
* @param _anchor Anchor contract address.
* @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 _anchor,
uint256 _bounty,
IsMemberInterface _membersManager
)
Organized(_membersManager)
public
{
require(
address(_core) != address(0),
"Core contract address must not be zero."
address(_anchor) != address(0),
"Anchor contract address must not be zero."
);

core = _core;
anchor = _anchor;

bounty = _bounty;
}
Expand All @@ -156,7 +156,7 @@ contract GatewayBase is Organized {
/**
* @notice proveGateway 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
* stateRoots mapping. stateRoot is anchored in anchorStateRoot
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
* 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
Expand Down Expand Up @@ -192,7 +192,7 @@ contract GatewayBase is Organized {
"Length of RLP parent nodes is 0"
);

bytes32 stateRoot = core.getStateRoot(_blockHeight);
bytes32 stateRoot = anchor.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 @@ -126,7 +126,7 @@ library GatewayLib {
);

/**
* Verify the remote OpenST contract against the committed state
* Verify the remote OpenST contract against the anchored state
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
* root with the state trie Merkle proof
*/
require(MerklePatriciaProof.verify(hashedAccount, _encodedPath,
Expand Down
6 changes: 3 additions & 3 deletions contracts/test/TestEIP20CoGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ 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 _anchor Anchor contract address.
* @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 +48,7 @@ contract TestEIP20CoGateway is EIP20CoGateway {
constructor(
address _valueToken,
address _utilityToken,
StateRootInterface _core,
StateRootInterface _anchor,
uint256 _bounty,
IsMemberInterface _membersManager,
address _gateway,
Expand All @@ -57,7 +57,7 @@ contract TestEIP20CoGateway is EIP20CoGateway {
EIP20CoGateway(
_valueToken,
_utilityToken,
_core,
_anchor,
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
_bounty,
_membersManager,
_gateway,
Expand Down
6 changes: 3 additions & 3 deletions contracts/test/TestEIP20Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ 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 _anchor Anchor contract address.
* @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 +45,15 @@ contract TestEIP20Gateway is EIP20Gateway {
constructor(
EIP20Interface _token,
EIP20Interface _baseToken,
StateRootInterface _core,
StateRootInterface _anchor,
uint256 _bounty,
IsMemberInterface _membersManager,
address payable _burner
)
EIP20Gateway(
_token,
_baseToken,
_core,
_anchor,
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
_bounty,
_membersManager,
_burner
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
pragma solidity ^0.5.0;

import "../../gateway/SafeCore.sol";
import "../../gateway/Anchor.sol";

/**
* @title MockSafeCore contract
* @title MockAnchor contract.
*
* @notice Used for test only
* @notice Used for test only.
*/
contract MockSafeCore is SafeCore {

contract MockAnchor is Anchor {

/* Public functions */

/**
* @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 All @@ -30,7 +29,7 @@ contract MockSafeCore is SafeCore {
uint256 _maxStateRoots,
IsMemberInterface _membersManager
)
SafeCore(
Anchor(
schemar marked this conversation as resolved.
Show resolved Hide resolved
_remoteChainId,
_blockHeight,
_stateRoot,
Expand All @@ -44,7 +43,7 @@ contract MockSafeCore is SafeCore {
* @notice Get the mocked state root.
*
* @dev This is for testing only so the data is mocked here. Also please
* note the Core contract has defined this function as view,
* note the Anchor contract has defined this function as view,
* so to keep this overridden function as view, reading a storage
* variable.
*
Expand Down
Loading