Skip to content

Commit

Permalink
Fog Seed Order Fix (#136)
Browse files Browse the repository at this point in the history
* Fix FogSeed Ordering

* Fix FogSeed Order

* Revert serialization change

* Remove unused serialization code
  • Loading branch information
dolanbernard authored Oct 2, 2023
1 parent f654797 commit 88efb46
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 45 deletions.
2 changes: 1 addition & 1 deletion android-sdk/publish.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'maven-publish'

version '5.0.0'
version '5.0.1-pre0'
group 'com.mobilecoin'

Properties properties = new Properties()
Expand Down
51 changes: 7 additions & 44 deletions android-sdk/src/main/java/com/mobilecoin/lib/FogSeed.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FogSeed implements Parcelable, Comparable<FogSeed> {
private int rngVersion;
// True if the seed is (a) decommissioned and (b) all utxos have been retrieved.
private boolean isObsolete;
private long ingestInvocationId;
private UnsignedLong ingestInvocationId;
private UnsignedLong startBlock;
private ArrayList<OwnedTxOut> utxos;

Expand All @@ -42,7 +42,7 @@ class FogSeed implements Parcelable, Comparable<FogSeed> {
@NonNull View.RngRecord rngRecord
) throws KexRngException {
Logger.i(TAG, "Initializing Fog Seed");
ingestInvocationId = rngRecord.getIngestInvocationId();
ingestInvocationId = UnsignedLong.fromLongBits(rngRecord.getIngestInvocationId());
nonce = rngRecord.getPubkey().getPubkey().toByteArray();
rngVersion = rngRecord.getPubkey().getVersion();
startBlock = UnsignedLong.fromLongBits(rngRecord.getStartBlock());
Expand Down Expand Up @@ -122,7 +122,7 @@ List<OwnedTxOut> getTxOuts() {
return utxos;
}

long getIngestInvocationId() {
UnsignedLong getIngestInvocationId() {
return ingestInvocationId;
}

Expand All @@ -134,43 +134,6 @@ void markObsolete() {
isObsolete = true;
}


private void writeObject(ObjectOutputStream out) throws IOException, KexRngException {
out.write(nonce.length);
out.write(nonce);

byte[] storedRngProtobufBytes = kexRng.getProtobufBytes();
out.write(storedRngProtobufBytes.length);
out.write(storedRngProtobufBytes);

out.writeInt(rngVersion);
out.writeObject(startBlock);
out.writeObject(utxos);
out.writeLong(ingestInvocationId);
}

@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException, KexRngException {
int nonceLength = in.read();
nonce = new byte[nonceLength];
int bytesRead = in.read(nonce);
if (bytesRead != nonceLength) {
throw new IOException();
}
int storedRngProtobufBytesLength = in.read();
byte[] storedRngProtobufBytes = new byte[storedRngProtobufBytesLength];
int kexRngProtobufBytesRead = in.read(storedRngProtobufBytes);
if (kexRngProtobufBytesRead != storedRngProtobufBytesLength) {
throw new IOException();
}
kexRng = new ClientKexRng(storedRngProtobufBytes);
rngVersion = in.readInt();
startBlock = (UnsignedLong) in.readObject();
utxos = (ArrayList<OwnedTxOut>) in.readObject();
ingestInvocationId = in.readLong();
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -182,7 +145,7 @@ public boolean equals(Object o) {
FogSeed fogSeed = (FogSeed) o;
return rngVersion == fogSeed.rngVersion &&
isObsolete == fogSeed.isObsolete &&
ingestInvocationId == fogSeed.ingestInvocationId &&
ingestInvocationId.equals(fogSeed.ingestInvocationId) &&
Objects.equals(kexRng, fogSeed.kexRng) &&
Arrays.equals(nonce, fogSeed.nonce) &&
Objects.equals(startBlock, fogSeed.startBlock) &&
Expand Down Expand Up @@ -221,7 +184,7 @@ public void writeToParcel(Parcel parcel, int flags) {
parcel.writeByteArray(nonce);
parcel.writeInt(rngVersion);
parcel.writeByte((byte) (isObsolete ? 1 : 0));
parcel.writeLong(ingestInvocationId);
parcel.writeLong(ingestInvocationId.longValue());
parcel.writeParcelable(startBlock, flags);
parcel.writeTypedList(utxos);
}
Expand All @@ -235,7 +198,7 @@ private FogSeed(Parcel parcel) {
nonce = parcel.createByteArray();
rngVersion = parcel.readInt();
isObsolete = parcel.readByte() != 0;
ingestInvocationId = parcel.readLong();
ingestInvocationId = UnsignedLong.fromLongBits(parcel.readLong());
startBlock = parcel.readParcelable(UnsignedLong.class.getClassLoader());
utxos = parcel.createTypedArrayList(OwnedTxOut.CREATOR);
}
Expand All @@ -262,6 +225,6 @@ public FogSeed[] newArray(int length) {

@Override
public int compareTo(FogSeed fogSeed) {
return this.startBlock.compareTo(fogSeed.startBlock);
return this.ingestInvocationId.compareTo(fogSeed.ingestInvocationId);
}
}

0 comments on commit 88efb46

Please sign in to comment.