Skip to content

Commit

Permalink
Updated repository to solidity 0.5.0
Browse files Browse the repository at this point in the history
All contracts now have the `^0.5.0` pragma.
There were quite some changes required to port the code. The most
notable changes are:

* In the `KernelGateway` there was a problem with the mapping to a
struct that contained two structs. Instead, there are now two separate
mappings for the contained structs of the original mapping.
* You cannot create functions anymore that have the same name that a
function created from a public variable has (shadow). I had to rename
some interface and contract methods to avoid the collision.
* Very important to check are the changes to the library contracts.
* The test util `expectThrow` now also expects an "invalid address"
passed to a function.
* When casting from `uint` to fixed size bytes (e.g. `bytes32`), uints
must first be cast to the correct bytelength uint type.
* When using the address of a contract, it is now explicitly cast to
`address`.
* When casting a contract to a different interface, it must be cast to
`address` first.
* Some functions were re-ordered based on their visibility modifiers.
* Some style guide related clean-up.

Fixes #479
  • Loading branch information
schemar committed Nov 29, 2018
1 parent cd387d6 commit a648856
Show file tree
Hide file tree
Showing 91 changed files with 3,481 additions and 3,077 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ before_install:
install:
- npm install
before_script:
- nohup ./tools/runGanacheCli.sh </dev/null >/dev/null 2>&1 &
- ./tools/runGanacheCli.sh </dev/null 1>/dev/null 2>&1 &
script:
- npm run test
after_script:
Expand Down
2 changes: 1 addition & 1 deletion contracts/OstInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.5.0;

// Copyright 2018 OpenST Ltd.
//
Expand Down
2 changes: 1 addition & 1 deletion contracts/StateRootInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.5.0;

// Copyright 2018 OpenST Ltd.
//
Expand Down
14 changes: 7 additions & 7 deletions contracts/core/AuxiliaryBlockStore.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.5.0;

// Copyright 2018 OpenST Ltd.
//
Expand Down Expand Up @@ -156,20 +156,20 @@ contract AuxiliaryBlockStore is
*
* @param _kernelGateway The kernel gateway address.
*/
function initialize(address _kernelGateway)
function initialize(KernelGatewayInterface _kernelGateway)
external
{
require(
_kernelGateway != address(0),
address(_kernelGateway) != address(0),
"Kernel gateway address must not be zero."
);

require(
kernelGateway == address(0),
address(kernelGateway) == address(0),
"Kernel gateway must not be already initialized."
);

kernelGateway = KernelGatewayInterface(_kernelGateway);
kernelGateway = _kernelGateway;
}

/**
Expand All @@ -179,7 +179,7 @@ contract AuxiliaryBlockStore is
* @param _blockHeaderRlp The header of the reported block, RLP encoded.
*/
function reportBlock(
bytes _blockHeaderRlp
bytes calldata _blockHeaderRlp
)
external
returns (bool success_)
Expand Down Expand Up @@ -328,7 +328,7 @@ contract AuxiliaryBlockStore is
)
internal
view
returns (bool valid_, string reason_)
returns (bool valid_, string memory reason_)
{
(valid_, reason_) = super.isTargetValid(
_sourceBlockHash,
Expand Down
2 changes: 1 addition & 1 deletion contracts/core/AuxiliaryTransitionObjectInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.5.0;

// Copyright 2018 OpenST Ltd.
//
Expand Down
8 changes: 4 additions & 4 deletions contracts/core/BlockStore.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.5.0;

// Copyright 2018 OpenST Ltd.
//
Expand Down Expand Up @@ -235,7 +235,7 @@ contract BlockStore is BlockStoreInterface, OriginTransitionObjectInterface {
* @param _blockHeaderRlp The header of the reported block, RLP encoded.
*/
function reportBlock(
bytes _blockHeaderRlp
bytes calldata _blockHeaderRlp
)
external
returns (bool success_)
Expand Down Expand Up @@ -563,7 +563,7 @@ contract BlockStore is BlockStoreInterface, OriginTransitionObjectInterface {
)
internal
view
returns (bool valid_, string reason_)
returns (bool valid_, string memory reason_)
{
if (!isReported(_targetBlockHash)) {
valid_ = false;
Expand Down Expand Up @@ -666,7 +666,7 @@ contract BlockStore is BlockStoreInterface, OriginTransitionObjectInterface {
)
private
view
returns (bool valid_, string reason_)
returns (bool valid_, string memory reason_)
{
if(!isReported(_sourceBlockHash)) {
valid_ = false;
Expand Down
4 changes: 2 additions & 2 deletions contracts/core/BlockStoreInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.5.0;

// Copyright 2018 OpenST Ltd.
//
Expand Down Expand Up @@ -40,7 +40,7 @@ interface BlockStoreInterface {
* @return `true` if the report succeeded.
*/
function reportBlock(
bytes _blockHeaderRlp
bytes calldata _blockHeaderRlp
)
external
returns (bool success_);
Expand Down
7 changes: 4 additions & 3 deletions contracts/core/InitializeGatewayKernelInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.5.0;

// Copyright 2018 OpenST Ltd.
//
Expand All @@ -14,16 +14,17 @@ pragma solidity ^0.4.23;
// See the License for the specific language governing permissions and
// limitations under the License.

/** @title The interface for opening the new kernel on auxiliary. */
import "./KernelGatewayInterface.sol";

/** @title The interface for opening the new kernel on auxiliary. */
interface InitializeGatewayKernelInterface {

/**
* @notice Set kernel gateway
*
* @param _kernelGateway The kernel gateway address
*/
function initialize(address _kernelGateway)
function initialize(KernelGatewayInterface _kernelGateway)
external;

}
45 changes: 22 additions & 23 deletions contracts/core/KernelGateway.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.5.0;

// Copyright 2018 OpenST Ltd.
//
Expand All @@ -24,7 +24,7 @@ import "./AuxiliaryTransitionObjectInterface.sol";
import "./KernelGatewayInterface.sol";

/** @title The kernel gateway on auxiliary. */
contract KernelGateway is KernelGatewayInterface{
contract KernelGateway is KernelGatewayInterface {
using SafeMath for uint256;

/* Events */
Expand Down Expand Up @@ -136,12 +136,12 @@ contract KernelGateway is KernelGatewayInterface{
);

require(
_originBlockStore != address(0),
address(_originBlockStore) != address(0),
"The address of the origin block store must not be zero."
);

require(
_auxiliaryBlockStore != address(0),
address(_auxiliaryBlockStore) != address(0),
"The address of the auxiliary block store must not be zero."
);

Expand All @@ -168,7 +168,7 @@ contract KernelGateway is KernelGatewayInterface{
);

bytes memory indexBytes = BytesLib.leftPad(
BytesLib.bytes32ToBytes(bytes32(KERNEL_HASH_INDEX))
BytesLib.bytes32ToBytes(bytes32(uint256(KERNEL_HASH_INDEX)))
);

storagePath = BytesLib.bytes32ToBytes(
Expand All @@ -195,8 +195,8 @@ contract KernelGateway is KernelGatewayInterface{
* @return success_ `true` if the proof is successful.
*/
function proveOriginCore(
bytes _accountRlp,
bytes _accountBranchRlp,
bytes calldata _accountRlp,
bytes calldata _accountBranchRlp,
uint256 _originBlockHeight
)
external
Expand Down Expand Up @@ -281,10 +281,10 @@ contract KernelGateway is KernelGatewayInterface{
function proveBlockOpening(
uint256 _height,
bytes32 _parent,
address[] _updatedValidators,
uint256[] _updatedWeights,
address[] calldata _updatedValidators,
uint256[] calldata _updatedWeights,
bytes32 _auxiliaryBlockHash,
bytes _storageBranchRlp,
bytes calldata _storageBranchRlp,
uint256 _originBlockHeight
)
external
Expand Down Expand Up @@ -494,8 +494,8 @@ contract KernelGateway is KernelGatewayInterface{
external
view
returns (
address[] updatedValidators_,
uint256[] updatedWeights_
address[] memory updatedValidators_,
uint256[] memory updatedWeights_
)
{
MetaBlock.Kernel storage kernel = kernels[_kernelHash];
Expand Down Expand Up @@ -532,9 +532,9 @@ contract KernelGateway is KernelGatewayInterface{
* @return bytes32 Storage path of the variable.
*/
function getStorageRoot(
bytes _accountRlp,
bytes _accountBranchRlp,
bytes _encodedPath,
bytes memory _accountRlp,
bytes memory _accountBranchRlp,
bytes storage _encodedPath,
bytes32 _stateRoot
)
internal
Expand Down Expand Up @@ -589,9 +589,9 @@ contract KernelGateway is KernelGatewayInterface{
* @return bytes32 Storage path of the variable.
*/
function updateStorageRoot(
bytes _accountRlp,
bytes _accountBranchRlp,
bytes _encodedPath,
bytes memory _accountRlp,
bytes memory _accountBranchRlp,
bytes storage _encodedPath,
bytes32 _stateRoot,
uint256 _blockHeight
)
Expand Down Expand Up @@ -625,8 +625,8 @@ contract KernelGateway is KernelGatewayInterface{
*/
function verify(
bytes32 _value,
bytes _encodedPath,
bytes _rlpParentNodes,
bytes memory _encodedPath,
bytes memory _rlpParentNodes,
bytes32 _root
)
internal
Expand Down Expand Up @@ -659,9 +659,8 @@ contract KernelGateway is KernelGatewayInterface{
returns (bytes32 metaBlockHash_)
{
bytes32 transitionHash =
AuxiliaryTransitionObjectInterface(auxiliaryBlockStore).auxiliaryTransitionHashAtBlock(
_blockHash
);
AuxiliaryTransitionObjectInterface(address(auxiliaryBlockStore))
.auxiliaryTransitionHashAtBlock(_blockHash);

metaBlockHash_ = MetaBlock.hashMetaBlock(
activeKernelHash,
Expand Down
16 changes: 8 additions & 8 deletions contracts/core/KernelGatewayInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.5.0;

// Copyright 2018 OpenST Ltd.
//
Expand Down Expand Up @@ -32,8 +32,8 @@ interface KernelGatewayInterface {
* @return success_ `true` if the proof is successful.
*/
function proveOriginCore(
bytes _accountRlp,
bytes _accountBranchRlp,
bytes calldata _accountRlp,
bytes calldata _accountBranchRlp,
uint256 _originBlockHeight
)
external
Expand Down Expand Up @@ -68,10 +68,10 @@ interface KernelGatewayInterface {
function proveBlockOpening(
uint256 _height,
bytes32 _parent,
address[] _updatedValidators,
uint256[] _updatedWeights,
address[] calldata _updatedValidators,
uint256[] calldata _updatedWeights,
bytes32 _auxiliaryBlockHash,
bytes _storageBranchRlp,
bytes calldata _storageBranchRlp,
uint256 _originBlockHeight
)
external
Expand Down Expand Up @@ -120,8 +120,8 @@ interface KernelGatewayInterface {
external
view
returns (
address[] updatedValidators_,
uint256[] updatedWeights_
address[] memory updatedValidators_,
uint256[] memory updatedWeights_
);

/**
Expand Down
Loading

0 comments on commit a648856

Please sign in to comment.