-
Notifications
You must be signed in to change notification settings - Fork 308
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
feat(avm-mini): call and return opcodes #3704
Changes from all commits
d3b3ccd
77a5425
17057c8
abf939d
33984c9
64b5f10
cfe5b71
97480e1
75c772d
a607e9a
b392b2e
4e54074
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,18 @@ namespace avmMini(256); | |
pol constant clk(i) { i }; | ||
pol constant first = [1] + [0]*; // Used mostly to toggle off the first row consisting | ||
// only in first element of shifted polynomials. | ||
|
||
//===== CONTROL FLOW ========================================================== | ||
// Program counter | ||
pol commit pc; | ||
// Return Pointer | ||
pol commit internal_return_ptr; | ||
|
||
pol commit sel_internal_call; | ||
pol commit sel_internal_return; | ||
|
||
// Halt program execution | ||
pol commit sel_halt; | ||
|
||
//===== TABLE SUBOP-TR ======================================================== | ||
// Boolean selectors for (sub-)operations. Only one operation is activated at | ||
|
@@ -66,6 +78,10 @@ namespace avmMini(256); | |
sel_op_mul * (1 - sel_op_mul) = 0; | ||
sel_op_div * (1 - sel_op_div) = 0; | ||
|
||
sel_internal_call * (1 - sel_internal_call) = 0; | ||
sel_internal_return * (1 - sel_internal_return) = 0; | ||
sel_halt * (1 - sel_halt) = 0; | ||
|
||
op_err * (1 - op_err) = 0; | ||
tag_err * (1 - tag_err) = 0; // Potential optimization (boolean constraint derivation from equivalence check to memTrace)? | ||
|
||
|
@@ -131,8 +147,47 @@ namespace avmMini(256); | |
// This works in combination with op_div_err * (sel_op_div - 1) = 0; | ||
// Drawback is the need to paralllelize the latter. | ||
|
||
|
||
//===== CALL_RETURN ======================================================== | ||
// The program counter in the next row should be equal to the value loaded from the ia register | ||
// This implies that a load from memory must occur at the same time | ||
// Imply that we must load the return location into mem_idx_a | ||
|
||
#[RETURN_POINTER_INCREMENT] | ||
sel_internal_call * ( internal_return_ptr' - ( internal_return_ptr + 1)) = 0; | ||
sel_internal_call * ( internal_return_ptr - mem_idx_a) = 0; | ||
sel_internal_call * ((pc + 1) - ia) = 0; | ||
|
||
// TODO(md): Below relations may be removed through sub-op table lookup | ||
sel_internal_call * (rwa - 1) = 0; | ||
sel_internal_call * (mem_op_a - 1) = 0; | ||
|
||
// We must load the memory pointer to be the internal_return_ptr | ||
#[RETURN_POINTER_DECREMENT] | ||
sel_internal_return * ( internal_return_ptr' - ( internal_return_ptr - 1)) = 0; | ||
sel_internal_return * ( (internal_return_ptr - 1) - mem_idx_a) = 0; | ||
sel_internal_return * (pc' - ia) = 0; | ||
|
||
// TODO(md): Below relations may be removed through sub-op table lookup | ||
sel_internal_return * rwa = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark as above related to the OP-SUBOP table. |
||
sel_internal_return * (mem_op_a - 1) = 0; | ||
|
||
//===== CONTROL_FLOW_CONSISTENCY ============================================ | ||
pol CONTROL_FLOW_SELECTORS = (first + sel_internal_call + sel_internal_return + sel_halt); | ||
pol OPCODE_SELECTORS = (sel_op_add + sel_op_sub + sel_op_div + sel_op_mul); | ||
|
||
// Program counter must increment if not jumping or returning | ||
#[PC_INCREMENT] | ||
(1 - first) * (1 - sel_halt) * OPCODE_SELECTORS * (pc' - (pc + 1)) = 0; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Maddiaa0 Should not we have a constraint on internal_return_ptr value staying constant for all other operations? Otherwise, we could change maliciously the index between to internal_return/call, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #3704 (comment) yes! I wondered this. I shall implement it |
||
// first == 0 && sel_internal_call == 0 && sel_internal_return == 0 && sel_halt == 0 ==> internal_return_ptr == internal_return_ptr' | ||
#[INTERNAL_RETURN_POINTER_CONSISTENCY] | ||
(1 - CONTROL_FLOW_SELECTORS) * (internal_return_ptr' - internal_return_ptr) = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest a comment line on top of the relation with this: |
||
|
||
// TODO: we want to set an initial number for the reserved memory of the jump pointer | ||
|
||
// Inter-table Constraints | ||
|
||
// TODO: tag_err {clk} IS memTrace.m_tag_err {memTrace.m_clk} | ||
// TODO: Map memory trace with intermediate register values whenever there is no tag error, sthg like: | ||
// mem_op_a * (1 - tag_err) {mem_idx_a, clk, ia, rwa} IS m_sub_clk == 0 && 1 - m_tag_err {m_addr, m_clk, m_val, m_rw} | ||
// mem_op_a * (1 - tag_err) {mem_idx_a, clk, ia, rwa} IS m_sub_clk == 0 && 1 - m_tag_err {m_addr, m_clk, m_val, m_rw} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do i need to assert the internal call counter does not change between calls?
resolved