rbpf icon indicating copy to clipboard operation
rbpf copied to clipboard

Interperter CUs Computation questions

Open shenghaoyuan opened this issue 1 year ago • 1 comments

Hello, I have two questions about CUs computation of the Solana interpreter, could someone please give me some suggestions?

  1. The Solana interpreter says the CALL_REG spends an additional CU by self.vm.due_insn_count += 1;, why?
  2. The interpreter does self.vm.due_insn_count = self.vm.previous_instruction_meter - self.vm.due_insn_count; and after invoking function, does self.vm.due_insn_count = 0;, why? Could we remove those two lines from the interpreter (and also modify the program.rs )?
// https://github.com/solana-labs/rbpf/blob/main/src/interpreter.rs#L477
                        self.vm.due_insn_count = self.vm.previous_instruction_meter - self.vm.due_insn_count; // removing 
                        self.vm.registers[0..6].copy_from_slice(&self.reg[0..6]);
                        self.vm.invoke_function(function);
                        self.vm.due_insn_count = 0; // removing 


https://github.com/solana-labs/rbpf/blob/main/src/program.rs#L331
                    vm.context_object_pointer.consume(vm.previous_instruction_meter - vm.due_insn_count); // `vm.previous_instruction_meter - vm.due_insn_count` -> `vm.due_insn_count`
                    ...
                    vm.previous_instruction_meter = vm.context_object_pointer.get_remaining(); // removing 

shenghaoyuan avatar Sep 23 '24 10:09 shenghaoyuan

The first question can be omitted as due_insn_count +1 is in a throw_error branch.

shenghaoyuan avatar Sep 24 '24 09:09 shenghaoyuan

The second is so that it is interface compatible with JIT compiled programs upon entry in a syscall. The syscall helper wrapper in program.rs does expect the CU metering to have been flushed.

Lichtso avatar Sep 30 '24 13:09 Lichtso