mirror of
https://github.com/powdr-labs/powdr.git
synced 2026-01-10 11:38:11 -05:00
Keep openvm program intact (#3075)
Since #3055, we don't need to change the program anymore. This PR keeps the program intact in openvm, passing the apc opcodes to openvm through a new API in openvm. See https://github.com/powdr-labs/openvm/pull/36 Related: https://github.com/powdr-labs/openvm-reth-benchmark/pull/26
This commit is contained in:
committed by
GitHub
parent
0d43b411b3
commit
9f36102a16
2
.github/workflows/nightly-tests.yml
vendored
2
.github/workflows/nightly-tests.yml
vendored
@@ -165,7 +165,7 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: powdr-labs/openvm-reth-benchmark
|
||||
ref: main
|
||||
ref: ac2da7e4ea0287e9c6f9ef3e6b753b5c3e913e03
|
||||
path: openvm-reth-benchmark
|
||||
|
||||
- name: Patch openvm-reth-benchmark to use local powdr
|
||||
|
||||
2
.github/workflows/pr-tests.yml
vendored
2
.github/workflows/pr-tests.yml
vendored
@@ -167,7 +167,7 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: powdr-labs/openvm-reth-benchmark
|
||||
ref: main
|
||||
ref: ac2da7e4ea0287e9c6f9ef3e6b753b5c3e913e03
|
||||
path: openvm-reth-benchmark
|
||||
|
||||
- name: Patch openvm-reth-benchmark to use local powdr
|
||||
|
||||
54
Cargo.toml
54
Cargo.toml
@@ -83,38 +83,38 @@ powdr-autoprecompiles = { path = "./autoprecompiles", version = "0.1.4" }
|
||||
powdr-openvm = { path = "./openvm", version = "0.1.4" }
|
||||
|
||||
# openvm
|
||||
openvm = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-build = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-rv32im-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-rv32im-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-rv32im-guest = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba", default-features = false }
|
||||
openvm-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-circuit-derive = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-circuit-primitives = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-circuit-primitives-derive = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-instructions = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-instructions-derive = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-sdk = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba", default-features = false, features = [
|
||||
openvm = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-build = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-rv32im-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-rv32im-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-rv32im-guest = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737", default-features = false }
|
||||
openvm-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-circuit-derive = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-circuit-primitives = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-circuit-primitives-derive = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-instructions = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-instructions-derive = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-sdk = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737", default-features = false, features = [
|
||||
"parallel",
|
||||
"jemalloc",
|
||||
"nightly-features",
|
||||
"bench-metrics",
|
||||
] }
|
||||
openvm-ecc-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-ecc-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-keccak256-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-keccak256-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-sha256-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-sha256-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-algebra-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-algebra-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-bigint-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-bigint-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-pairing-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-pairing-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba" }
|
||||
openvm-native-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba", default-features = false }
|
||||
openvm-native-recursion = { git = "https://github.com/powdr-labs/openvm.git", rev = "acbd2ba", default-features = false }
|
||||
openvm-ecc-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-ecc-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-keccak256-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-keccak256-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-sha256-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-sha256-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-algebra-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-algebra-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-bigint-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-bigint-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-pairing-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-pairing-transpiler = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737" }
|
||||
openvm-native-circuit = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737", default-features = false }
|
||||
openvm-native-recursion = { git = "https://github.com/powdr-labs/openvm.git", rev = "391b737", default-features = false }
|
||||
|
||||
# stark-backend
|
||||
openvm-stark-sdk = { git = "https://github.com/powdr-labs/stark-backend.git", rev = "ee4e22b", default-features = false, features = [
|
||||
|
||||
@@ -224,18 +224,9 @@ pub fn customize(
|
||||
vm_config,
|
||||
);
|
||||
|
||||
let program = &mut exe.program.instructions_and_debug_infos;
|
||||
|
||||
let noop = OpenVmInstruction {
|
||||
opcode: VmOpcode::from_usize(0xdeadaf),
|
||||
a: BabyBear::ZERO,
|
||||
b: BabyBear::ZERO,
|
||||
c: BabyBear::ZERO,
|
||||
d: BabyBear::ZERO,
|
||||
e: BabyBear::ZERO,
|
||||
f: BabyBear::ZERO,
|
||||
g: BabyBear::ZERO,
|
||||
};
|
||||
let pc_base = exe.program.pc_base;
|
||||
let pc_step = exe.program.step;
|
||||
let program = &mut exe.program;
|
||||
|
||||
tracing::info!("Adjust the program with the autoprecompiles");
|
||||
|
||||
@@ -249,47 +240,13 @@ pub fn customize(
|
||||
subs,
|
||||
} = apc;
|
||||
let opcode = POWDR_OPCODE + i;
|
||||
// Create a new instruction that will be used to replace the original instructions in the block.
|
||||
// Note that this instruction is never actually looked up, because our APCs do not contain any
|
||||
// PC lookup (instead, they hardcode a PC in the execution bridge receive).
|
||||
// Replacing the instruction here has the effect that the prover is forced to use the APC.
|
||||
// We could also skip this to allow the prover to take either the software or APC path.
|
||||
// This does complicate witgen though, because which executor should be run is no longer deterministic.
|
||||
let new_instr = OpenVmInstruction {
|
||||
opcode: VmOpcode::from_usize(opcode),
|
||||
a: BabyBear::ZERO,
|
||||
b: BabyBear::ZERO,
|
||||
c: BabyBear::ZERO,
|
||||
d: BabyBear::ZERO,
|
||||
e: BabyBear::ZERO,
|
||||
f: BabyBear::ZERO,
|
||||
g: BabyBear::ZERO,
|
||||
};
|
||||
|
||||
let start_index = ((block.start_pc - exe.program.pc_base as u64)
|
||||
/ exe.program.step as u64)
|
||||
let start_index = ((block.start_pc - pc_base as u64) / pc_step as u64)
|
||||
.try_into()
|
||||
.unwrap();
|
||||
let n_acc = block.statements.len();
|
||||
let (acc, new_instrs): (Vec<_>, Vec<_>) = program[start_index..start_index + n_acc]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, x)| {
|
||||
let instr = x.as_ref().unwrap();
|
||||
let instr = instr.0.clone();
|
||||
if i == 0 {
|
||||
(instr, new_instr.clone())
|
||||
} else {
|
||||
(instr, noop.clone())
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let new_instrs = new_instrs.into_iter().map(|x| Some((x, None)));
|
||||
|
||||
let len_before = program.len();
|
||||
program.splice(start_index..start_index + n_acc, new_instrs);
|
||||
assert_eq!(program.len(), len_before);
|
||||
// We encode in the program that the prover should execute the apc instruction instead of the original software version.
|
||||
// This is only for witgen: the program in the program chip is left unchanged.
|
||||
program.add_apc_instruction_at_pc_index(start_index, VmOpcode::from_usize(opcode));
|
||||
|
||||
let is_valid_column = machine
|
||||
.main_columns()
|
||||
@@ -302,9 +259,11 @@ pub fn customize(
|
||||
class_offset: opcode,
|
||||
},
|
||||
machine,
|
||||
acc.into_iter()
|
||||
block
|
||||
.statements
|
||||
.into_iter()
|
||||
.zip_eq(subs)
|
||||
.map(|(instruction, subs)| OriginalInstruction::new(instruction, subs))
|
||||
.map(|(instruction, subs)| OriginalInstruction::new(instruction.0, subs))
|
||||
.collect(),
|
||||
is_valid_column,
|
||||
apc_stats,
|
||||
|
||||
@@ -85,10 +85,6 @@ impl<F: PrimeField32> PowdrChip<F> {
|
||||
}
|
||||
|
||||
impl<F: PrimeField32> InstructionExecutor<F> for PowdrChip<F> {
|
||||
fn receives_from_program_chip(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn execute(
|
||||
&mut self,
|
||||
memory: &mut MemoryController<F>,
|
||||
|
||||
@@ -90,10 +90,6 @@ impl<F: PrimeField32> PlonkChip<F> {
|
||||
}
|
||||
|
||||
impl<F: PrimeField32> InstructionExecutor<F> for PlonkChip<F> {
|
||||
fn receives_from_program_chip(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn execute(
|
||||
&mut self,
|
||||
memory: &mut MemoryController<F>,
|
||||
|
||||
Reference in New Issue
Block a user