Commit 1d230d23 authored by clabby's avatar clabby

Add `VMStatus` type

dedup
parent e5014d71
This diff is collapsed.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
"src/L2/L2StandardBridge.sol": "0xe025dcccbf21d48828ecf588941c9ba04c91b87bdd177a653d3f1b265b0b02a8", "src/L2/L2StandardBridge.sol": "0xe025dcccbf21d48828ecf588941c9ba04c91b87bdd177a653d3f1b265b0b02a8",
"src/L2/L2ToL1MessagePasser.sol": "0xda56ba2e5b2c28fa8ca2df24077d49e96155a00ecc99cd0778d681be6ed166fe", "src/L2/L2ToL1MessagePasser.sol": "0xda56ba2e5b2c28fa8ca2df24077d49e96155a00ecc99cd0778d681be6ed166fe",
"src/L2/SequencerFeeVault.sol": "0x37816035c992d38cf7e3d5a1846b02d017dd7bdca46abe6e5c5171b9ee6225ab", "src/L2/SequencerFeeVault.sol": "0x37816035c992d38cf7e3d5a1846b02d017dd7bdca46abe6e5c5171b9ee6225ab",
"src/dispute/FaultDisputeGame.sol": "0xb965888c2ea9e8dda89d6b5041c05b445568c8819b6616bba15ecf61fa112045", "src/dispute/FaultDisputeGame.sol": "0x80a0571e79b452c086e5432606c26ff548d2ae4443d0836833302c2989b0a1ea",
"src/legacy/DeployerWhitelist.sol": "0xf2129ec3da75307ba8e21bc943c332bb04704642e6e263149b5c8ee92dbcb7a8", "src/legacy/DeployerWhitelist.sol": "0xf2129ec3da75307ba8e21bc943c332bb04704642e6e263149b5c8ee92dbcb7a8",
"src/legacy/L1BlockNumber.sol": "0x30aae1fc85103476af0226b6e98c71c01feebbdc35d93401390b1ad438a37be6", "src/legacy/L1BlockNumber.sol": "0x30aae1fc85103476af0226b6e98c71c01feebbdc35d93401390b1ad438a37be6",
"src/legacy/LegacyMessagePasser.sol": "0x5c08b0a663cc49d30e4e38540f6aefab19ef287c3ecd31c8d8c3decd5f5bd497", "src/legacy/LegacyMessagePasser.sol": "0x5c08b0a663cc49d30e4e38540f6aefab19ef287c3ecd31c8d8c3decd5f5bd497",
......
...@@ -449,7 +449,9 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver { ...@@ -449,7 +449,9 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
// The VMStatus must indicate (1) 'invalid', to argue that disputed thing is invalid. // The VMStatus must indicate (1) 'invalid', to argue that disputed thing is invalid.
// Games that agree with the existing outcome are not allowed. // Games that agree with the existing outcome are not allowed.
// NOTE(clabby): This assumption will change in Alpha Chad. // NOTE(clabby): This assumption will change in Alpha Chad.
if (uint8(Claim.unwrap(rootClaim())[0]) != 1) revert UnexpectedRootClaim(rootClaim()); if (uint8(Claim.unwrap(rootClaim())[0]) != VMStatus.unwrap(VMStatuses.INVALID)) {
revert UnexpectedRootClaim(rootClaim());
}
// Set the game's starting timestamp // Set the game's starting timestamp
createdAt = Timestamp.wrap(uint64(block.timestamp)); createdAt = Timestamp.wrap(uint64(block.timestamp));
......
...@@ -62,6 +62,9 @@ type Position is uint128; ...@@ -62,6 +62,9 @@ type Position is uint128;
/// @notice A `GameType` represents the type of game being played. /// @notice A `GameType` represents the type of game being played.
type GameType is uint8; type GameType is uint8;
/// @notice A `VMStatus` represents the status of a VM execution.
type VMStatus is uint8;
/// @notice The current status of the dispute game. /// @notice The current status of the dispute game.
enum GameStatus enum GameStatus
// The game is currently in progress, and has not been resolved. // The game is currently in progress, and has not been resolved.
...@@ -85,3 +88,18 @@ library GameTypes { ...@@ -85,3 +88,18 @@ library GameTypes {
/// @dev The game will use a `IDisputeGame` implementation that utilizes attestation proofs. /// @dev The game will use a `IDisputeGame` implementation that utilizes attestation proofs.
GameType internal constant ATTESTATION = GameType.wrap(2); GameType internal constant ATTESTATION = GameType.wrap(2);
} }
/// @title VMStatuses
library VMStatuses {
/// @dev The VM has executed successfully and the outcome is valid.
VMStatus internal constant VALID = VMStatus.wrap(0);
/// @dev The VM has executed successfully and the outcome is invalid.
VMStatus internal constant INVALID = VMStatus.wrap(1);
/// @dev The VM has paniced.
VMStatus internal constant PANIC = VMStatus.wrap(2);
/// @dev The VM execution is still in progress.
VMStatus internal constant UNFINISHED = VMStatus.wrap(3);
}
...@@ -42,7 +42,7 @@ contract DisputeGameFactory_Create_Test is DisputeGameFactory_Init { ...@@ -42,7 +42,7 @@ contract DisputeGameFactory_Create_Test is DisputeGameFactory_Init {
// Ensure that the `gameType` is within the bounds of the `GameType` enum's possible values. // Ensure that the `gameType` is within the bounds of the `GameType` enum's possible values.
GameType gt = GameType.wrap(uint8(bound(gameType, 0, 2))); GameType gt = GameType.wrap(uint8(bound(gameType, 0, 2)));
// Ensure the rootClaim has a VMStatus that disagrees with the validity. // Ensure the rootClaim has a VMStatus that disagrees with the validity.
rootClaim = changeClaimStatus(rootClaim, 1); rootClaim = changeClaimStatus(rootClaim, VMStatuses.INVALID);
// Set all three implementations to the same `FakeClone` contract. // Set all three implementations to the same `FakeClone` contract.
for (uint8 i; i < 3; i++) { for (uint8 i; i < 3; i++) {
...@@ -71,7 +71,7 @@ contract DisputeGameFactory_Create_Test is DisputeGameFactory_Init { ...@@ -71,7 +71,7 @@ contract DisputeGameFactory_Create_Test is DisputeGameFactory_Init {
// Ensure that the `gameType` is within the bounds of the `GameType` enum's possible values. // Ensure that the `gameType` is within the bounds of the `GameType` enum's possible values.
GameType gt = GameType.wrap(uint8(bound(gameType, 0, 2))); GameType gt = GameType.wrap(uint8(bound(gameType, 0, 2)));
// Ensure the rootClaim has a VMStatus that disagrees with the validity. // Ensure the rootClaim has a VMStatus that disagrees with the validity.
rootClaim = changeClaimStatus(rootClaim, 1); rootClaim = changeClaimStatus(rootClaim, VMStatuses.INVALID);
vm.expectRevert(abi.encodeWithSelector(NoImplementation.selector, gt)); vm.expectRevert(abi.encodeWithSelector(NoImplementation.selector, gt));
factory.create(gt, rootClaim, extraData); factory.create(gt, rootClaim, extraData);
...@@ -82,7 +82,7 @@ contract DisputeGameFactory_Create_Test is DisputeGameFactory_Init { ...@@ -82,7 +82,7 @@ contract DisputeGameFactory_Create_Test is DisputeGameFactory_Init {
// Ensure that the `gameType` is within the bounds of the `GameType` enum's possible values. // Ensure that the `gameType` is within the bounds of the `GameType` enum's possible values.
GameType gt = GameType.wrap(uint8(bound(gameType, 0, 2))); GameType gt = GameType.wrap(uint8(bound(gameType, 0, 2)));
// Ensure the rootClaim has a VMStatus that disagrees with the validity. // Ensure the rootClaim has a VMStatus that disagrees with the validity.
rootClaim = changeClaimStatus(rootClaim, 1); rootClaim = changeClaimStatus(rootClaim, VMStatuses.INVALID);
// Set all three implementations to the same `FakeClone` contract. // Set all three implementations to the same `FakeClone` contract.
for (uint8 i; i < 3; i++) { for (uint8 i; i < 3; i++) {
...@@ -106,10 +106,10 @@ contract DisputeGameFactory_Create_Test is DisputeGameFactory_Init { ...@@ -106,10 +106,10 @@ contract DisputeGameFactory_Create_Test is DisputeGameFactory_Init {
factory.create(gt, rootClaim, extraData); factory.create(gt, rootClaim, extraData);
} }
function changeClaimStatus(Claim claim, uint8 status) public pure returns (Claim _out) { function changeClaimStatus(Claim _claim, VMStatus _status) public pure returns (Claim out_) {
bytes32 hash = Claim.unwrap(claim); assembly {
hash = bytes32((uint256(hash) & (~(uint256(0xff) << 248))) | (uint256(status) << 248)); out_ := or(and(not(shl(248, 0xFF)), _claim), shl(248, _status))
return Claim.wrap(hash); }
} }
} }
......
...@@ -147,7 +147,7 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init { ...@@ -147,7 +147,7 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
function testFuzz_initialize_badRootStatus_reverts(Claim rootClaim, bytes calldata extraData) public { function testFuzz_initialize_badRootStatus_reverts(Claim rootClaim, bytes calldata extraData) public {
// Ensure that the `gameType` is within the bounds of the `GameType` enum's possible values. // Ensure that the `gameType` is within the bounds of the `GameType` enum's possible values.
// Ensure the root claim does not have the correct VM status // Ensure the root claim does not have the correct VM status
if (uint8(Claim.unwrap(rootClaim)[0]) == 1) rootClaim = changeClaimStatus(rootClaim, 0); if (uint8(Claim.unwrap(rootClaim)[0]) == 1) rootClaim = changeClaimStatus(rootClaim, VMStatuses.VALID);
vm.expectRevert(abi.encodeWithSelector(UnexpectedRootClaim.selector, rootClaim)); vm.expectRevert(abi.encodeWithSelector(UnexpectedRootClaim.selector, rootClaim));
factory.create(GameTypes.FAULT, rootClaim, extraData); factory.create(GameTypes.FAULT, rootClaim, extraData);
...@@ -460,10 +460,10 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init { ...@@ -460,10 +460,10 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
return bytes32((uint256(h) & ~uint256(0xFF << 248)) | (1 << 248)); return bytes32((uint256(h) & ~uint256(0xFF << 248)) | (1 << 248));
} }
function changeClaimStatus(Claim claim, uint8 status) public pure returns (Claim _out) { function changeClaimStatus(Claim _claim, VMStatus _status) public pure returns (Claim out_) {
bytes32 hash = Claim.unwrap(claim); assembly {
hash = bytes32((uint256(hash) & (~(uint256(0xff) << 248))) | (uint256(status) << 248)); out_ := or(and(not(shl(248, 0xFF)), _claim), shl(248, _status))
return Claim.wrap(hash); }
} }
} }
...@@ -1024,16 +1024,13 @@ contract AlphabetVM is IBigStepper { ...@@ -1024,16 +1024,13 @@ contract AlphabetVM is IBigStepper {
} }
// STF: n -> n + 1 // STF: n -> n + 1
postState_ = keccak256(abi.encode(traceIndex, claim + 1)); postState_ = keccak256(abi.encode(traceIndex, claim + 1));
uint256 status; VMStatus status;
if (traceIndex == traceLength - 1) { if (traceIndex == traceLength - 1) {
// VmStatusInvalid status = VMStatuses.INVALID;
status = 1;
} else if (traceIndex < traceLength - 1) { } else if (traceIndex < traceLength - 1) {
// VmStatusUnfinished status = VMStatuses.UNFINISHED;
status = 3;
} else { } else {
// VmStatusPanic status = VMStatuses.PANIC;
status = 2;
} }
assembly { assembly {
postState_ := or(and(postState_, not(shl(248, 0xFF))), shl(248, status)) postState_ := or(and(postState_, not(shl(248, 0xFF))), shl(248, status))
......
...@@ -4,6 +4,7 @@ pragma solidity 0.8.15; ...@@ -4,6 +4,7 @@ pragma solidity 0.8.15;
import { CommonTest } from "./CommonTest.t.sol"; import { CommonTest } from "./CommonTest.t.sol";
import { MIPS } from "src/cannon/MIPS.sol"; import { MIPS } from "src/cannon/MIPS.sol";
import { PreimageOracle } from "src/cannon/PreimageOracle.sol"; import { PreimageOracle } from "src/cannon/PreimageOracle.sol";
import "src/libraries/DisputeTypes.sol";
contract MIPS_Test is CommonTest { contract MIPS_Test is CommonTest {
MIPS internal mips; MIPS internal mips;
...@@ -1558,23 +1559,23 @@ contract MIPS_Test is CommonTest { ...@@ -1558,23 +1559,23 @@ contract MIPS_Test is CommonTest {
/// 1. Exited with success (Invalid) /// 1. Exited with success (Invalid)
/// 2. Exited with failure (Panic) /// 2. Exited with failure (Panic)
/// 3. Unfinished /// 3. Unfinished
function vmStatus(MIPS.State memory state) internal pure returns (uint256 out_) { function vmStatus(MIPS.State memory state) internal pure returns (VMStatus out_) {
if (state.exited) { if (state.exited) {
if (state.exitCode == 0) { if (state.exitCode == 0) {
return 0; return VMStatuses.VALID;
} else if (state.exitCode == 1) { } else if (state.exitCode == 1) {
return 1; return VMStatuses.INVALID;
} else { } else {
return 2; return VMStatuses.PANIC;
} }
} else { } else {
return 3; return VMStatuses.UNFINISHED;
} }
} }
function outputState(MIPS.State memory state) internal pure returns (bytes32 out_) { function outputState(MIPS.State memory state) internal pure returns (bytes32 out_) {
bytes memory enc = encodeState(state); bytes memory enc = encodeState(state);
uint256 status = vmStatus(state); VMStatus status = vmStatus(state);
assembly { assembly {
out_ := keccak256(add(enc, 0x20), 226) out_ := keccak256(add(enc, 0x20), 226)
out_ := or(and(not(shl(248, 0xFF)), out_), shl(248, status)) out_ := or(and(not(shl(248, 0xFF)), out_), shl(248, status))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment