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

refactor/ remove MOCK_PROGRAM in MockProver #395

Merged
merged 18 commits into from
Oct 18, 2024
Merged

Conversation

KimiWu123
Copy link
Contributor

@KimiWu123 KimiWu123 commented Oct 15, 2024

This PR is trying to remove MOCK_PROGRAM and MOCK_PC_XXX in MockProver, related to part of #331.

The idea is to

  1. move load_program_table out from load_table so that we can pass any opcodes we would like to test, and
  2. leverage existing DecodedInstruction::from_raw() to reassemble the opcode format for MockProver.

@@ -167,6 +192,39 @@ impl StepRecord {
}
}

fn new_insn2(
Copy link
Contributor Author

@KimiWu123 KimiWu123 Oct 15, 2024

Choose a reason for hiding this comment

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

Tried not to touch existing code so having this function and have a quick PoC. Will modify new_insn if this approach works. The same as above new_r_instruction2

rd: Option<Change<Word>>,
previous_cycle: Cycle,
) -> StepRecord {
let insn = DecodedInstruction::from_raw(insn_kind, MOCK_RS1, MOCK_RS2, MOCK_RD);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This from_raw method does not look right. It cannot be that simple to support all the instruction formats.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead, I would write "encode" functions for each type that return insn_code: u32, and then pass this to (like StepRecord::new_r_instruction). This way the test data go through the same decoder as production code.

Self::run_maybe_challenge(cb, wits_in, &[], &[], None)
}

pub fn run_with_program(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes that’s nice.

@@ -52,6 +52,10 @@ impl<T> MemOp<T> {
pub type ReadOp = MemOp<Word>;
pub type WriteOp = MemOp<Change<Word>>;

const MOCK_RS1: u32 = 2;
const MOCK_RS2: u32 = 3;
const MOCK_RD: u32 = 4;
Copy link
Collaborator

Choose a reason for hiding this comment

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

That kind of test data belongs more closely to the MockProver module or test utils of ceno_zkvm.

ceno_emul/src/tracer.rs Show resolved Hide resolved
@@ -85,13 +87,14 @@ fn test_opcode_or() {
.unwrap()
.unwrap();

let insn_code = EncodedInstruction::encode(InsnKind::OR, 2, 3, 4, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@@ -207,6 +207,81 @@ pub struct InsnCodes {
pub func7: u32,
}

pub struct EncodedInstruction;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be a module rather than a type.

@@ -207,6 +207,81 @@ pub struct InsnCodes {
pub func7: u32,
}

pub struct EncodedInstruction;
impl EncodedInstruction {
pub fn encode(kind: InsnKind, rs1: u32, rs2: u32, rd: u32, imm: u32) -> u32 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@KimiWu123 KimiWu123 force-pushed the refactor/mock_program branch from 948b163 to eff9abf Compare October 17, 2024 03:21
@KimiWu123 KimiWu123 force-pushed the refactor/mock_program branch from eff9abf to ffaece6 Compare October 17, 2024 07:25
@KimiWu123 KimiWu123 changed the title [WIP] refactor/ remove MOCK_PROGRAM in MockProver refactor/ remove MOCK_PROGRAM in MockProver Oct 17, 2024
@KimiWu123 KimiWu123 marked this pull request as ready for review October 17, 2024 09:24
@KimiWu123
Copy link
Contributor Author

@naure, do you mind reviewing this PR again? It's the final version now.

Copy link
Collaborator

@naure naure left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@KimiWu123 KimiWu123 enabled auto-merge (squash) October 18, 2024 01:37
@KimiWu123 KimiWu123 merged commit 4cbc891 into master Oct 18, 2024
6 checks passed
@KimiWu123 KimiWu123 deleted the refactor/mock_program branch October 18, 2024 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants