-
Notifications
You must be signed in to change notification settings - Fork 614
Expand file tree
/
Copy pathDecoderBase.sol
More file actions
131 lines (115 loc) · 4.63 KB
/
Copy pathDecoderBase.sol
File metadata and controls
131 lines (115 loc) · 4.63 KB
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
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;
import {TestBase} from "../base/Base.sol";
import {Timestamp, Slot} from "@aztec/core/libraries/TimeLib.sol";
import {ProposedHeader, GasFees} from "@aztec/core/libraries/rollup/ProposedHeaderLib.sol";
import {ProposedHeaderLib} from "@aztec/core/libraries/rollup/ProposedHeaderLib.sol";
// Many of the structs in here match what you see in `header` but with very important exceptions!
// The order of variables is sorted alphabetically in the structs in here to work with the
// JSON cheatcodes.
contract DecoderBase is TestBase {
using ProposedHeaderLib for ProposedHeader;
// When I had data and messages as one combined struct it failed, but I can have this top-layer and it works :shrug:
// Note: Members of the struct (and substructs) have to be in ALPHABETICAL order!
struct Full {
Data checkpoint;
Messages messages;
Populate populate;
}
struct AlphabeticalFull {
AlphabeticalData checkpoint;
Messages messages;
Populate populate;
}
struct Populate {
bytes32[] l1ToL2Content;
bytes32 recipient;
address sender;
}
struct Messages {
bytes32[] l2ToL1Messages;
}
struct AlphabeticalHeader {
uint256 accumulatedFees;
bytes32 blobsHash;
bytes32 blockHeadersHash;
address coinbase;
bytes32 feeRecipient;
GasFees gasFees;
bytes32 inboxRollingHash;
bytes32 lastArchiveRoot;
bytes32 outHash;
uint256 slotNumber;
uint256 timestamp;
uint256 totalManaUsed;
}
struct Data {
bytes32 archive;
// Note: batchedBlobInputs is usually per epoch, rather than per checkpoint. For testing, these batchedBlobInputs
// assume that an epoch contains blobs including and up to the 'current' checkpoint.
// e.g. mixed_checkpoint_2's batchedBlobInputs assumes that the epoch consists of 2 checkpoints, mixed_checkpoint_1
// and mixed_checkpoint_2, and their blobs.
// e.g. mixed_checkpoint_1's batchedBlobInputs assumes the epoch contains only mixed_checkpoint_1 and its blob(s).
bytes batchedBlobInputs; // EVM point evaluation precompile inputs for verifying an epoch's batch of blobs
bytes blobCommitments; // [numBlobs, ...blobCommitments], used in proposing checkpoints
uint256 checkpointNumber;
bytes body;
ProposedHeader header;
bytes32 headerHash;
uint32 numTxs;
}
struct AlphabeticalData {
bytes32 archive;
bytes batchedBlobInputs;
bytes blobCommitments;
bytes body;
uint256 checkpointNumber;
AlphabeticalHeader header;
bytes32 headerHash;
uint32 numTxs;
}
function load(string memory name) internal view returns (Full memory) {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/test/fixtures/", name, ".json");
string memory json = vm.readFile(path);
bytes memory jsonBytes = vm.parseJson(json);
AlphabeticalFull memory full = abi.decode(jsonBytes, (AlphabeticalFull));
return fromAlphabeticalToNormal(full);
}
// Decode does not support the custom types
function fromAlphabeticalToNormal(AlphabeticalFull memory full) internal pure returns (Full memory) {
Full memory result = Full({
checkpoint: Data({
archive: full.checkpoint.archive,
blobCommitments: full.checkpoint.blobCommitments,
batchedBlobInputs: full.checkpoint.batchedBlobInputs,
checkpointNumber: full.checkpoint.checkpointNumber,
body: full.checkpoint.body,
header: ProposedHeader({
lastArchiveRoot: full.checkpoint.header.lastArchiveRoot,
blockHeadersHash: full.checkpoint.header.blockHeadersHash,
blobsHash: full.checkpoint.header.blobsHash,
inboxRollingHash: full.checkpoint.header.inboxRollingHash,
outHash: full.checkpoint.header.outHash,
slotNumber: Slot.wrap(full.checkpoint.header.slotNumber),
timestamp: Timestamp.wrap(full.checkpoint.header.timestamp),
coinbase: full.checkpoint.header.coinbase,
feeRecipient: full.checkpoint.header.feeRecipient,
gasFees: full.checkpoint.header.gasFees,
totalManaUsed: full.checkpoint.header.totalManaUsed,
accumulatedFees: full.checkpoint.header.accumulatedFees
}),
headerHash: full.checkpoint.headerHash,
numTxs: full.checkpoint.numTxs
}),
messages: full.messages,
populate: full.populate
});
assertEq(result.checkpoint.headerHash, result.checkpoint.header.hash(), "headerHash mismatch when loading");
return result;
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
}