Skip to content

Commit

Permalink
feat: update reset test and constants
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenctw committed Mar 24, 2024
1 parent c790e92 commit d538c68
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
2 changes: 1 addition & 1 deletion shasum-mock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ b0bb91ae378db1c938e73eccde20c539da01b8556165835839fd1794ca573404 src/Buffer.sol
c2e9abd5557092fb2c7a3b6eb3d55933613c202b8ce54bba2e8cbd2d276278a1 src/Memory.sol
06df1c5a0a6094fdc3f55240a42b1991290eb672fae6833e9f2b4d4bfe2a5b88 src/MetaStep.sol
d858085617f1e8037e06420d9569e2196b72a8bd0dd217aefbb8bb738b44a8fd src/UArchCompat.sol
60ab17c719b0cb58047bfa5a83e390b30b32f5be00243890f2d321635bc5359a src/UArchConstants.sol
1152e2e0f1fdc8befe075251f5e69dcc55ec2666a287fc5002bfa021b2aaea98 src/UArchConstants.sol
c250ea17a7a471716148a60528b2cd01bd82dffd1c3c57aa0a7e99527fe44527 src/UArchReset.sol
40ab03ff44235b8ee5490314db112120e1ff99b347a5faf6a00f812e2497568d src/UArchStep.sol
2 changes: 1 addition & 1 deletion shasum-prod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ b0bb91ae378db1c938e73eccde20c539da01b8556165835839fd1794ca573404 src/Buffer.sol
c2e9abd5557092fb2c7a3b6eb3d55933613c202b8ce54bba2e8cbd2d276278a1 src/Memory.sol
06df1c5a0a6094fdc3f55240a42b1991290eb672fae6833e9f2b4d4bfe2a5b88 src/MetaStep.sol
d858085617f1e8037e06420d9569e2196b72a8bd0dd217aefbb8bb738b44a8fd src/UArchCompat.sol
60ab17c719b0cb58047bfa5a83e390b30b32f5be00243890f2d321635bc5359a src/UArchConstants.sol
1152e2e0f1fdc8befe075251f5e69dcc55ec2666a287fc5002bfa021b2aaea98 src/UArchConstants.sol
c250ea17a7a471716148a60528b2cd01bd82dffd1c3c57aa0a7e99527fe44527 src/UArchReset.sol
40ab03ff44235b8ee5490314db112120e1ff99b347a5faf6a00f812e2497568d src/UArchStep.sol
2 changes: 1 addition & 1 deletion src/UArchConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ library UArchConstants {
uint64 constant RESET_POSITION = 0x400000;
uint8 constant RESET_ALIGNED_SIZE = 22;
bytes32 constant PRESTINE_STATE =
0xf3ca81afcb4afed7dd6a6f1fadbe0a62aecc71fe9009040dfd700229de88b266;
0x0ceeb27295050183aff6fbead83d1033b469737d9aef99e1a6e5cb6e2bf2af8a;
// END OF AUTO-GENERATED CODE

uint64 constant LOG2_CYCLES_TO_RESET = 10;
Expand Down
74 changes: 56 additions & 18 deletions test/UArchReset.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,20 @@ contract UArchReset_Test is Test {

// configure the tests
string constant JSON_PATH = "./test/uarch-log/";
string constant CATALOG_PATH = "catalog.json";
string constant RESET_PATH = "uarch-reset.json";

uint256 constant siblingsLength = 42;

struct Entry {
string finalRootHash;
string initialRootHash;
string path;
bool proof;
uint256 proofsFrequency;
uint256 steps;
}

struct RawAccess {
uint256 position;
string hash;
Expand All @@ -47,35 +57,63 @@ contract UArchReset_Test is Test {
// string val; omit val because it's not used in reset

function testReset() public {
Entry[] memory catalog =
loadCatalog(string.concat(JSON_PATH, CATALOG_PATH));
string memory resetLog = string.concat(JSON_PATH, RESET_PATH);

// all tests combined can easily run out of gas, stop metering
// also raise memory_limit in foundry.toml per https://github.com/foundry-rs/foundry/issues/3971
vm.pauseGasMetering();
// create a large buffer and reuse it
bytes memory buffer = new bytes(100 * (siblingsLength + 1) * 32);
string memory rj = loadJsonLog(resetLog);
bytes32 initialRootHash = bytes32(
0xe6924ad1b17f3e77b62b33d0e43f16066cd4fcd8c5531369fcf71936a93fe271
);
bytes32 finalRootHash = bytes32(
0xc4a80b24909990e42edabfe9bfb3b90974173e22735a0c191f8809c45e22da66
);

// load json log
loadBufferFromRawJson(buffer, rj);
for (uint256 i = 0; i < catalog.length; i++) {
if (
keccak256(abi.encodePacked(catalog[i].path))
!= keccak256(abi.encodePacked("uarch-reset-steps.json"))
) {
continue;
}
console.log("Replaying file %s ...", catalog[i].path);
require(
catalog[i].proofsFrequency == 1, "require proof in every step"
);

AccessLogs.Context memory accessLogs =
AccessLogs.Context(initialRootHash, Buffer.Context(buffer, 0));
string memory rj = loadJsonLog(resetLog);

// initialRootHash is passed and will be updated through out the step
UArchReset.reset(accessLogs);
bytes32 initialRootHash =
vm.parseBytes32(string.concat("0x", catalog[i].initialRootHash));
bytes32 finalRootHash =
vm.parseBytes32(string.concat("0x", catalog[i].finalRootHash));

assertEq(
accessLogs.currentRootHash,
finalRootHash,
"final root hash must match"
);
loadBufferFromRawJson(buffer, rj);

AccessLogs.Context memory accessLogs =
AccessLogs.Context(initialRootHash, Buffer.Context(buffer, 0));

// initialRootHash is passed and will be updated through out the step
UArchReset.reset(accessLogs);

assertEq(
accessLogs.currentRootHash,
finalRootHash,
"final root hash must match"
);
}

// load json log
}

function loadCatalog(string memory path)
private
view
returns (Entry[] memory)
{
string memory json = vm.readFile(path);
bytes memory raw = json.parseRaw("");
Entry[] memory catalog = abi.decode(raw, (Entry[]));

return catalog;
}

function loadJsonLog(string memory path)
Expand Down

0 comments on commit d538c68

Please sign in to comment.