From eb25b704f10f4599adba6cd842ca29bb245dd2e6 Mon Sep 17 00:00:00 2001 From: Jacob Caban-Tomski Date: Mon, 13 Sep 2021 22:52:09 -0600 Subject: [PATCH] WIP mm, stack too deep error --- contracts/Create2Transfer.sol | 2 +- contracts/MassMigrations.sol | 4 ++++ contracts/Transfer.sol | 1 + contracts/client/FrontendMassMigration.sol | 10 +++++++++- contracts/rollup/Rollup.sol | 16 +++++++++------- contracts/test/TestMassMigration.sol | 2 ++ 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/contracts/Create2Transfer.sol b/contracts/Create2Transfer.sol index a7c62188..18222995 100644 --- a/contracts/Create2Transfer.sol +++ b/contracts/Create2Transfer.sol @@ -60,7 +60,7 @@ contract Create2Transfer { } (stateRoot, result) = Transition.processReceiver( stateRoot, - stateHashes[size + 1], + stateHashes[size], feeReceiver, tokenID, fees, diff --git a/contracts/MassMigrations.sol b/contracts/MassMigrations.sol index 0d0cd032..371e6166 100644 --- a/contracts/MassMigrations.sol +++ b/contracts/MassMigrations.sol @@ -27,6 +27,7 @@ contract MassMigration { * */ function processMassMigrationCommit( bytes32 stateRoot, + bytes32[] memory stateHashes, uint256 maxTxSize, Types.MassMigrationBody memory committed, Types.StateMerkleProof[] memory proofs @@ -36,6 +37,7 @@ contract MassMigration { uint256 size = committed.txs.massMigrationSize(); if (size > maxTxSize) return (stateRoot, Types.Result.TooManyTx); + // TODO stateHashes require check Tx.MassMigration memory _tx; uint256 totalAmount = 0; @@ -47,6 +49,7 @@ contract MassMigration { _tx = committed.txs.massMigrationDecode(i); (stateRoot, freshState, result) = Transition.processMassMigration( stateRoot, + stateHashes[i], _tx, committed.tokenID, proofs[i] @@ -60,6 +63,7 @@ contract MassMigration { } (stateRoot, result) = Transition.processReceiver( stateRoot, + stateHashes[size], committed.feeReceiver, committed.tokenID, fees, diff --git a/contracts/Transfer.sol b/contracts/Transfer.sol index 9f6b20a7..37ba56c6 100644 --- a/contracts/Transfer.sol +++ b/contracts/Transfer.sol @@ -35,6 +35,7 @@ contract Transfer { uint256 size = txs.transferSize(); if (size > maxTxSize) return (stateRoot, Types.Result.TooManyTx); + // TODO Fix require require( stateHashes.length % size == size + 1, "stateHashes size mismatch with txs" diff --git a/contracts/client/FrontendMassMigration.sol b/contracts/client/FrontendMassMigration.sol index 28fda34a..9674d787 100644 --- a/contracts/client/FrontendMassMigration.sol +++ b/contracts/client/FrontendMassMigration.sol @@ -130,6 +130,7 @@ contract FrontendMassMigration { function process( bytes32 stateRoot, + bytes32 stateHashFrom, bytes memory encodedTx, uint256 tokenID, Types.StateMerkleProof memory from @@ -150,7 +151,14 @@ contract FrontendMassMigration { offchainTx.amount, offchainTx.fee ); - return Transition.processMassMigration(stateRoot, _tx, tokenID, from); + return + Transition.processMassMigration( + stateRoot, + stateHashFrom, + _tx, + tokenID, + from + ); } function checkSignature( diff --git a/contracts/rollup/Rollup.sol b/contracts/rollup/Rollup.sol index 166a9455..fe8b76ee 100644 --- a/contracts/rollup/Rollup.sol +++ b/contracts/rollup/Rollup.sol @@ -29,8 +29,7 @@ contract Rollup is BatchManager, EIP712, IEIP712 { string public constant DOMAIN_VERSION = "1"; /** - * @dev If this is not being externally consumed, - * it can be removed and refs replaced with Types.ZERO_BYTES32 + * @dev If this is not being externally consumed, it can be removed. */ bytes32 public immutable ZERO_BYTES32; @@ -85,11 +84,11 @@ contract Rollup is BatchManager, EIP712, IEIP712 { ); bytes32 genesisCommitment = - keccak256(abi.encode(genesisStateRoot, ZERO_BYTES32)); + keccak256(abi.encode(genesisStateRoot, Types.ZERO_BYTES32)); // Same effect as `MerkleTree.merklize` bytes32 commitmentRoot = - keccak256(abi.encode(genesisCommitment, ZERO_BYTES32)); + keccak256(abi.encode(genesisCommitment, Types.ZERO_BYTES32)); batches[nextBatchID] = Types.Batch({ commitmentRoot: commitmentRoot, meta: Types.encodeMeta( @@ -360,9 +359,10 @@ contract Rollup is BatchManager, EIP712, IEIP712 { vacant.witness ); bytes32 depositCommitment = - keccak256(abi.encode(newRoot, ZERO_BYTES32)); + keccak256(abi.encode(newRoot, Types.ZERO_BYTES32)); // Same effect as `MerkleTree.merklize` - bytes32 root = keccak256(abi.encode(depositCommitment, ZERO_BYTES32)); + bytes32 root = + keccak256(abi.encode(depositCommitment, Types.ZERO_BYTES32)); // AccountRoot doesn't matter for deposit, add dummy value submitBatch(root, 1, bytes32(0), Types.Usage.Deposit); } @@ -403,7 +403,8 @@ contract Rollup is BatchManager, EIP712, IEIP712 { uint256 batchID, Types.CommitmentInclusionProof memory previous, Types.MMCommitmentInclusionProof memory target, - Types.StateMerkleProof[] memory proofs + Types.StateMerkleProof[] memory proofs, + bytes32[] memory stateHashes ) public isDisputable(batchID) @@ -417,6 +418,7 @@ contract Rollup is BatchManager, EIP712, IEIP712 { (bytes32 processedStateRoot, Types.Result result) = massMigration.processMassMigrationCommit( previous.commitment.stateRoot, + stateHashes, paramMaxTxsPerCommit, target.commitment.body, proofs diff --git a/contracts/test/TestMassMigration.sol b/contracts/test/TestMassMigration.sol index b5051a86..a07b194e 100644 --- a/contracts/test/TestMassMigration.sol +++ b/contracts/test/TestMassMigration.sol @@ -30,6 +30,7 @@ contract TestMassMigration is MassMigration { function testProcessMassMigrationCommit( bytes32 stateRoot, + bytes32[] memory stateHashes, uint256 maxTxSize, Types.MassMigrationBody memory commitmentBody, Types.StateMerkleProof[] memory proofs @@ -46,6 +47,7 @@ contract TestMassMigration is MassMigration { (bytes32 postRoot, Types.Result result) = processMassMigrationCommit( stateRoot, + stateHashes, maxTxSize, commitmentBody, proofs