From 1375729f44ae53cd1f9f6bb9e299162f0d1aa4a5 Mon Sep 17 00:00:00 2001
From: mvahabi <mvahabi@ucsc.edu>
Date: Tue, 18 Mar 2025 18:58:27 -0700
Subject: [PATCH] brought back the code comment blocks

---
 oram.cpp | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/oram.cpp b/oram.cpp
index 36b26dc..956dab5 100644
--- a/oram.cpp
+++ b/oram.cpp
@@ -11,24 +11,26 @@
 using namespace std;
 
 // ORAM parameters (for demonstration)
-const int TREE_HEIGHT = 3;
-const int BUCKET_CAPACITY = 3;
-const int NUM_LEAVES = 1 << TREE_HEIGHT;
-const int NUM_BUCKETS = (1 << (TREE_HEIGHT + 1)) - 1;
-const string STATE_FILE = "oram_state.db";
+const int TREE_HEIGHT = 5;            // Height of the tree (number of levels - 1)
+const int BUCKET_CAPACITY = 5;        // Maximum number of blocks per bucket
+const int NUM_LEAVES = 1 << TREE_HEIGHT;             // 2^TREE_HEIGHT leaves
+const int NUM_BUCKETS = (1 << (TREE_HEIGHT + 1)) - 1;  // Total number of buckets in a complete binary tree
+const string STATE_FILE = "oram_state.db";           // File to persist ORAM state
+
 
 // Structure for a data block.
 struct Block {
-    string id;
-    string data;
+    string id;     // Hashed block identifier (SHA-256 hex string)
+    string data;   // Block data (e.g. hex-encoded string)
 };
 
+
 // Global ORAM state:
-vector<vector<Block>> tree;
-unordered_map<string, int> posMap;
-vector<Block> stash;
+vector<vector<Block>> tree;              // Tree: vector of buckets (each bucket is a vector of blocks)
+unordered_map<string, int> posMap;       // Position map: maps block id (hashed string) to assigned leaf
+vector<Block> stash;                     // Stash: temporary storage for blocks during accesses
 
-// RNG for leaf assignment
+// Random number generator for new leaf assignments.
 mt19937 rng(random_device{}());
 
 // Helper: path indices from root to leaf
@@ -40,17 +42,17 @@ vector<int> getPathIndices(int leaf) {
         if (idx == 0) break;
         idx = (idx - 1) / 2;
     }
-    reverse(path.begin(), path.end());
+    //reverse(path.begin(), path.end());
     return path;
 }
 
-// Helper: random leaf
+// Helper: Generate a random leaf number between 0 and NUM_LEAVES-1.
 int getRandomLeaf() {
     uniform_int_distribution<int> dist(0, NUM_LEAVES - 1);
     return dist(rng);
 }
 
-// Load ORAM state
+// Load ORAM state firm the persistent file.
 void loadState() {
     ifstream infile(STATE_FILE);
     if (!infile) {
@@ -117,7 +119,7 @@ void loadState() {
     infile.close();
 }
 
-// Save ORAM state
+// Save ORAM state frim the persistent file
 void saveState() {
     ofstream outfile(STATE_FILE, ios::trunc);
     outfile << "#tree" << endl;
@@ -143,7 +145,7 @@ void saveState() {
     outfile.close();
 }
 
-// Eviction
+// Eviction function with dummy block insertion.
 void evictPath(vector<int> path) {
     reverse(path.begin(), path.end());
     for (int bucketIdx : path) {
@@ -175,7 +177,7 @@ void evictPath(vector<int> path) {
     }
 }
 
-// Access
+// ORAM access function.
 string accessBlock(const string &blockId, const string &newData, bool isWrite) {
     int oldLeaf;
     if (posMap.find(blockId) == posMap.end()) {
-- 
GitLab