-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhackathondarkdropprogramsdarkpool-program
More file actions
110 lines (110 loc) · 8 KB
/
hackathondarkdropprogramsdarkpool-program
File metadata and controls
110 lines (110 loc) · 8 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
warning: in the working copy of 'programs/darkpool/src/lib.rs', LF will be replaced by CRLF the next time Git touches it
[1mdiff --git a/programs/darkpool/src/lib.rs b/programs/darkpool/src/lib.rs[m
[1mindex 5f4343f..53a367c 100644[m
[1m--- a/programs/darkpool/src/lib.rs[m
[1m+++ b/programs/darkpool/src/lib.rs[m
[36m@@ -2,18 +2,53 @@[m [muse std::collections::BTreeSet;[m
[m
use anchor_lang::prelude::*;[m
use anchor_lang::AccountsExit;[m
use anchor_lang::Bumps;[m
use anchor_lang::system_program;[m
[32m+[m[32muse anchor_lang::solana_program::hash::hashv;[m
[32m+[m[32m#[cfg(feature = "poseidon")][m
[32m+[m[32muse ark_bn254::Fr;[m
[32m+[m[32m#[cfg(feature = "poseidon")][m
[32m+[m[32muse ark_ff::BigInteger;[m
[32m+[m[32m#[cfg(feature = "poseidon")][m
[32m+[m[32muse light_poseidon::{Poseidon, PoseidonHasher, PoseidonParameters};[m
[32m+[m
[32m+[m[32m#[cfg(feature = "poseidon")][m
[32m+[m[32mmod poseidon_constants_fr;[m
[m
const MAX_EXPIRATION_WINDOW: i64 = 30 * 24 * 60 * 60; // 30 days[m
const MIN_EXPIRATION_WINDOW: i64 = 60; // 1 minute[m
const MIN_RATE_LIMIT_SECONDS: i64 = 10;[m
const MIN_AUTHORITY_DELAY_SECONDS: i64 = 15 * 60; // 15 minutes[m
const MAX_AUTHORITY_DELAY_SECONDS: i64 = 7 * 24 * 60 * 60; // 7 days[m
const DEFAULT_AUTHORITY_DELAY_SECONDS: i64 = 24 * 60 * 60; // 24 hours[m
const MAX_FEE_BPS: u16 = 1000; // 10%[m
[32m+[m[32mconst SHIELDED_TREE_MAX_DEPTH: u8 = 20;[m
[32m+[m[32mconst SHIELDED_TREE_MAX_DEPTH_USIZE: usize = 20;[m
[32m+[m[32mconst SHIELDED_ZEROES: [[u8; 32]; 20] = [[m
[32m+[m[32m [32, 152, 245, 251, 158, 35, 158, 171, 60, 234, 195, 242, 123, 129, 228, 129, 220, 49, 36, 213, 95, 254, 213, 35, 168, 57, 238, 132, 70, 182, 72, 100],[m
[32m+[m[32m [13, 42, 45, 22, 205, 89, 26, 187, 101, 40, 94, 17, 180, 106, 87, 213, 202, 232, 251, 75, 0, 101, 203, 59, 250, 170, 20, 26, 206, 64, 19, 104],[m
[32m+[m[32m [7, 230, 128, 188, 164, 144, 187, 159, 30, 157, 9, 226, 43, 39, 19, 170, 154, 248, 17, 191, 202, 193, 138, 63, 48, 122, 4, 77, 41, 195, 73, 86],[m
[32m+[m[32m [26, 96, 199, 12, 249, 100, 63, 169, 166, 232, 102, 231, 38, 216, 134, 135, 103, 167, 75, 119, 158, 170, 117, 171, 53, 100, 112, 132, 68, 137, 93, 10],[m
[32m+[m[32m [35, 128, 16, 171, 32, 169, 232, 4, 174, 118, 77, 61, 79, 40, 79, 47, 232, 125, 196, 86, 9, 223, 129, 106, 190, 21, 102, 92, 138, 89, 109, 233],[m
[32m+[m[32m [44, 72, 21, 148, 130, 187, 172, 227, 120, 26, 173, 2, 24, 18, 27, 237, 220, 21, 100, 198, 176, 251, 252, 223, 68, 146, 25, 246, 109, 234, 204, 22],[m
[32m+[m[32m [20, 144, 239, 87, 158, 76, 47, 31, 235, 191, 118, 86, 98, 194, 98, 101, 10, 202, 52, 139, 195, 56, 66, 130, 156, 127, 239, 116, 41, 115, 4, 189],[m
[32m+[m[32m [2, 174, 165, 120, 72, 121, 181, 87, 218, 135, 152, 109, 57, 0, 63, 93, 211, 113, 234, 126, 198, 48, 133, 186, 54, 134, 94, 179, 44, 231, 11, 56],[m
[32m+[m[32m [38, 18, 236, 132, 199, 68, 152, 120, 180, 11, 100, 4, 241, 50, 151, 132, 43, 135, 13, 84, 177, 130, 87, 84, 144, 158, 43, 149, 189, 17, 233, 175],[m
[32m+[m[32m [46, 58, 251, 29, 26, 113, 8, 171, 63, 66, 175, 162, 246, 61, 231, 230, 50, 223, 180, 29, 62, 7, 117, 89, 60, 168, 141, 34, 218, 205, 155, 223],[m
[32m+[m[32m [47, 54, 75, 84, 109, 9, 110, 26, 213, 154, 151, 53, 145, 253, 60, 45, 29, 1, 232, 241, 88, 213, 111, 132, 231, 187, 240, 130, 79, 123, 234, 179],[m
[32m+[m[32m [41, 119, 29, 68, 205, 189, 160, 125, 44, 75, 37, 73, 50, 181, 75, 211, 177, 42, 255, 129, 196, 248, 161, 128, 128, 129, 22, 149, 142, 214, 241, 1],[m
[32m+[m[32m [15, 119, 124, 198, 191, 232, 68, 85, 38, 197, 122, 249, 255, 61, 22, 97, 82, 86, 92, 107, 244, 172, 132, 67, 235, 107, 184, 101, 202, 223, 144, 161],[m
[32m+[m[32m [8, 119, 83, 29, 39, 42, 224, 20, 107, 126, 103, 193, 129, 172, 179, 148, 81, 215, 227, 188, 113, 129, 71, 144, 21, 160, 87, 72, 117, 194, 239, 100],[m
[32m+[m[32m [46, 126, 88, 247, 224, 107, 203, 217, 98, 29, 24, 121, 215, 136, 205, 193, 27, 234, 0, 183, 154, 188, 177, 123, 58, 165, 93, 168, 14, 98, 38, 98],[m
[32m+[m[32m [30, 252, 182, 206, 135, 120, 223, 214, 244, 240, 57, 171, 6, 140, 6, 28, 19, 31, 20, 59, 233, 55, 36, 12, 43, 156, 143, 95, 148, 220, 239, 70],[m
[32m+[m[32m [40, 141, 85, 76, 44, 168, 81, 79, 81, 244, 221, 60, 70, 60, 133, 160, 173, 195, 241, 213, 156, 166, 238, 248, 183, 244, 164, 124, 224, 119, 173, 20],[m
[32m+[m[32m [16, 93, 55, 210, 6, 102, 160, 34, 253, 254, 183, 194, 234, 214, 181, 67, 62, 229, 205, 54, 73, 252, 78, 188, 166, 230, 101, 201, 65, 188, 153, 112],[m
[32m+[m[32m [10, 84, 243, 220, 193, 107, 4, 107, 122, 89, 109, 162, 19, 197, 87, 82, 26, 179, 104, 252, 46, 229, 18, 50, 202, 47, 180, 86, 159, 137, 10, 20],[m
[32m+[m[32m [31, 119, 64, 186, 175, 91, 166, 84, 77, 246, 87, 254, 66, 194, 157, 80, 60, 132, 108, 213, 146, 155, 176, 133, 163, 81, 163, 241, 180, 153, 121, 235],[m
[32m+[m[32m];[m
[32m+[m
[m
declare_id!("EPpgM9ogD8wTVESMmin8kwemTmkVPQhPq9w1Mpz8Gxb7");[m
[m
#[program][m
pub mod darkpool {[m
[36m@@ -101,10 +136,281 @@[m [mpub mod darkpool {[m
config_state.try_serialize(&mut cursor)?;[m
[m
Ok(())[m
}[m
[m
[32m+[m[32m pub fn initialize_shielded([m
[32m+[m[32m ctx: Context<InitializeShielded>,[m
[32m+[m[32m tree_depth: u8,[m
[32m+[m[32m ) -> Result<()> {[m
[32m+[m[32m let program_id = ctx.program_id;[m
[32m+[m[32m let config_info = ctx.accounts.shielded_config.to_account_info();[m
[32m+[m[32m let tree_info = ctx.accounts.shielded_tree.to_account_info();[m
[32m+[m[32m let vault_info = ctx.accounts.shielded_vault.to_account_info();[m
[32m+[m[32m let authority_info = ctx.accounts.authority.to_account_info();[m
[32m+[m[32m let system_program_info = ctx.accounts.system_program.to_account_info();[m
[32m+[m
[32m+[m[32m let (config_pda, config_bump) =[m
[32m+[m[32m Pubkey::find_program_address(&[b"shielded_config"], program_id);[m
[32m+[m[32m let (tree_pda, tree_bump) = Pubkey::find_program_address(&[b"shielded_tree"], program_id);[m
[32m+[m[32m let (vault_pda, vault_bump) =[m
[32m+[m[32m Pubkey::find_program_address(&[b"shielded_vault"], program_id);[m
[32m+[m
[32m+[m[32m require_keys_eq!(config_pda, *config_info.key, ErrorCode::ConstraintSeeds);[m
[32m+[m[32m require_keys_eq!(tree_pda, *tree_info.key, ErrorCode::ConstraintSeeds);[m
[32m+[m[32m require_keys_eq!(vault_pda, *vault_info.key, ErrorCode::ConstraintSeeds);[m
[32m+[m[32m require_keys_eq!([m
[32m+[m[32m system_program::ID,[m
[32m+[m[32m *system_program_info.key,[m
[32m+[m[32m ErrorCode::ConstraintAddress[m
[32m+[m[32m );[m
[32m+[m[32m require!(authority_info.is_writable, ErrorCode::ConstraintMut);[m
[32m+[m[32m require!(config_info.is_writable, ErrorCode::ConstraintMut);[m
[32m+[m[32m require!(tree_info.is_writable, ErrorCode::ConstraintMut);[m
[32m+[m[32m require!(vault_info.is_writable, ErrorCode::ConstraintMut);[m
[32m+[m
[32m+[m[32m require!([m
[32m+[m[32m tree_depth > 0 && tree_depth <= SHIELDED_TREE_MAX_DEPTH,[m
[32m+[m[32m DarkPoolError::InvalidTreeDepth[m
[32m+[m[32m );[m
[32m+[m
[32m+[m[32m let config_uninitialized =[m
[32m+[m[32m config_info.owner == &system_program::ID && config_info.lamports() == 0;[m
[32m+[m[32m let tree_uninitialized = tree_info.owner == &system_program::ID && tree_info.lamports() == 0;[m
[32m+[m[32m let vault_uninitialized =[m
[32m+[m[32m vault_info.owner == &system_program::ID && vault_info.lamports() == 0;[m
[32m+[m
[32m+[m[32m if config_uninitialized || tree_uninitialized || vault_uninitialized {[m
[32m+[m[32m require!([m
[32m+[m[32m config_uninitialized && tree_uninitialized && vault_uninitialized,[m
[32m+[m