Skip to content

Commit

Permalink
Reformat source code of some contracts, scripts and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evercoinx committed Sep 20, 2024
1 parent 90e4853 commit d7f1644
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 215 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run check && npm test
npm run format && npm run lint && npm run check && npm test
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
.vscode/
artifacts/
cache/
contracts/ChildPool.sol
contracts/interfaces/IChildPool.sol
coverage/
crytic-corpus/
crytic-export/
Expand Down
4 changes: 2 additions & 2 deletions contracts/MaticX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ contract MaticX is
);

IValidatorShare(userRequest.validatorAddress).unstakeClaimTokens_newPOL(
userRequest.validatorNonce
);
userRequest.validatorNonce
);

userRequests[_idx] = userRequests[userRequests.length - 1];
userRequests.pop();
Expand Down
129 changes: 48 additions & 81 deletions contracts/lib/ExitPayloadReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ library ExitPayloadReader {
}

// copy paste of private copy() from RLPReader to avoid changing of existing contracts
function copy(
uint256 src,
uint256 dest,
uint256 len
) private pure {
function copy(uint256 src, uint256 dest, uint256 len) private pure {
if (len == 0) return;

// copy as many word sizes as possible
Expand All @@ -46,77 +42,61 @@ library ExitPayloadReader {
}

// left over bytes. Mask is used to remove unwanted bytes from the word
uint256 mask = 256**(WORD_SIZE - len) - 1;
uint256 mask = 256 ** (WORD_SIZE - len) - 1;
assembly {
let srcpart := and(mload(src), not(mask)) // zero out src
let destpart := and(mload(dest), mask) // retrieve the bytes
mstore(dest, or(destpart, srcpart))
}
}

function toExitPayload(bytes memory data)
internal
pure
returns (ExitPayload memory)
{
function toExitPayload(
bytes memory data
) internal pure returns (ExitPayload memory) {
RLPReader.RLPItem[] memory payloadData = data.toRlpItem().toList();

return ExitPayload(payloadData);
}

function getHeaderNumber(ExitPayload memory payload)
internal
pure
returns (uint256)
{
function getHeaderNumber(
ExitPayload memory payload
) internal pure returns (uint256) {
return payload.data[0].toUint();
}

function getBlockProof(ExitPayload memory payload)
internal
pure
returns (bytes memory)
{
function getBlockProof(
ExitPayload memory payload
) internal pure returns (bytes memory) {
return payload.data[1].toBytes();
}

function getBlockNumber(ExitPayload memory payload)
internal
pure
returns (uint256)
{
function getBlockNumber(
ExitPayload memory payload
) internal pure returns (uint256) {
return payload.data[2].toUint();
}

function getBlockTime(ExitPayload memory payload)
internal
pure
returns (uint256)
{
function getBlockTime(
ExitPayload memory payload
) internal pure returns (uint256) {
return payload.data[3].toUint();
}

function getTxRoot(ExitPayload memory payload)
internal
pure
returns (bytes32)
{
function getTxRoot(
ExitPayload memory payload
) internal pure returns (bytes32) {
return bytes32(payload.data[4].toUint());
}

function getReceiptRoot(ExitPayload memory payload)
internal
pure
returns (bytes32)
{
function getReceiptRoot(
ExitPayload memory payload
) internal pure returns (bytes32) {
return bytes32(payload.data[5].toUint());
}

function getReceipt(ExitPayload memory payload)
internal
pure
returns (Receipt memory receipt)
{
function getReceipt(
ExitPayload memory payload
) internal pure returns (Receipt memory receipt) {
receipt.raw = payload.data[6].toBytes();
RLPReader.RLPItem memory receiptItem = receipt.raw.toRlpItem();

Expand All @@ -142,44 +122,34 @@ library ExitPayloadReader {
return receipt;
}

function getReceiptProof(ExitPayload memory payload)
internal
pure
returns (bytes memory)
{
function getReceiptProof(
ExitPayload memory payload
) internal pure returns (bytes memory) {
return payload.data[7].toBytes();
}

function getBranchMaskAsBytes(ExitPayload memory payload)
internal
pure
returns (bytes memory)
{
function getBranchMaskAsBytes(
ExitPayload memory payload
) internal pure returns (bytes memory) {
return payload.data[8].toBytes();
}

function getBranchMaskAsUint(ExitPayload memory payload)
internal
pure
returns (uint256)
{
function getBranchMaskAsUint(
ExitPayload memory payload
) internal pure returns (uint256) {
return payload.data[8].toUint();
}

function getReceiptLogIndex(ExitPayload memory payload)
internal
pure
returns (uint256)
{
function getReceiptLogIndex(
ExitPayload memory payload
) internal pure returns (uint256) {
return payload.data[9].toUint();
}

// Receipt methods
function toBytes(Receipt memory receipt)
internal
pure
returns (bytes memory)
{
function toBytes(
Receipt memory receipt
) internal pure returns (bytes memory) {
return receipt.raw;
}

Expand All @@ -195,11 +165,9 @@ library ExitPayloadReader {
return RLPReader.toAddress(log.list[0]);
}

function getTopics(Log memory log)
internal
pure
returns (LogTopics memory)
{
function getTopics(
Log memory log
) internal pure returns (LogTopics memory) {
return LogTopics(log.list[1].toList());
}

Expand All @@ -212,11 +180,10 @@ library ExitPayloadReader {
}

// LogTopics methods
function getField(LogTopics memory topics, uint256 index)
internal
pure
returns (RLPReader.RLPItem memory)
{
function getField(
LogTopics memory topics,
uint256 index
) internal pure returns (RLPReader.RLPItem memory) {
return topics.data[index];
}
}
2 changes: 1 addition & 1 deletion contracts/lib/Merkle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ library Merkle {
uint256 proofHeight = proof.length / 32;
// Proof of size n means, height of the tree is n+1.
// In a tree of height n+1, max #leafs possible is 2 ^ n
require(index < 2**proofHeight, "Leaf index is too big");
require(index < 2 ** proofHeight, "Leaf index is too big");

bytes32 proofElement;
bytes32 computedHash = leaf;
Expand Down
17 changes: 7 additions & 10 deletions contracts/lib/MerklePatriciaProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,9 @@ library MerklePatriciaProof {
}

// bytes b must be hp encoded
function _getNibbleArray(bytes memory b)
internal
pure
returns (bytes memory)
{
function _getNibbleArray(
bytes memory b
) internal pure returns (bytes memory) {
bytes memory nibbles = "";
if (b.length > 0) {
uint8 offset;
Expand All @@ -147,11 +145,10 @@ library MerklePatriciaProof {
return nibbles;
}

function _getNthNibbleOfBytes(uint256 n, bytes memory str)
private
pure
returns (bytes1)
{
function _getNthNibbleOfBytes(
uint256 n,
bytes memory str
) private pure returns (bytes1) {
return
bytes1(
n % 2 == 0 ? uint8(str[n / 2]) / 0x10 : uint8(str[n / 2]) % 0x10
Expand Down
64 changes: 23 additions & 41 deletions contracts/lib/RLPReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ library RLPReader {
/*
* @param item RLP encoded bytes
*/
function toRlpItem(bytes memory item)
internal
pure
returns (RLPItem memory)
{
function toRlpItem(
bytes memory item
) internal pure returns (RLPItem memory) {
uint256 memPtr;
assembly {
memPtr := add(item, 0x20)
Expand All @@ -67,11 +65,9 @@ library RLPReader {
* @param self The RLP item.
* @return An 'Iterator' over the item.
*/
function iterator(RLPItem memory self)
internal
pure
returns (Iterator memory)
{
function iterator(
RLPItem memory self
) internal pure returns (Iterator memory) {
require(isList(self));

uint256 ptr = self.memPtr + _payloadOffset(self.memPtr);
Expand All @@ -95,11 +91,9 @@ library RLPReader {
/*
* @param item RLP encoded list in bytes
*/
function toList(RLPItem memory item)
internal
pure
returns (RLPItem[] memory)
{
function toList(
RLPItem memory item
) internal pure returns (RLPItem[] memory) {
require(isList(item));

uint256 items = numItems(item);
Expand Down Expand Up @@ -134,11 +128,9 @@ library RLPReader {
* @dev A cheaper version of keccak256(toRlpBytes(item)) that avoids copying memory.
* @return keccak256 hash of RLP encoded bytes.
*/
function rlpBytesKeccak256(RLPItem memory item)
internal
pure
returns (bytes32)
{
function rlpBytesKeccak256(
RLPItem memory item
) internal pure returns (bytes32) {
uint256 ptr = item.memPtr;
uint256 len = item.len;
bytes32 result;
Expand All @@ -148,11 +140,9 @@ library RLPReader {
return result;
}

function payloadLocation(RLPItem memory item)
internal
pure
returns (uint256, uint256)
{
function payloadLocation(
RLPItem memory item
) internal pure returns (uint256, uint256) {
uint256 offset = _payloadOffset(item.memPtr);
uint256 memPtr = item.memPtr + offset;
uint256 len = item.len - offset; // data length
Expand All @@ -163,11 +153,9 @@ library RLPReader {
* @dev A cheaper version of keccak256(toBytes(item)) that avoids copying memory.
* @return keccak256 hash of the item payload.
*/
function payloadKeccak256(RLPItem memory item)
internal
pure
returns (bytes32)
{
function payloadKeccak256(
RLPItem memory item
) internal pure returns (bytes32) {
(uint256 memPtr, uint256 len) = payloadLocation(item);
bytes32 result;
assembly {
Expand All @@ -179,11 +167,9 @@ library RLPReader {
/** RLPItem conversions into data types **/

// @returns raw rlp encoding in bytes
function toRlpBytes(RLPItem memory item)
internal
pure
returns (bytes memory)
{
function toRlpBytes(
RLPItem memory item
) internal pure returns (bytes memory) {
bytes memory result = new bytes(item.len);
if (result.length == 0) return result;

Expand Down Expand Up @@ -341,11 +327,7 @@ library RLPReader {
* @param dest Pointer to destination
* @param len Amount of memory to copy from the source
*/
function copy(
uint256 src,
uint256 dest,
uint256 len
) private pure {
function copy(uint256 src, uint256 dest, uint256 len) private pure {
if (len == 0) return;

// copy as many word sizes as possible
Expand All @@ -361,7 +343,7 @@ library RLPReader {
if (len == 0) return;

// left over bytes. Mask is used to remove unwanted bytes from the word
uint256 mask = 256**(WORD_SIZE - len) - 1;
uint256 mask = 256 ** (WORD_SIZE - len) - 1;

assembly {
let srcpart := and(mload(src), not(mask)) // zero out src
Expand Down
Loading

0 comments on commit d7f1644

Please sign in to comment.