Skip to content

Commit c3951ed

Browse files
authored
Merge pull request #133 from Zondax/dev
New Release
2 parents c2a9c9f + 1a200aa commit c3951ed

23 files changed

+381
-374
lines changed

app/Makefile.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ APPVERSION_M=4
33
# This is the minor version
44
APPVERSION_N=2
55
# This is the patch version
6-
APPVERSION_P=3
6+
APPVERSION_P=4

app/src/apdu_handler.c

-6
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
145145
break;
146146
}
147147

148-
case INS_SIGN_SAPLING: {
149-
CHECK_PIN_VALIDATED()
150-
handleSignSapling();
151-
break;
152-
}
153-
154148
default:
155149
THROW(APDU_CODE_INS_NOT_SUPPORTED);
156150
}

app/src/coin.h

-4
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,12 @@ extern "C" {
6666

6767
#define INS_GET_VERSION 0x00
6868
#define INS_GET_ADDR_SECP256K1 0x01
69-
#define INS_SIGN_SECP256K1 0x02
7069
#define INS_GET_ADDR_SAPLING_DIV 0x10
7170
#define INS_GET_ADDR_SAPLING 0x11
72-
#define INS_SIGN_SAPLING 0x12
7371

7472
#define INS_GET_DIV_LIST 0x09
7573

7674
#define INS_INIT_TX 0xa0
77-
#define INS_KEY_EXCHANGE 0xaa
7875
#define INS_EXTRACT_SPEND 0xa1
7976
#define INS_EXTRACT_OUTPUT 0xa2
8077
#define INS_CHECKANDSIGN 0xa3
@@ -85,7 +82,6 @@ extern "C" {
8582
#define INS_GET_OVK 0xf1
8683
#define INS_GET_NF 0xf2
8784
#define INS_GET_FVK 0xf3
88-
#define INS_CRASH_TEST 0xff
8985

9086
typedef enum { key_ivk = 0, key_ovk = 1, key_fvk = 2, nf = 3 } key_type_e;
9187

app/src/handlers/handler_signing.h

-4
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,3 @@ __Z_INLINE void handleCheckandSign(volatile uint32_t *tx, uint32_t rx) {
333333
*tx = 32;
334334
THROW(APDU_CODE_OK);
335335
}
336-
337-
__Z_INLINE void handleSignSapling() {
338-
THROW(APDU_CODE_COMMAND_NOT_ALLOWED);
339-
}

docs/APDUSPEC.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ The general structure of commands and responses is as follows:
6868

6969
---
7070

71-
### GET_VERSION
71+
### INS_GET_VERSION
7272

7373
#### Command
7474

@@ -198,7 +198,7 @@ If a diversifier was not valid, zero-bytes are returned (so always 220 bytes are
198198

199199
---
200200

201-
### INS_GET_IVK_SAPLING
201+
### INS_GET_IVK
202202

203203
Returns a sapling incoming viewing key.
204204
Forced user confirmation (So P1 needs to be 0x01).
@@ -225,7 +225,7 @@ Also returns the default diversifier (starting from index 0).
225225

226226
---
227227

228-
### INS_GET_OVK_SAPLING
228+
### INS_GET_OVK
229229

230230
Returns a sapling outgoing viewing key. Forced user confirmation (So P1 needs to be 0x01).
231231

@@ -249,7 +249,7 @@ Returns a sapling outgoing viewing key. Forced user confirmation (So P1 needs to
249249

250250
---
251251

252-
### INS_GET_FVK_SAPLING
252+
### INS_GET_FVK
253253

254254
Returns a sapling full viewing key fvk = (ak, nk, ovk). Forced user confirmation (So P1 needs to be 0x01).
255255

@@ -275,7 +275,7 @@ Returns a sapling full viewing key fvk = (ak, nk, ovk). Forced user confirmation
275275

276276
---
277277

278-
### INS_GET_NF_SAPLING
278+
### INS_GET_NF
279279

280280
Returns a sapling nullifier. TODO: Forced user confirmation (So P1 needs to be 0x01).
281281

@@ -397,7 +397,7 @@ Data is defined as:
397397

398398
Returns a proof generating key (PGK) and randomness (rcv and alpha) for a sapling spend.
399399

400-
- This command requires you already called the INS_INIT_TX_SAPLING.
400+
- This command requires you already called the INS_INIT_TX.
401401
- This command requires that it is needed to extract spendinfo.
402402

403403
#### Command
@@ -425,7 +425,7 @@ Returns a proof generating key (PGK) and randomness (rcv and alpha) for a saplin
425425

426426
Returns randomness (rcv and rseed (after ZIP202) and optional Hash_Seed) for a sapling output.
427427

428-
- This command requires you already called the INS_INIT_TX_SAPLING.
428+
- This command requires you already called the INS_INIT_TX.
429429
- This command requires you already called the correct number of INS_GET_SPENDINFO.
430430
- This command requires that it is needed to extract outputinfo.
431431

@@ -560,7 +560,7 @@ Data is defined as:
560560

561561
---
562562

563-
### INS_GET_EXTRACT_TRANSSSIG
563+
### INS_EXTRACT_TRANSSIG
564564

565565
Returns a SECP256K1 signature for a sapling transparent input if available. Othrewise, it returns only an error code.
566566

docs/previuos/zcash_workflow_v1.md

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
Zcash ledger, first connect:
2+
- Address generation
3+
- Sharing address with host
4+
- Sharing IVK with host
5+
//TODO: change to APDU API
6+
```mermaid
7+
sequenceDiagram
8+
participant LF as Ledger flash storage
9+
participant LC as Ledger computation
10+
participant H as Host
11+
participant N as Network
12+
H ->> LC: compute_address(path: u32)
13+
activate LC
14+
LC -->> LF: store_ivk(ivk) ?
15+
Note over LF: potentially store (path, IVK)
16+
LC ->> H: address: (diversifier, pk_d)
17+
LC ->> H: incoming viewing key: ivk
18+
deactivate LC
19+
Note over H,LC: show address on both screens?
20+
```
21+
22+
Zcash ledger, syncing
23+
- Sharing IVK with host
24+
- Decrypt incoming notes and verification note commitments
25+
- TODO: what to do with matching notes?
26+
```mermaid
27+
sequenceDiagram
28+
participant LF as Ledger flash storage
29+
participant LC as Ledger computation
30+
participant H as Host
31+
participant N as Network
32+
H ->> LC: get_ivk(path: u32)
33+
#add minor confirmation
34+
activate LC
35+
LC -->> LF: retrieve_ivk(path) ?
36+
LF -->> LC: ivk ?
37+
Note over LC: compute_ivk(path)
38+
LC ->> H: ivk
39+
deactivate LC
40+
activate H
41+
H ->> N: get_unspend_notes()
42+
N ->> H: [unspend_notes]
43+
Note over H: [matching_notes] = decrypt_all_unspend_notes(ivk, [unspend_notes])
44+
Note over H: store [matching_notes] (d, pk_d, v, rcm)
45+
deactivate H
46+
```
47+
48+
Zcash ledger, make shielded transaction phase 1
49+
- Verify outputs on screen
50+
51+
```mermaid
52+
sequenceDiagram
53+
participant LF as Ledger flash storage
54+
participant LC as Ledger computation
55+
participant H as Host
56+
participant N as Network
57+
58+
Note over H: show amount, address, memo-fields per output
59+
Note over H: validate amount <= total_amount
60+
H ->> LC: initiate_transaction()
61+
N ->> H: anchor of note?
62+
N ->> H: metadata
63+
Note over H: input note selection (path, note)
64+
65+
activate LC
66+
loop Every output note
67+
H ->> LC: verify_output(d, pk_d, value, memo)
68+
Note over H,LC: approve amount and address and verify on screens
69+
Note over H,LC: approve hash of memo and verify on screens
70+
LC ->> H: approval of output
71+
LC ->> LF: store_output_data(d,pk_d,value,memo)
72+
end
73+
deactivate LC
74+
#compute value balance and approve
75+
Note over LC,H: continue if all approved
76+
```
77+
78+
Zcash ledger, make shielded transaction phase 2
79+
- Process outputs and store in flash
80+
- Compute hash of all outputs
81+
82+
```mermaid
83+
sequenceDiagram
84+
participant LF as Ledger flash storage
85+
participant LC as Ledger computation
86+
participant H as Host
87+
participant N as Network
88+
activate LC
89+
loop Every output note
90+
H ->> LC: make_transaction(path) #TODO: which path??? fixed one makes sense??
91+
Note over LC: compute random rcm
92+
LC ->> LF: update_rcmnew(rcm)
93+
LF ->> LC: (d,pk_d,value)
94+
Note over LC: compute value/note commitments
95+
LC ->> LF: update_valuecommitsum(vc)
96+
LC ->> LF: value/note commitments
97+
LC ->> H: value/note commitments
98+
LF ->> LC: d,pk_d, value, memo
99+
Note over LC: compute eph, c_out, c_enc
100+
LC ->> LF: eph, c_out, c_enc
101+
LC ->> H: eph, c_out, c_enc
102+
deactivate LC
103+
activate H
104+
H -->> LC: get_proof_key(path) #is this necessary?
105+
LC -->> H: proof_key
106+
Note over H: ZK proof of output note
107+
H ->> LC: zk_proof
108+
deactivate H
109+
activate LC
110+
LC ->> LF: zk_proof
111+
end
112+
Note over LC: perform shieldedoutput_hash
113+
LC ->> H: shielded_output_hash
114+
LC ->> LF: shielded_output_hash
115+
deactivate LC
116+
```
117+
118+
Zcash ledger, make shielded transaction phase 3
119+
- Process spends and store in flash
120+
- Store RCM values in flash
121+
- Compute hash of all outputs
122+
123+
```mermaid
124+
sequenceDiagram
125+
participant LF as Ledger flash storage
126+
participant LC as Ledger computation
127+
participant H as Host
128+
participant N as Network
129+
loop Every spend note
130+
N ->> H: anchor of note?
131+
H ->> LC: spend_this_note(path, valuecommit, rcm, anchor) # Do we need to verify here that rcm is correct? Is the zkproof of the spend the old one in the blockchain? #what about the valuecommit?
132+
LC ->> LF: (path, valuecommit, anchor)
133+
LC -->> H: proof_gen_key(path) ? #is this needed
134+
135+
activate LC
136+
LC ->> LF: update_rcmvalue(rcm)
137+
LC ->> LF: update_valuecommitsum(vc) #???
138+
139+
note over LC: compute nullifier
140+
LC ->> H: nullifier
141+
LC ->> LF: nullifier
142+
143+
note over LC: compute randomized verification key
144+
LC ->> H: randomized verification key
145+
LC ->> LF: (path, randomizer value, randomized verification key)
146+
deactivate LC
147+
148+
Note over H: ZK proof of spend note
149+
H ->> LC: zk_proof
150+
LC ->> LF: zk_proof
151+
152+
end
153+
Note over LC: perform shieldedspend_hash
154+
LC ->> LF: shieldedspend_hash #does the host actually need this?
155+
LC ->> H: shieldedspend_hash
156+
```
157+
158+
Zcash ledger, make shielded transaction phase 4
159+
- Host gives all remaining transaction (meta) data
160+
- Ledger does the complete TX_HASH_ALL
161+
- Final approval of transaction?
162+
- Ledger signs the necessary parts and shares with host
163+
- Host sends transaction blob to network
164+
165+
```mermaid
166+
sequenceDiagram
167+
participant LF as Ledger flash storage
168+
participant LC as Ledger computation
169+
participant H as Host
170+
participant N as Network
171+
172+
H -->> N: retrieve meta_data from network?
173+
N -->> H: meta_data
174+
175+
H ->> LC: meta_data transaction
176+
LC ->> LF: meta_data transaction
177+
178+
Note over LC: compute valuebalance and commitment
179+
LC ->> LF: valuebalance and commitment
180+
Note over LF,LC: verify rcm_secretkey/publickey
181+
182+
Note over LF,LC: perform_tx_hash_all over all data in flash
183+
184+
LC ->> H: tx_hash_all
185+
186+
Note over LC,H: final verification/approval of tx before signing?
187+
188+
LC ->> H: sign(rcm_secretkey, tx_hash_all)
189+
loop Every spend note
190+
LF ->> LC: randomized value
191+
Note over LC: get_secret_key(path)
192+
Note over LC: sign(sk, randomized value, tx_hash_all)
193+
LC ->> H: spend_auth_sign
194+
end
195+
196+
Note over H: make raw transaction blob
197+
H ->> N: raw_transaction_blob
198+
199+
```

docs/zcash_workflow_version2.md docs/previuos/zcash_workflow_v2.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Zcash ledger, make shielded transaction phase 1
7474
end
7575
deactivate LC
7676
Note over LC,H: continue if all approved
77-
```
77+
```
7878

7979
Zcash ledger, make shielded transaction phase 2
8080
- Process outputs and store in flash
@@ -114,14 +114,14 @@ Zcash ledger, make shielded transaction phase 1
114114
LC ->> H: shielded_output_hash
115115
LC ->> LF: shielded_output_hash
116116
deactivate LC
117-
```
117+
```
118118

119119
Zcash ledger, make shielded transaction phase 3
120120
- Process spends and store in flash
121121
- Store RCM values in flash
122122
- Compute hash of all outputs
123123

124-
```mermaid
124+
```mermaid
125125
sequenceDiagram
126126
participant LF as Ledger flash storage
127127
participant LC as Ledger computation
@@ -162,7 +162,7 @@ Zcash ledger, make shielded transaction phase 4
162162
- Ledger signs the necessary parts and shares with host
163163
- Host sends transaction blob to network
164164

165-
```mermaid
165+
```mermaid
166166
sequenceDiagram
167167
participant LF as Ledger flash storage
168168
participant LC as Ledger computation

0 commit comments

Comments
 (0)