|
| 1 | +// Copyright 2024, Offchain Labs, Inc. |
| 2 | +// For license information, see https://github.com/nitro/blob/master/LICENSE |
| 3 | +// SPDX-License-Identifier: BUSL-1.1 |
| 4 | + |
| 5 | +pragma solidity ^0.8.24; |
| 6 | + |
| 7 | +/* |
| 8 | + * HostioTest is a test contract used to compare EVM with Stylus. |
| 9 | + */ |
| 10 | +contract HostioTest { |
| 11 | + function exitEarly() external pure { |
| 12 | + assembly { |
| 13 | + stop() |
| 14 | + } |
| 15 | + } |
| 16 | + |
| 17 | + function transientLoadBytes32(bytes32 key) external view returns (bytes32) { |
| 18 | + bytes32 data; |
| 19 | + assembly { |
| 20 | + data := tload(key) |
| 21 | + } |
| 22 | + return data; |
| 23 | + } |
| 24 | + |
| 25 | + function transientStoreBytes32(bytes32 key, bytes32 value) external { |
| 26 | + assembly { |
| 27 | + // solc-ignore-next-line transient-storage |
| 28 | + tstore(key, value) |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + function returnDataSize() external pure returns (uint256) { |
| 33 | + uint256 size; |
| 34 | + assembly { |
| 35 | + size := returndatasize() |
| 36 | + } |
| 37 | + return size; |
| 38 | + } |
| 39 | + |
| 40 | + function emitLog( |
| 41 | + bytes calldata _data, |
| 42 | + int8 n, |
| 43 | + bytes32 t1, |
| 44 | + bytes32 t2, |
| 45 | + bytes32 t3, |
| 46 | + bytes32 t4 |
| 47 | + ) external { |
| 48 | + bytes memory data = _data; |
| 49 | + if (n == 0) { |
| 50 | + assembly { |
| 51 | + log0(add(data, 32), mload(data)) |
| 52 | + } |
| 53 | + } else if (n == 1) { |
| 54 | + assembly { |
| 55 | + log1(add(data, 32), mload(data), t1) |
| 56 | + } |
| 57 | + } else if (n == 2) { |
| 58 | + assembly { |
| 59 | + log2(add(data, 32), mload(data), t1, t2) |
| 60 | + } |
| 61 | + } else if (n == 3) { |
| 62 | + assembly { |
| 63 | + log3(add(data, 32), mload(data), t1, t2, t3) |
| 64 | + } |
| 65 | + } else if (n == 4) { |
| 66 | + assembly { |
| 67 | + log4(add(data, 32), mload(data), t1, t2, t3, t4) |
| 68 | + } |
| 69 | + } else { |
| 70 | + revert("invalid n for emit log"); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + function accountBalance(address account) external view returns (uint256) { |
| 75 | + return account.balance; |
| 76 | + } |
| 77 | + |
| 78 | + function accountCode(address account) external view returns (bytes memory) { |
| 79 | + uint256 size = 10000; |
| 80 | + bytes memory code = new bytes(size); |
| 81 | + assembly { |
| 82 | + extcodecopy(account, add(code, 32), 0, size) |
| 83 | + size := extcodesize(account) |
| 84 | + mstore(code, size) |
| 85 | + } |
| 86 | + return code; |
| 87 | + } |
| 88 | + |
| 89 | + function accountCodeSize(address account) external view returns (uint256) { |
| 90 | + uint256 size; |
| 91 | + assembly { |
| 92 | + size := extcodesize(account) |
| 93 | + } |
| 94 | + return size; |
| 95 | + } |
| 96 | + |
| 97 | + function accountCodehash(address account) external view returns (bytes32) { |
| 98 | + bytes32 hash; |
| 99 | + assembly { |
| 100 | + hash := extcodehash(account) |
| 101 | + } |
| 102 | + return hash; |
| 103 | + } |
| 104 | + |
| 105 | + function evmGasLeft() external view returns (uint256) { |
| 106 | + return gasleft(); |
| 107 | + } |
| 108 | + |
| 109 | + function evmInkLeft() external view returns (uint256) { |
| 110 | + return gasleft(); |
| 111 | + } |
| 112 | + |
| 113 | + function blockBasefee() external view returns (uint256) { |
| 114 | + return block.basefee; |
| 115 | + } |
| 116 | + |
| 117 | + function chainid() external view returns (uint256) { |
| 118 | + return block.chainid; |
| 119 | + } |
| 120 | + |
| 121 | + function blockCoinbase() external view returns (address) { |
| 122 | + return block.coinbase; |
| 123 | + } |
| 124 | + |
| 125 | + function blockGasLimit() external view returns (uint256) { |
| 126 | + return block.gaslimit; |
| 127 | + } |
| 128 | + |
| 129 | + function blockNumber() external view returns (uint256) { |
| 130 | + return block.number; |
| 131 | + } |
| 132 | + |
| 133 | + function blockTimestamp() external view returns (uint256) { |
| 134 | + return block.timestamp; |
| 135 | + } |
| 136 | + |
| 137 | + function contractAddress() external view returns (address) { |
| 138 | + return address(this); |
| 139 | + } |
| 140 | + |
| 141 | + function mathDiv(uint256 a, uint256 b) external pure returns (uint256) { |
| 142 | + return a / b; |
| 143 | + } |
| 144 | + |
| 145 | + function mathMod(uint256 a, uint256 b) external pure returns (uint256) { |
| 146 | + return a % b; |
| 147 | + } |
| 148 | + |
| 149 | + function mathPow(uint256 a, uint256 b) external pure returns (uint256) { |
| 150 | + uint256 result; |
| 151 | + assembly { |
| 152 | + result := exp(a, b) |
| 153 | + } |
| 154 | + return result; |
| 155 | + } |
| 156 | + |
| 157 | + function mathAddMod( |
| 158 | + uint256 a, |
| 159 | + uint256 b, |
| 160 | + uint256 c |
| 161 | + ) external pure returns (uint256) { |
| 162 | + return addmod(a, b, c); |
| 163 | + } |
| 164 | + |
| 165 | + function mathMulMod( |
| 166 | + uint256 a, |
| 167 | + uint256 b, |
| 168 | + uint256 c |
| 169 | + ) external pure returns (uint256) { |
| 170 | + return mulmod(a, b, c); |
| 171 | + } |
| 172 | + |
| 173 | + function msgSender() external view returns (address) { |
| 174 | + return msg.sender; |
| 175 | + } |
| 176 | + |
| 177 | + function msgValue() external payable returns (uint256) { |
| 178 | + return msg.value; |
| 179 | + } |
| 180 | + |
| 181 | + function keccak(bytes calldata preimage) external pure returns (bytes32) { |
| 182 | + return keccak256(preimage); |
| 183 | + } |
| 184 | + |
| 185 | + function txGasPrice() external view returns (uint256) { |
| 186 | + return tx.gasprice; |
| 187 | + } |
| 188 | + |
| 189 | + function txInkPrice() external view returns (uint256) { |
| 190 | + return tx.gasprice; |
| 191 | + } |
| 192 | + |
| 193 | + function txOrigin() external view returns (address) { |
| 194 | + return tx.origin; |
| 195 | + } |
| 196 | +} |
0 commit comments