Created
March 15, 2022 18:35
-
-
Save llSourcell/70e3d1447218a349c306e37ac5e228e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rollUp( | |
uint256[2] memory a, | |
uint256[2][2] memory b, | |
uint256[2] memory c, | |
uint256[73] memory input | |
) public { | |
// TODO: Check if current merkle tree is | |
// equal to supplied merkle tree | |
uint256 balanceTreeRoot = input[1]; | |
// uint256 newBalanceTreeRoot = input[1]; | |
if (balanceTree.getRoot() != balanceTreeRoot) { | |
revert("Proof not valid for current tree"); | |
} | |
if (!txVerifier.verifyProof(a, b, c, input)) { | |
revert("Invalid roll up proofs"); | |
} | |
// Transaction one | |
uint256 from; | |
uint256 to; | |
uint256 amount; | |
uint256 fee; | |
uint256 nonce; | |
uint256 curOffset; | |
uint256 senderLeaf; | |
uint256 recipientLeaf; | |
uint256 senderPublicKeyHash; | |
uint256 recipientPublicKeyHash; | |
uint256 txDataOffset = 3; | |
uint256 txDataLength = 8; | |
uint256 batchSize = 2; | |
for (uint256 i = 0; i < batchSize; i++) { | |
curOffset = txDataOffset + (txDataLength * i); | |
from = input[curOffset]; | |
to = input[curOffset + 1]; | |
amount = input[curOffset + 2]; | |
fee = input[curOffset + 3]; | |
nonce = input[curOffset + 4]; | |
// Update user data | |
senderPublicKeyHash = balanceTreeKeys[from]; | |
recipientPublicKeyHash = balanceTreeKeys[to]; | |
User storage sender = balanceTreeUsers[senderPublicKeyHash]; | |
sender.balance -= amount; | |
sender.balance -= fee; | |
sender.nonce = nonce; | |
User storage recipient = balanceTreeUsers[recipientPublicKeyHash]; | |
recipient.balance += amount; | |
accuredFees += fee; | |
// Update merkle tree leaf | |
senderLeaf = hasher.hashBalanceTreeLeaf( | |
sender.publicKeyX, | |
sender.publicKeyY, | |
sender.balance, | |
sender.nonce | |
); | |
recipientLeaf = hasher.hashBalanceTreeLeaf( | |
recipient.publicKeyX, | |
recipient.publicKeyY, | |
recipient.balance, | |
recipient.nonce | |
); | |
balanceTree.update(sender.balanceTreeLeafIndex, senderLeaf); | |
balanceTree.update(recipient.balanceTreeLeafIndex, recipientLeaf); | |
} | |
emit RollUpProcessed(balanceTree.getRoot()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment