This repository was archived by the owner on Oct 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Token wallet doc #1272
Open
codeblooded1729
wants to merge
22
commits into
main
Choose a base branch
from
kapil/token_wallet_doc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Token wallet doc #1272
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a3fe53c
checkpoint
codeblooded1729 39ffbad
checkpoint
codeblooded1729 995c5a8
checkpoint
codeblooded1729 fd699aa
Merge remote-tracking branch 'origin/main' into kapil/token_wallet_doc
codeblooded1729 c592ee3
remove gitignore files
jdkanani 9639f0d
first draft
codeblooded1729 3fd1bfb
delete tapes
codeblooded1729 78a1552
fix typo
codeblooded1729 10dab3e
Minor changes
SteveThakur 74dbec5
only one kind of wallet
codeblooded1729 22aaa03
add token and wallet
codeblooded1729 81cb8a8
checkpoint
codeblooded1729 65df22f
CPC doc
codeblooded1729 72092d3
update CPC
codeblooded1729 a047c57
update typo
codeblooded1729 290844d
update high level overview
codeblooded1729 ade15ff
remove token and wallet programs for a while
codeblooded1729 97a279d
remove gitignore
codeblooded1729 405298c
update authors
codeblooded1729 c672257
remove image
codeblooded1729 287aeaf
remove wallet example
codeblooded1729 8d4a8a6
Merge branch 'main' into kapil/token_wallet_doc
codeblooded1729 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| book |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [book] | ||
| authors = ["codeblooded1729"] | ||
| language = "en" | ||
| multilingual = false | ||
| src = "src" | ||
| title = "wallet-token-example" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Summary | ||
|
|
||
| - [Chapter 1](./chapter_1.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # High level overview | ||
|
|
||
| Lets setup the scenario. | ||
|
|
||
| Alice owns a USDC token in her USDC wallet. She has to transfer the token to Bob, who has his own USDC wallet. | ||
codeblooded1729 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| A USDC token is represented as `StateObject` with constraint owner being USDC token program represented through `ProgramIdentifier`. | ||
|
|
||
| ```rust | ||
|
|
||
| let struct StateObject{ | ||
| /// location in the state Patricia tree | ||
| address: [bool; DEPTH] // TODO: update to exact datatype | ||
codeblooded1729 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// The only program who can mutate data field | ||
| constraint_owner: ProgramIdentifier | ||
| /// blob of data | ||
| data: &[u8] | ||
| } | ||
|
|
||
| struct ProgramIdenitifer{ | ||
codeblooded1729 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// commitment to read only data from ELF | ||
| program_rom_hash: Poseidon2Hash | ||
| /// commitment to memory init table | ||
| memory_init_hash: Poseidon2Hash | ||
| /// the instruction at which program execution starts | ||
| entry_point: usize | ||
| } | ||
| let usdc_token_program = ProgramIdentifier { | ||
| program_rom_hash: [11, 113, 20, 251].into(), | ||
| memory_init_hash: [2, 31, 3, 62].into(), | ||
| entry_point: 0, | ||
| }; | ||
|
|
||
| let usdc_token_owner = ALICE_PUBLIC_KEY; | ||
|
|
||
| let usdc_token_object = StateObject{ | ||
| address: [1, 0, 0].into(), | ||
| constraint_owner: usdc_token_program | ||
| data: usdc_token_owner.to_bytes(), | ||
|
|
||
| } | ||
| ``` | ||
|
|
||
| The USDC token transfer also needs to interact with wallets of Alice and Bob. Namely it needs approval from their respective wallet programs to do the token transfer. | ||
codeblooded1729 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```rust | ||
| S let alice_wallet = ProgramIdentifier { | ||
| program_rom_hash: [21, 90, 121, 87].into(), | ||
| memory_init_hash: [31, 35, 20, 189].into(), | ||
| entry_point: 0, | ||
| }; | ||
|
|
||
| let bob_wallet = ProgramIdentifier { | ||
| program_rom_hash: [0, 2, 121, 187].into(), | ||
| memory_init_hash: [180, 19, 19, 56].into(), | ||
| entry_point: 0, | ||
| }; | ||
| ``` | ||
|
|
||
| on high level, the programs be responsible for the following: | ||
|
|
||
| - `usdc_token_program` : | ||
| - - "send" a request to `alice_wallet` program to approve the transfer of `usdc_token_object` to `bob_wallet`. | ||
codeblooded1729 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - once it "receives" an approval from the program, it changes the owner of `usdc_token_program` to Bob, by updating the public key | ||
| - finally, it "broadcasts" that it has changed the object's state. | ||
codeblooded1729 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - `alice_wallet` | ||
| - - "receive" request of approval from `alice_wallet` to do the transfer of `usdc_token_object` to `bob_wallet` | ||
| - "broadcast" that it has read the `usdc_token_object` | ||
| - check that the public key mentioned in `usdc_token_object` indeed corresponds to `alice_wallet`'s private key. And `bob_wallet` corresponds to the wallet it indeed wants to transfer the token object to. | ||
| - "send" back the approval to `usdc_token_program` | ||
|
|
||
| But what exactly would happen when we say "send", "receive" and "broadcast" occur? | ||
| The reality is that these won't occur in usual sense. That is, "send" or "receive" don't correspond to a program calling another program or waiting for a response from other program. Nor "broadcast" refers to sending it some entity who is listening. | ||
|
|
||
| What actually would happen is that these programs would demonstrate that they have actually followed a script together, complied with other's requests, as well as sent the intended responses. Each of the program continues the execution as if it had made the "call" with correct arguements, "received" the intended response, and "broadcasted" the intended state change. | ||
| This entire script is stored in two parts. `CallTape` is the part where the "call" and "receive" events are stored. While `EventTape` is the part where all the proposed changes to final state are stored. | ||
|
|
||
| Now how these tapes are created? The idea is that the play is performed, and then the script is created. Each program has two types of execution, native and zkvm. In the native execution all the "call", "receive" and "broadcast" are emulated in the intended manner, and the `CallTape` and `EventTape` is generated. In the zkvm execution, the program, the actual functions mentioned in the `CallTape` are executed by corresponding program, and their output is shown to be the same as the ones mentioned in the `CallTape`. | ||
|
|
||
| In this scenario, the `CallTape` would attest to following events | ||
|
|
||
| - `token_program` called `alice_wallet` to execute the `approve_transfer` function with arguments `(alice_wallet, usdc_token_object, ))` | ||
codeblooded1729 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| SystemTapes { | ||
| private_tape: RawTape { | ||
| start: 0, | ||
| len: 0, | ||
| }, | ||
| public_tape: RawTape { | ||
| start: 0, | ||
| len: 0, | ||
| }, | ||
| call_tape: CallTape { | ||
| writer: [ | ||
| CPCMessage { | ||
| caller_prog: MZK-00000000-00000000-0, | ||
| callee_prog: MZK-0b7114fb-021f033e-0, | ||
| args: 0x46143821000000000b7114fb021f033e000000000400000000000000e4ffffff000000000b7114fb021f033e00000000d0ffffff04000000155a79571f2314bd00000000000279bbb413133800000000, | ||
| ret: 0x00, | ||
| }, | ||
| CPCMessage { | ||
| caller_prog: MZK-0b7114fb-021f033e-0, | ||
| callee_prog: MZK-155a7957-1f2314bd-0, | ||
| args: 0x4614382100000000155a79571f2314bd000000000400000000000000e4ffffff000000000b7114fb021f033e0000000000000000000279bbb413133800000000c0ffffff04000000, | ||
| ret: 0x0001, | ||
| }, | ||
| ], | ||
| }, | ||
| event_tape: EventTape { | ||
| writer: [ | ||
| EventTapeSingle { | ||
| id: MZK-0b7114fb-021f033e-0, | ||
| contents: [ | ||
| ReadContextVariable( | ||
| SelfProgramIdentifier( | ||
| MZK-0b7114fb-021f033e-0, | ||
| ), | ||
| ), | ||
| UpdatedStateObject( | ||
| StateObject { | ||
| address: Addr: 0x0400000000000000, | ||
| constraint_owner: MZK-0b7114fb-021f033e-0, | ||
| data: [], | ||
| }, | ||
| ), | ||
| ], | ||
| }, | ||
| EventTapeSingle { | ||
| id: MZK-155a7957-1f2314bd-0, | ||
| contents: [ | ||
| ReadContextVariable( | ||
| SelfProgramIdentifier( | ||
| MZK-155a7957-1f2314bd-0, | ||
| ), | ||
| ), | ||
| ReadStateObject( | ||
| StateObject { | ||
| address: Addr: 0x0400000000000000, | ||
| constraint_owner: MZK-0b7114fb-021f033e-0, | ||
| data: [], | ||
| }, | ||
| ), | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| riscv32-elf-objdump -d ./examples/target/riscv32im-mozak-zkvm-elf/release/tokenbin |
9 changes: 9 additions & 0 deletions
9
wasm-demo/node_modules/playwright-core/lib/vite/recorder/playwright-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
wasm-demo/node_modules/playwright-core/lib/vite/traceViewer/playwright-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.