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
Expand file tree
/
Copy pathmain.rs
More file actions
55 lines (48 loc) · 1.83 KB
/
main.rs
File metadata and controls
55 lines (48 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! We approve signatures by asserting the following equality:
//!
//! hash(private_key) == public_key
//!
//! Where `hash` can be any hard to invert function (in this case it's the
//! poseidon2 hash).
//!
//! During native execution:
//! We randomly generate a private key, which we then
//! hash to obtain a public key. We write this private key to our private tape.
//!
//! During guest execution:
//! We read this private key from the private tape and use a poseidon2 ecall to
//! help us prove that we know the pre-image.
// TODO(bing): We may use our `signatures` crate in future as an optimization,
// once we link it to our SDK.
#![allow(unused_attributes)]
use mozak_sdk::common::types::ProgramIdentifier;
use wallet_core_logic::{dispatch, BlackBox, MethodArgs, PrivateKey, PublicKey, TokenObject};
fn main() {
let remitter_program = ProgramIdentifier::new_from_rand_seed(2);
let remittee_program = ProgramIdentifier::new_from_rand_seed(3);
let remitter_private_key = PrivateKey::new_from_rand_seed(4);
let remitter_public_key = PublicKey(mozak_sdk::native::poseidon::poseidon2_hash_no_pad(
&remitter_private_key.0,
));
mozak_sdk::add_identity(remitter_program); // Manual override for `IdentityStack`
let _ = mozak_sdk::write(
&mozak_sdk::InputTapeType::PrivateTape,
&remitter_private_key.0[..],
);
mozak_sdk::rm_identity(); // Manual override for `IdentityStack`
let token_object = TokenObject {
pub_key: remitter_public_key.clone(),
amount: 10.into(),
};
let black_box = BlackBox {
remitter_program,
remittee_program,
token_object,
};
mozak_sdk::call_send(
remitter_program,
MethodArgs::ApproveSignature(remitter_public_key, black_box.clone()),
dispatch,
);
mozak_sdk::native::dump_proving_files();
}