Skip to content

Commit

Permalink
Add new getters for debug group plust bucket data formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
rheitjoh committed Jul 8, 2021
1 parent f40a9f1 commit 0d6a34c
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 278 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Changed
- `DebugGroup` group operation counting data is now split up into buckets that allow, for example, to separately count operations done by different parties in an interactive protocol.
- `DebugGroup` group operation counting data is now split up into buckets that allow, for example, to separately count operations done by different parties in an interactive protocol. Furthermore, counting is now done statically, i.e. the data in each bucket persists across `DebugGroup` instances.

## [2.1.0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void incrementNumOps() {
++numOps;
}


public void incrementNumInversions() {
++numInversions;
}
Expand Down Expand Up @@ -104,35 +103,35 @@ public List<Integer> getMultiExpTermNumbers() {
return multiExpTermNumbers;
}

public void resetOpsCounter() {
/**
* Resets all counters.
*/
public void resetCounters() {
resetOpsCounter();
resetInversionsCounter();
resetSquaringsCounter();
resetExpsCounter();
resetMultiExpTermNumbers();
resetRetrievedRepresentationsCounter();
}

protected void resetOpsCounter() {
numOps = 0;
}

public void resetInversionsCounter() {
protected void resetInversionsCounter() {
numInversions = 0;
}

public void resetSquaringsCounter() {
protected void resetSquaringsCounter() {
numSquarings = 0;
}

public void resetExpsCounter() { numExps = 0; }
protected void resetExpsCounter() { numExps = 0; }

public void resetMultiExpTermNumbers() { multiExpTermNumbers = new LinkedList<>(); }
protected void resetMultiExpTermNumbers() { multiExpTermNumbers = new LinkedList<>(); }

public void resetRetrievedRepresentationsCounter() {
protected void resetRetrievedRepresentationsCounter() {
numRetrievedRepresentations = 0;
}

/**
* Resets all counters.
*/
public void resetCounters() {
resetOpsCounter();
resetInversionsCounter();
resetSquaringsCounter();
resetExpsCounter();
resetMultiExpTermNumbers();
resetRetrievedRepresentationsCounter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,33 +237,137 @@ public long getNumRetrievedRepresentations(String bucketName) {
return ((DebugGroupImpl) groupTotal.getImpl()).getNumRetrievedRepresentations(bucketName);
}

/*
-------------- ALL BUCKETS GETTER METHODS BLOCK -----------------------------------------------
*/

/**
* Retrieves number of group squarings including ones done in (multi-)exponentiation algorithms
* summed up across all buckets.
*/
public long getNumSquaringsTotalAllBuckets() {
return ((DebugGroupImpl) groupTotal.getImpl()).getNumOpsAllBuckets();
}

/**
* Retrieves number of group inversions including ones done in (multi-)exponentiation algorithms
* summed up across all buckets.
*/
public long getNumInversionsTotalAllBuckets() {
return ((DebugGroupImpl) groupTotal.getImpl()).getNumInversionsAllBuckets();
}

/**
* Retrieves number of group ops including ones done in (multi-)exponentiation algorithms
* summed up across all buckets.
* Does not include squarings.
*/
public long getNumOpsTotalAllBuckets() {
return ((DebugGroupImpl) groupTotal.getImpl()).getNumOpsAllBuckets();
}

/**
* Retrieves number of group squarings not including ones done in (multi-)exponentiation algorithms
* summed up across all buckets.
*/
public long getNumSquaringsNoExpMultiExpAllBuckets() {
return ((DebugGroupImpl) groupNoExpMultiExp.getImpl()).getNumSquaringsAllBuckets();
}

/**
* Retrieves number of group inversions not including ones done in (multi-)exponentiation algorithms
* summed up across all buckets.
*/
public long getNumInversionsNoExpMultiExpAllBuckets() {
return ((DebugGroupImpl) groupNoExpMultiExp.getImpl()).getNumInversionsAllBuckets();
}

/**
* Retrieves number of group ops not including ones done in (multi-)exponentiation algorithms
* summed up across all buckets.
* Does not include squarings.
*/
public long getNumOpsNoExpMultiExpAllBuckets() {
return((DebugGroupImpl) groupNoExpMultiExp.getImpl()).getNumOpsAllBuckets();
}

/**
* Retrieves number of group exponentiations done summed up across all buckets.
*/
public long getNumExpsAllBuckets() {
return ((DebugGroupImpl) groupNoExpMultiExp.getImpl()).getNumExpsAllBuckets();
}

/**
* Retrieves number of terms of each multi-exponentiation done across all buckets.
*/
public List<Integer> getMultiExpTermNumbersAllBuckets() {
return ((DebugGroupImpl) groupNoExpMultiExp.getImpl()).getMultiExpTermNumbersAllBuckets();
}

/**
* Retrieves number of retrieved representations of group elements for this group (via {@code getRepresentation()})
* summed up across all buckets.
*/
public long getNumRetrievedRepresentationsAllBuckets() {
// one of the groups suffices since we represent both elements
return ((DebugGroupImpl) groupTotal.getImpl()).getNumRetrievedRepresentationsAllBuckets();
}

/**
* Resets all counters for the bucket with the given name.
*/
public void resetCounters(String bucketName) {
((DebugGroupImpl) groupTotal.getImpl()).resetCounters(bucketName);
((DebugGroupImpl) groupNoExpMultiExp.getImpl()).resetCounters(bucketName);
}

/**
* Resets all counters.
* Resets counters for all buckets.
*/
public void resetCounters() {
((DebugGroupImpl) groupTotal.getImpl()).resetCounters();
((DebugGroupImpl) groupNoExpMultiExp.getImpl()).resetCounters();
public void resetCountersAllBuckets() {
((DebugGroupImpl) groupTotal.getImpl()).resetCountersAllBuckets();
((DebugGroupImpl) groupNoExpMultiExp.getImpl()).resetCountersAllBuckets();
}

/**
* Formats the count data for printing.
* Formats the count data of the bucket with the given name for printing.
*
* @param bucketName the name of the bucket whose data to format for printing
*
* @return a string detailing the results of counting
*/
public String formatCounterData(String bucketName) {
long totalNumOps = getNumOpsTotal(bucketName);
long totalNumSqs = getNumSquaringsTotal(bucketName);
long totalNumInvs = getNumInversionsTotal(bucketName);
long totalNumOpsSqs = totalNumOps + totalNumSqs;
long expMultiExpNumOps = totalNumOps - getNumOpsNoExpMultiExp(bucketName);
long expMultiExpNumSqs = totalNumSqs - getNumSquaringsNoExpMultiExp(bucketName);
long expMultiExpNumInvs = totalNumInvs - getNumInversionsNoExpMultiExp(bucketName);
List<Integer> multiExpTerms = getMultiExpTermNumbers(bucketName);

String tab = " ";
return String.format("%s\n", bucketName)
+ String.format("%s(Costly) Operations: %d\n", tab, totalNumOpsSqs)
+ String.format("%s%sNon-squarings: %d (%d of which happened during (multi-)exp)\n",
tab, tab, totalNumSqs, expMultiExpNumSqs)
+ String.format("%s%sSquarings: %d (%d of which happened during (multi-)exp)\n",
tab, tab, totalNumSqs, expMultiExpNumSqs)
+ String.format("%sInversions: %d (%d of which happened during (multi-)exp)\n",
tab, totalNumInvs, expMultiExpNumInvs)
+ String.format("%sExponentiations: %d\n", tab, getNumExps(bucketName))
+ String.format("%sMulti-exponentiations (number of terms in each): %s\n", tab, multiExpTerms)
+ String.format("%sgetRepresentation() calls: %d\n", tab, getNumRetrievedRepresentations(bucketName));
}

/**
* Formats the count data of all buckets for printing.
*
* @return a string detailing results of counting
*/
public String formatCounterData() {
return "------- Operation data for " + toString() + " -------\n"
+ "----- Total group operation data: -----\n"
+ " Number of Group Operations: " + getNumOpsTotal() + "\n"
+ " Number of Group Inversions: " + getNumInversionsTotal() + "\n"
+ " Number of Group Squarings: " + getNumSquaringsTotal() + "\n"
+ "----- Group operation data without operations done in (multi-)exp algorithms: -----\n"
+ " Number of Group Operations: " + getNumOpsNoExpMultiExp() + "\n"
+ " Number of Group Inversions: " + getNumInversionsNoExpMultiExp() + "\n"
+ " Number of Group Squarings: " + getNumSquaringsNoExpMultiExp() + "\n"
+ "----- Other data: -----\n"
+ " Number of exponentiations: " + getNumExps() + "\n"
+ " Number of terms in each multi-exponentiation: " + getMultiExpTermNumbers() + "\n"
+ " Number of retrieved representations (via getRepresentation()): "
+ getNumRetrievedRepresentations() + "\n";

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected GroupElementImpl pow(BigInteger k, boolean count) {

@Override
public GroupElementImpl pow(BigInteger k) {
// Only the NoExpMultiExp mode will call this method so we just always count here
return this.pow(k, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,46 +129,117 @@ public DebugGroupElementImpl wrap(Zn.ZnElement elem) {
public double estimateCostInvPerOp() {
return 1.6;
}

void incrementNumOps() {
getCurrentBucket().incrementNumOps();
getAllBucketsBucket().incrementNumOps();
}

void incrementNumInversions() {
getCurrentBucket().incrementNumInversions();
getAllBucketsBucket().incrementNumInversions();
}

void incrementNumSquarings() {
getCurrentBucket().incrementNumSquarings();
getAllBucketsBucket().incrementNumSquarings();
}

void incrementNumExps() {
getCurrentBucket().incrementNumExps();
getAllBucketsBucket().incrementNumExps();
}

void addMultiExpBaseNumber(int numTerms) {
getCurrentBucket().addMultiExpBaseNumber(numTerms);
getAllBucketsBucket().addMultiExpBaseNumber(numTerms);
}

void incrementNumRetrievedRepresentations() {
getCurrentBucket().incrementNumRetrievedRepresentations();
getAllBucketsBucket().incrementNumRetrievedRepresentations();
}

long getNumOps(String bucketName) {
return putBucketIfAbsent(bucketName).getNumOps();
}

long getNumInversions(String bucketName) {
return putBucketIfAbsent(bucketName).getNumInversions();
}

abstract void setBucket(String name);

abstract void incrementNumOps();

abstract void incrementNumInversions();
long getNumSquarings(String bucketName) {
return putBucketIfAbsent(bucketName).getNumSquarings();
}

abstract void incrementNumSquarings();
long getNumExps(String bucketName) {
return putBucketIfAbsent(bucketName).getNumExps();
}

abstract void incrementNumExps();
List<Integer> getMultiExpTermNumbers(String bucketName) {
return putBucketIfAbsent(bucketName).getMultiExpTermNumbers();
}

/**
* Tracks the fact that a multi-exponentiation with the given number of terms was done.
* @param numTerms the number of terms (bases) in the multi-exponentiation
*/
abstract void addMultiExpBaseNumber(int numTerms);
long getNumRetrievedRepresentations(String bucketName) {
return putBucketIfAbsent(bucketName).getNumRetrievedRepresentations();
}

abstract void incrementNumRetrievedRepresentations();
long getNumOpsAllBuckets() {
return getAllBucketsBucket().getNumOps();
}

abstract long getNumOps(String bucketName);
long getNumInversionsAllBuckets() {
return getAllBucketsBucket().getNumInversions();
}

abstract long getNumInversions(String bucketName);
long getNumSquaringsAllBuckets() {
return getAllBucketsBucket().getNumSquarings();
}

abstract long getNumSquarings(String bucketName);
long getNumExpsAllBuckets() {
return getAllBucketsBucket().getNumExps();
}

abstract long getNumExps(String bucketName);
List<Integer> getMultiExpTermNumbersAllBuckets() {
return getAllBucketsBucket().getMultiExpTermNumbers();
}

abstract List<Integer> getMultiExpTermNumbers(String bucketName);
long getNumRetrievedRepresentationsAllBuckets() {
return getAllBucketsBucket().getNumRetrievedRepresentations();
}

abstract long getNumRetrievedRepresentations(String bucketName);
void resetCounters(String bucketName) {
putBucketIfAbsent(bucketName).resetCounters();
}

abstract long getNumOpsAllBuckets();
void resetCountersAllBuckets() {
getAllBucketsBucket().resetCounters();
getBucketMap().forEach((name, bucket) -> bucket.resetCounters());
}

abstract long getNumInversionsAllBuckets();
/**
* Sets the currently used operation count storage bucket to the one with the given name.
* If a bucket with the given name does not exist, a new one is created.
* <p>
* All operations executed after setting a bucket will be counted within that bucket only.
* <p>
* The name of the default bucket is "default".
*
* @param name the name of the bucket to enable
*/
abstract void setBucket(String name);

abstract long getNumSquaringsAllBuckets();
/**
* Retrieves the bucket with the given name from {@code countingBucketMap},
* creating a new one if it does not exist yet.
*
* @param name the name of the bucket to retrieve
*/
abstract CountingBucket putBucketIfAbsent(String name);

abstract long getNumExpsAllBuckets();
abstract CountingBucket getAllBucketsBucket();

abstract List<Integer> getMultiExpTermNumbersAllBuckets();
abstract CountingBucket getCurrentBucket();

abstract long getNumRetrievedRepresentationsAllBuckets();
abstract Map<String, CountingBucket> getBucketMap();
}
Loading

0 comments on commit 0d6a34c

Please sign in to comment.