forked from crypto-org-chain/cronos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pytest -v -s test_ica.py::test_exploit
- Loading branch information
Showing
6 changed files
with
119 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
contract TestICAExploit { | ||
uint256 max = 1; | ||
uint64 lastSeq; | ||
// sha256('cronos-evm')[:20] | ||
address constant module_address = 0x89A7EF2F08B1c018D5Cc88836249b84Dd5392905; | ||
enum Status { | ||
NONE, | ||
SUCCESS, | ||
FAIL | ||
} | ||
mapping (uint256 => mapping (uint256 => string[])) public dataMap; | ||
mapping (string => mapping (uint64 => Status)) public statusMap; | ||
event OnPacketResult(string indexed packetSrcChannel, uint64 seq, Status status); | ||
|
||
function getStatus(string calldata packetSrcChannel, uint64 seq) public view returns (Status) { | ||
return statusMap[packetSrcChannel][seq]; | ||
} | ||
|
||
function onPacketResultCallback(string calldata packetSrcChannel, uint64 seq, bool ack) external payable returns (bool) { | ||
// To prevent called by arbitrary user | ||
require(msg.sender == module_address); | ||
Status status = Status.FAIL; | ||
if (ack) { | ||
status = Status.SUCCESS; | ||
} | ||
statusMap[packetSrcChannel][seq] = status; | ||
emit OnPacketResult(packetSrcChannel, seq, status); | ||
for (uint256 n = 0; n < max; n++) { | ||
innerLoop(n, packetSrcChannel); | ||
} | ||
return true; | ||
} | ||
|
||
function innerLoop(uint256 iterations, string calldata packetSrcChannel) private { | ||
if (iterations == 0) { | ||
return; | ||
} | ||
for (uint256 i = 0; i < max; i++) { | ||
string[] memory list = new string[](max); | ||
for (uint256 j = 0; j < max; j++) { | ||
list[j] = packetSrcChannel; | ||
} | ||
dataMap[iterations][i] = list; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters