Skip to content

Commit bbd8fba

Browse files
committed
feat(wasm-privacy-coin): thread owned flag into shardtree retention
Per-commitment ownership booleans are now threaded from the proto wire format into the Rust shardtree append path. Owned leaves are assigned Retention::Marked so the shardtree preserves their witness paths; non-owned leaves remain Retention::Ephemeral (or Checkpoint for the last commitment in a block). Ticket: CSHLD-1208
1 parent b01608b commit bbd8fba

6 files changed

Lines changed: 219 additions & 42 deletions

File tree

packages/wasm-privacy-coin/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
<version>5.10.3</version>
4242
<scope>test</scope>
4343
</dependency>
44+
<dependency>
45+
<groupId>com.fasterxml.jackson.core</groupId>
46+
<artifactId>jackson-databind</artifactId>
47+
<version>2.17.0</version>
48+
<scope>test</scope>
49+
</dependency>
4450
</dependencies>
4551

4652
<distributionManagement>

packages/wasm-privacy-coin/proto/privacy_coin.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ message AppendCommitmentsRequest {
1515
uint32 block_height = 1;
1616
repeated bytes commitments = 2; // each exactly 32 bytes (cmx)
1717
optional bytes expected_root = 3; // 32 bytes; absent = skip verification
18+
repeated bool owned = 4; // per-commitment ownership flag; absent/empty = all not-owned
1819
}
1920

2021
message TruncateRequest {

packages/wasm-privacy-coin/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ pub unsafe extern "C" fn append_commitments(ptr: *const u8, len: u32) -> i32 {
186186
Some(tree) => {
187187
let commitments: Vec<Vec<u8>> =
188188
req.commitments.iter().map(|b| b.to_vec()).collect();
189+
let owned = req.owned;
189190
let exp = expected_root.as_deref();
190-
match tree.append_commitments(req.block_height, commitments, exp) {
191+
match tree.append_commitments(req.block_height, commitments, owned, exp) {
191192
Ok(root) => write_ok_bytes(root),
192193
Err(e) => {
193194
let (code, msg) = split_error(&e);

packages/wasm-privacy-coin/src/main/java/com/bitgo/wasm/privacycoin/zcash/ShieldedMerkleTree.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ public void ping() {
100100
*
101101
* @param blockHeight block height (u32 range)
102102
* @param commitments shielded note commitment values (cmx) for this block
103+
* @param owned per-commitment ownership flags; {@code null} or shorter list → remaining are false
103104
* @param expectedRoot root to verify against; {@code null} to skip
104105
* @return computed root after appending
105106
* @throws WasmException with code {@code ROOT_MISMATCH} if verification fails
106107
*/
107108
public ShieldedRoot appendCommitments(
108-
long blockHeight, List<ShieldedCommitment> commitments, ShieldedRoot expectedRoot) {
109+
long blockHeight, List<ShieldedCommitment> commitments, List<Boolean> owned,
110+
ShieldedRoot expectedRoot) {
109111
requireU32(blockHeight, "blockHeight");
110112
Objects.requireNonNull(commitments, "commitments must not be null");
111113

@@ -115,6 +117,9 @@ public ShieldedRoot appendCommitments(
115117
.addAllCommitments(commitments.stream()
116118
.map(c -> ByteString.copyFrom(c.bytes()))
117119
.toList());
120+
if (owned != null && !owned.isEmpty()) {
121+
req.addAllOwned(owned);
122+
}
118123
if (expectedRoot != null) {
119124
req.setExpectedRoot(ByteString.copyFrom(expectedRoot.bytes()));
120125
}
@@ -123,11 +128,6 @@ public ShieldedRoot appendCommitments(
123128
return ShieldedRoot.of(unwrap(r, resp -> resp.getBytesValue().toByteArray()));
124129
}
125130

126-
/** Convenience overload — appends without root verification. */
127-
public ShieldedRoot appendCommitments(long blockHeight, List<ShieldedCommitment> commitments) {
128-
return appendCommitments(blockHeight, commitments, null);
129-
}
130-
131131
/**
132132
* Rolls the tree back to the checkpoint at the given block height.
133133
*

0 commit comments

Comments
 (0)