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

Commit

Permalink
WIP mm, stack too deep error
Browse files Browse the repository at this point in the history
  • Loading branch information
jacque006 committed Sep 14, 2021
1 parent 25bf336 commit eb25b70
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion contracts/Create2Transfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract Create2Transfer {
}
(stateRoot, result) = Transition.processReceiver(
stateRoot,
stateHashes[size + 1],
stateHashes[size],
feeReceiver,
tokenID,
fees,
Expand Down
4 changes: 4 additions & 0 deletions contracts/MassMigrations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contract MassMigration {
* */
function processMassMigrationCommit(
bytes32 stateRoot,
bytes32[] memory stateHashes,
uint256 maxTxSize,
Types.MassMigrationBody memory committed,
Types.StateMerkleProof[] memory proofs
Expand All @@ -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;
Expand All @@ -47,6 +49,7 @@ contract MassMigration {
_tx = committed.txs.massMigrationDecode(i);
(stateRoot, freshState, result) = Transition.processMassMigration(
stateRoot,
stateHashes[i],
_tx,
committed.tokenID,
proofs[i]
Expand All @@ -60,6 +63,7 @@ contract MassMigration {
}
(stateRoot, result) = Transition.processReceiver(
stateRoot,
stateHashes[size],
committed.feeReceiver,
committed.tokenID,
fees,
Expand Down
1 change: 1 addition & 0 deletions contracts/Transfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion contracts/client/FrontendMassMigration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ contract FrontendMassMigration {

function process(
bytes32 stateRoot,
bytes32 stateHashFrom,
bytes memory encodedTx,
uint256 tokenID,
Types.StateMerkleProof memory from
Expand All @@ -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(
Expand Down
16 changes: 9 additions & 7 deletions contracts/rollup/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions contracts/test/TestMassMigration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,6 +47,7 @@ contract TestMassMigration is MassMigration {
(bytes32 postRoot, Types.Result result) =
processMassMigrationCommit(
stateRoot,
stateHashes,
maxTxSize,
commitmentBody,
proofs
Expand Down

0 comments on commit eb25b70

Please sign in to comment.