forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashing.t.sol
137 lines (127 loc) · 4.45 KB
/
Hashing.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
// Testing utilities
import { CommonTest } from "./CommonTest.t.sol";
// Libraries
import { Types } from "../src/libraries/Types.sol";
import { Encoding } from "../src/libraries/Encoding.sol";
import { LegacyCrossDomainUtils } from "../src/libraries/LegacyCrossDomainUtils.sol";
// Target contract
import { Hashing } from "../src/libraries/Hashing.sol";
contract Hashing_hashDepositSource_Test is CommonTest {
/// @notice Tests that hashDepositSource returns the correct hash in a simple case.
function test_hashDepositSource_succeeds() external {
assertEq(
Hashing.hashDepositSource(0xd25df7858efc1778118fb133ac561b138845361626dfb976699c5287ed0f4959, 0x1),
0xf923fb07134d7d287cb52c770cc619e17e82606c21a875c92f4c63b65280a5cc
);
}
}
contract Hashing_hashCrossDomainMessage_Test is CommonTest {
/// @notice Tests that hashCrossDomainMessage returns the correct hash in a simple case.
function testDiff_hashCrossDomainMessage_succeeds(
uint240 _nonce,
uint16 _version,
address _sender,
address _target,
uint256 _value,
uint256 _gasLimit,
bytes memory _data
)
external
{
// Ensure the version is valid.
uint16 version = uint16(bound(uint256(_version), 0, 1));
uint256 nonce = Encoding.encodeVersionedNonce(_nonce, version);
assertEq(
Hashing.hashCrossDomainMessage(nonce, _sender, _target, _value, _gasLimit, _data),
ffi.hashCrossDomainMessage(nonce, _sender, _target, _value, _gasLimit, _data)
);
}
/// @notice Tests that hashCrossDomainMessageV0 matches the hash of the legacy encoding.
function testFuzz_hashCrossDomainMessageV0_matchesLegacy_succeeds(
address _target,
address _sender,
bytes memory _message,
uint256 _messageNonce
)
external
{
assertEq(
keccak256(LegacyCrossDomainUtils.encodeXDomainCalldata(_target, _sender, _message, _messageNonce)),
Hashing.hashCrossDomainMessageV0(_target, _sender, _message, _messageNonce)
);
}
}
contract Hashing_hashWithdrawal_Test is CommonTest {
/// @notice Tests that hashWithdrawal returns the correct hash in a simple case.
function testDiff_hashWithdrawal_succeeds(
uint256 _nonce,
address _sender,
address _target,
uint256 _value,
uint256 _gasLimit,
bytes memory _data
)
external
{
assertEq(
Hashing.hashWithdrawal(Types.WithdrawalTransaction(_nonce, _sender, _target, _value, _gasLimit, _data)),
ffi.hashWithdrawal(_nonce, _sender, _target, _value, _gasLimit, _data)
);
}
}
contract Hashing_hashOutputRootProof_Test is CommonTest {
/// @notice Tests that hashOutputRootProof returns the correct hash in a simple case.
function testDiff_hashOutputRootProof_succeeds(
bytes32 _stateRoot,
bytes32 _messagePasserStorageRoot,
bytes32 _latestBlockhash
)
external
{
bytes32 version = 0;
assertEq(
Hashing.hashOutputRootProof(
Types.OutputRootProof({
version: version,
stateRoot: _stateRoot,
messagePasserStorageRoot: _messagePasserStorageRoot,
latestBlockhash: _latestBlockhash
})
),
ffi.hashOutputRootProof(version, _stateRoot, _messagePasserStorageRoot, _latestBlockhash)
);
}
}
contract Hashing_hashDepositTransaction_Test is CommonTest {
/// @notice Tests that hashDepositTransaction returns the correct hash in a simple case.
function testDiff_hashDepositTransaction_succeeds(
address _from,
address _to,
uint256 _mint,
uint256 _value,
uint64 _gas,
bytes memory _data,
uint64 _logIndex
)
external
{
assertEq(
Hashing.hashDepositTransaction(
Types.UserDepositTransaction(
_from,
_to,
false, // isCreate
_value,
_mint,
_gas,
_data,
bytes32(uint256(0)),
_logIndex
)
),
ffi.hashDepositTransaction(_from, _to, _mint, _value, _gas, _data, _logIndex)
);
}
}