Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Set console caller and signer when executing closures. #2525

Draft
wants to merge 4 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion synthesizer/process/src/stack/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ impl<N: Network> StackExecute<N> for Stack<N> {

// Initialize the registers.
let mut registers = Registers::new(call_stack, self.get_register_types(closure.name())?.clone());

use circuit::Eject;

// Set the transaction signer.
registers.set_signer(signer.eject_value());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you wrap the two new sets with if let CallStack::Execute(..) = registers.call_stack() just like we do below? Then we can keep the use Eject to just within the Execute blocks. I hope the tests still pass then O:)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually want to do that? In the corresponding logic in execute_function we set in all modes, not just CallStack::Execute.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm good call out. I guess we can leave the PR as is then.

I appended a diff to test if wrapping all of the console sets in Execute mode would work, and indeed the tests still pass (modulo requiring new expectations because I changed a test). Maybe this can inform a hypothetical future refactor of execute_{function, closure}.

diff.txt

// Set the transition signer, as a circuit.
registers.set_signer_circuit(signer);
// Set the transaction caller.
registers.set_caller(caller.eject_value());
// Set the transition caller, as a circuit.
registers.set_caller_circuit(caller);
// Set the transition view key, as a circuit.
Expand All @@ -57,7 +64,6 @@ impl<N: Network> StackExecute<N> for Stack<N> {
closure.inputs().iter().map(|i| i.register()).zip_eq(inputs).try_for_each(|(register, input)| {
// If the circuit is in execute mode, then store the console input.
if let CallStack::Execute(..) = registers.call_stack() {
use circuit::Eject;
// Assign the console input to the register.
registers.store(self, register, input.eject_value())?;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
errors: []
outputs:
- verified: true
execute:
self_caller_in_closure.aleo/dummy:
outputs:
- '{"type":"private","id":"2216227416503041347433412034872956491846811102146440372685849103494739704020field","value":"ciphertext1qyqya6k83s309kj2l82tj5fr80n7e7w7t56ff72ug8ueqhqzevn2vys72rsev"}'
speculate: the execution was accepted
add_next_block: succeeded.
- verified: true
execute:
self_caller_in_closure.aleo/run_check:
outputs: []
speculate: the execution was accepted
add_next_block: succeeded.
additional:
- child_outputs:
credits.aleo/fee_public:
outputs:
- '{"type":"future","id":"7718771598168275830568214808516419506185731287938173896061440207543931919734field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1gj8900ftrtm5gpjljk9tuv8tmr46m88s5dvugdx8hnmftvpfv5rqempqfd,\n 1334u64\n ]\n}"}'
- child_outputs:
credits.aleo/fee_public:
outputs:
- '{"type":"future","id":"3733678765361147903053791676426696003831360239303256048750709990852510369243field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1gj8900ftrtm5gpjljk9tuv8tmr46m88s5dvugdx8hnmftvpfv5rqempqfd,\n 1161u64\n ]\n}"}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
randomness: 63249871089234
cases:
- program: self_caller_in_closure.aleo
function: dummy
inputs: [1u32, 2u32]
- program: self_caller_in_closure.aleo
function: run_check
inputs: []
*/

program self_caller_in_closure.aleo;

closure check_caller:
input r0 as address;
assert.eq self.caller r0;

closure check_signer:
input r0 as address;
assert.eq self.signer r0;

function run_check:
call check_caller self.caller;
call check_signer self.signer;

function dummy:
input r0 as u32.public;
input r1 as u32.private;
add r0 r1 into r2;
output r2 as u32.private;