From 6e4524aa60c594d8b42ca763e93033889920c18c Mon Sep 17 00:00:00 2001 From: Boris Cvitak Date: Fri, 30 Aug 2024 20:30:39 +0200 Subject: [PATCH] build(blog): add math and latex plugins for blog build --- apps/website/blog/2024-08-29-poll-joining.md | 2 +- apps/website/docusaurus.config.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/website/blog/2024-08-29-poll-joining.md b/apps/website/blog/2024-08-29-poll-joining.md index d9f34f7b6..a8ebe9c21 100644 --- a/apps/website/blog/2024-08-29-poll-joining.md +++ b/apps/website/blog/2024-08-29-poll-joining.md @@ -30,7 +30,7 @@ The poll joining does introduce one extra step for the user. Besides that, all f Besides poll joining we have introduced a new feature that drastically lowered the overall cost of the protocol. Before we reveal what was the upgrade, we should first recap how the protocol worked in the original version, specifically the message processing. In the original protocol, users submitted their messages to the Poll smart contract. Each message was stored in a smart contract Merkle tree, the accumulator queue to be precise. At the end of the voting period, the coordinator had to merge the message tree by sending multiple merging messages for data structure subtrees so the final message root could be computed. When the message route was computed, the coordinator used inclusion proofs in the message processing circuit to prove that each processed message was indeed found in the message tree. This sounds like a really expensive procedure - because it was. Let's analyze what could be improved. -First, all messages need to be processed in the same order that they were submitted to the poll contract. Using a tree structure and inclusion proofs does indeed prove that, but if there only was a data structure that maintains the order of items in a given immutable order? Yes, you guessed it, it is Blockchain. Each block in the chain stores an immutable reference to a previous block, keeping the order. It sounds like we have to make the message object even more complex and keep the reference to the previous message, but that is not the way. We can start with a random value, a hash of an initial string, and call it a chain hash. When there are no messages, the chain hash keeps the initial value. Once a new message comes to the poll, we can compute the message hash (already done for the message tree in the original protocol) and update the chain hash to a hash value of the current chain hash and newly received message hash. Formally, $chainHash_i = hash(chainHash_{i-1}, messageHash_i)$. +First, all messages need to be processed in the same order that they were submitted to the poll contract. Using a tree structure and inclusion proofs does indeed prove that, but if there only was a data structure that maintains the order of items in a given immutable order? Yes, you guessed it, it is Blockchain. Each block in the chain stores an immutable reference to a previous block, keeping the order. It sounds like we have to make the message object even more complex and keep the reference to the previous message, but that is not the way. We can start with a random value, a hash of an initial string, and call it a chain hash. When there are no messages, the chain hash keeps the initial value. Once a new message comes to the poll, we can compute the message hash (already done for the message tree in the original protocol) and update the chain hash to a hash value of the current chain hash and newly received message hash. Formally, $$chainHash_i = hash(chainHash_{i-1}, messageHash_i)$$ Second, the coordinator collects all messages from the smart contract events, so why should we explicitly store messages in the smart contract? With the chain hash approach - we don't. When the coordinator is processing messages, the only important thing for making sure that the messages are properly ordered and all messages are included is to check that the chain hash is correctly computed. Starting with an initial chain hash value we can process messages and incrementally update the chain hash in the circuit ending up with a value that has to match the last chain hash value in the smart contract. To optimize this procedure for batch message processing, we explicitly store chain hashes for each batch in the smart contract and verify the batch processing by submitting the chain hash values before and after the message batch. We can dynamically set the size of the batch, thus the number of stored batch chain hashes, based on the coordinator's processing power. diff --git a/apps/website/docusaurus.config.ts b/apps/website/docusaurus.config.ts index 9ccfb639f..f460b41cb 100644 --- a/apps/website/docusaurus.config.ts +++ b/apps/website/docusaurus.config.ts @@ -60,6 +60,8 @@ async function getConfig(): Promise { showReadingTime: true, editUrl: ({ blogDirPath, blogPath }) => `${GITHUB_URL}/edit/dev/website/${blogDirPath}/${blogPath}`, + remarkPlugins: [remarkMath], + rehypePlugins: [rehypeKatex], }, theme: { customCss: "./src/css/custom.css",