Skip to content

Commit c8c8068

Browse files
committed
added in code to comport with snarkvm 3.8 upgrade
1 parent a2e526d commit c8c8068

File tree

3 files changed

+89
-23
lines changed

3 files changed

+89
-23
lines changed

wasm/src/programs/macros.rs

Lines changed: 83 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,82 @@ macro_rules! process_inputs {
3030
}};
3131
}
3232

33+
#[macro_export]
34+
macro_rules! authorize {
35+
(
36+
$process:expr,
37+
$inputs:expr,
38+
$program_string:expr,
39+
$function_id_string:expr,
40+
$private_key:expr,
41+
$rng:expr
42+
) => {{
43+
log("Loading program");
44+
let program =
45+
ProgramNative::from_str($program_string).map_err(|_| "The program ID provided was invalid".to_string())?;
46+
log("Loading function");
47+
let function_name = IdentifierNative::from_str($function_id_string)
48+
.map_err(|_| "The function name provided was invalid".to_string())?;
49+
50+
let program_id = program.id().to_string();
51+
52+
if program_id != "credits.aleo" {
53+
if !$process.contains_program(program.id()) {
54+
log("Adding program to the process");
55+
$process.add_program(&program).map_err(|e| e.to_string())?;
56+
}
57+
}
58+
59+
log(&format!("Creating authorization for {program_id}:{function_name}"));
60+
$process
61+
.authorize::<CurrentAleo, _>($private_key, program.id(), function_name, $inputs.iter(), $rng)
62+
.map_err(|err| err.to_string())?
63+
}};
64+
}
65+
66+
#[macro_export]
67+
macro_rules! authorize_fee {
68+
(
69+
$process:expr,
70+
$private_key:expr,
71+
$deployment_or_execution_id:expr,
72+
$base_fee:expr,
73+
$priority_fee:expr,
74+
$fee_record:expr,
75+
$rng:expr
76+
) => {{
77+
match $fee_record {
78+
Some(fee_record) => {
79+
log("Authorizing credits.aleo/fee_private");
80+
let fee_record_native = RecordPlaintextNative::from_str(&fee_record.to_string())
81+
.map_err(|e| format!("Invalid fee record: {}", e))?;
82+
$process
83+
.authorize_fee_private::<CurrentAleo, _>(
84+
$private_key,
85+
fee_record_native,
86+
$base_fee,
87+
$priority_fee,
88+
$deployment_or_execution_id,
89+
$rng,
90+
)
91+
.map_err(|e| e.to_string())?
92+
}
93+
None => {
94+
log("Authorizing credits.aleo/fee_public");
95+
$process
96+
.authorize_fee_public::<CurrentAleo, _>(
97+
$private_key,
98+
$base_fee,
99+
$priority_fee,
100+
$deployment_or_execution_id,
101+
$rng,
102+
)
103+
.map_err(|e| e.to_string())?
104+
}
105+
}
106+
}};
107+
}
108+
33109
#[macro_export]
34110
macro_rules! execute_program {
35111
($process:expr, $inputs:expr, $program_string:expr, $function_id_string:expr, $private_key:expr, $proving_key:expr, $verifying_key:expr, $rng:expr) => {{
@@ -52,12 +128,8 @@ macro_rules! execute_program {
52128
let program_id = program.id().to_string();
53129

54130
if program_id != "credits.aleo" {
55-
log("Adding program to the process");
56-
if let Ok(stored_program) = $process.get_program(program.id()) {
57-
if stored_program != &program {
58-
return Err("The program provided does not match the program stored in the cache, please clear the cache before proceeding".to_string());
59-
}
60-
} else {
131+
if !$process.contains_program(program.id()) {
132+
log("Adding program to the process");
61133
$process.add_program(&program).map_err(|e| e.to_string())?;
62134
}
63135
}
@@ -98,7 +170,7 @@ macro_rules! execute_program {
98170

99171
#[macro_export]
100172
macro_rules! execute_fee {
101-
($process:expr, $private_key:expr, $fee_record:expr, $priority_fee_microcredits:expr, $submission_url:expr, $fee_proving_key:expr, $fee_verifying_key:expr, $execution_id:expr, $rng:expr, $offline_query:expr, $minimum_execution_cost:expr) => {{
173+
($process:expr, $private_key:expr, $fee_record:expr, $priority_fee_microcredits:expr, $submission_url:expr, $fee_proving_key:expr, $fee_verifying_key:expr, $deployment_or_execution_id:expr, $rng:expr, $offline_query:expr, $minimum_execution_cost:expr) => {{
102174
if (($fee_proving_key.is_some() && $fee_verifying_key.is_none())
103175
|| ($fee_proving_key.is_none() && $fee_verifying_key.is_some()))
104176
{
@@ -138,7 +210,7 @@ macro_rules! execute_fee {
138210
fee_record_native,
139211
$minimum_execution_cost,
140212
$priority_fee_microcredits,
141-
$execution_id,
213+
$deployment_or_execution_id,
142214
$rng,
143215
).map_err(|e| e.to_string())?
144216
}
@@ -147,7 +219,7 @@ macro_rules! execute_fee {
147219
$private_key,
148220
$minimum_execution_cost,
149221
$priority_fee_microcredits,
150-
$execution_id,
222+
$deployment_or_execution_id,
151223
$rng,
152224
).map_err(|e| e.to_string())?
153225
}
@@ -168,7 +240,7 @@ macro_rules! execute_fee {
168240
let fee = trace.prove_fee::<CurrentAleo, _>(VarunaVersion::V2, &mut StdRng::from_entropy()).map_err(|e|e.to_string())?;
169241

170242
log("Verifying fee execution");
171-
$process.verify_fee(VarunaVersion::V2,&fee, $execution_id).map_err(|e| e.to_string())?;
243+
$process.verify_fee(VarunaVersion::V2,&fee, $deployment_or_execution_id).map_err(|e| e.to_string())?;
172244

173245
fee
174246
}}
@@ -194,4 +266,4 @@ macro_rules! calculate_minimum_fee {
194266

195267
minimum_execution_cost
196268
}};
197-
}
269+
}

wasm/src/programs/manager/execute.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ impl ProgramManager {
324324

325325
// Calculate the finalize cost for the function identified in the transition
326326
let cost = if block_height >= CurrentNetwork::CONSENSUS_HEIGHT(ConsensusVersion::V2).unwrap() {
327-
cost_in_microcredits_v2(stack, function_name).map_err(|e| e.to_string())?
327+
cost_in_microcredits_v2(&stack, function_name).map_err(|e| e.to_string())?
328328
} else {
329-
cost_in_microcredits_v1(stack, function_name).map_err(|e| e.to_string())?
329+
cost_in_microcredits_v1(&stack, function_name).map_err(|e| e.to_string())?
330330
};
331331

332332
// Accumulate the finalize cost.
@@ -360,6 +360,6 @@ impl ProgramManager {
360360

361361
let stack = process.get_stack(program.id()).map_err(|e| e.to_string())?;
362362

363-
cost_in_microcredits_v2(stack, &function_id).map_err(|e| e.to_string())
363+
cost_in_microcredits_v2(&stack, &function_id).map_err(|e| e.to_string())
364364
}
365365
}

wasm/src/programs/manager/mod.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,8 @@ function add_and_double:
219219

220220
ProgramManager::resolve_imports(&mut process, &program, Some(imports)).unwrap();
221221

222-
let add_import = process.get_program("addition_test.aleo").unwrap();
223-
let multiply_import = process.get_program("multiply_test.aleo").unwrap();
224-
let double_import = process.get_program("double_test.aleo").unwrap();
225-
let main_program = process.get_program("imported_add_mul.aleo");
226-
227-
assert_eq!(add_import, &add_program);
228-
assert_eq!(multiply_import, &multiply_program);
229-
assert_eq!(double_import, &double_program);
230-
assert!(main_program.is_err());
222+
assert!(process.contains_program(add_program.id()));
223+
assert!(process.contains_program(multiply_program.id()));
224+
assert!(process.contains_program(double_program.id()));
231225
}
232226
}

0 commit comments

Comments
 (0)