Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
Allow disputing a transfer from/to a non-existent state.
Browse files Browse the repository at this point in the history
Switch requires to results (BadFromIndex & BadToIndex) when confirming
that a sender and reciever exist.
Sync some enums from Types.sol to match up in TS types in client.
Add more extensive test cases for disputeTransitionTransfer for triggering rollbacks.
Typo signautre -> signature.
  • Loading branch information
jacque006 committed Aug 23, 2021
1 parent ea02b74 commit 2597253
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 101 deletions.
14 changes: 6 additions & 8 deletions contracts/libs/Transition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,14 @@ library Transition {
uint256 fee,
Types.StateMerkleProof memory proof
) internal pure returns (bytes32 newRoot, Types.Result) {
require(
bool doesSenderExist =
MerkleTree.verify(
stateRoot,
keccak256(proof.state.encode()),
senderStateIndex,
proof.witness
),
"Transition: Sender does not exist"
);
);
if (!doesSenderExist) return (bytes32(0), Types.Result.BadFromIndex);
(Types.UserState memory newSender, Types.Result result) =
validateAndApplySender(tokenID, amount, fee, proof.state);
if (result != Types.Result.Ok) return (bytes32(0), result);
Expand All @@ -151,15 +150,14 @@ library Transition {
uint256 amount,
Types.StateMerkleProof memory proof
) internal pure returns (bytes32 newRoot, Types.Result) {
require(
bool doesReceiverExist =
MerkleTree.verify(
stateRoot,
keccak256(proof.state.encode()),
receiverStateIndex,
proof.witness
),
"Transition: receiver does not exist"
);
);
if (!doesReceiverExist) return (bytes32(0), Types.Result.BadToIndex);
(Types.UserState memory newReceiver, Types.Result result) =
validateAndApplyReceiver(tokenID, amount, proof.state);
if (result != Types.Result.Ok) return (bytes32(0), result);
Expand Down
7 changes: 6 additions & 1 deletion contracts/libs/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ library Types {
bytes32[] witness;
}

/**
* @notice Results of a validation check on a transaction or commit
*/
enum Result {
Ok,
InvalidTokenAmount,
Expand All @@ -250,6 +253,8 @@ library Types {
BadWithdrawRoot,
BadCompression,
TooManyTx,
BadPrecompileCall
BadPrecompileCall,
BadFromIndex,
BadToIndex
}
}
Loading

0 comments on commit 2597253

Please sign in to comment.