This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 844
insufficient balance error circuit #919
Closed
DreamWuGit
wants to merge
7
commits into
privacy-scaling-explorations:main
from
scroll-tech:insufficient_balance
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c79622
draft insufficient balance error state
DreamWuGit a847163
implement root call constraint
DreamWuGit 2b9e378
remove restore context
DreamWuGit e48bf6a
merge to main
DreamWuGit dde23be
fix log
DreamWuGit efac131
Merge branch 'main' into insufficient_balance
DreamWuGit 5c82814
chores fix
DreamWuGit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use super::Opcode; | ||
use crate::{ | ||
circuit_input_builder::{CircuitInputStateRef, ExecStep}, | ||
operation::{AccountField, CallContextField}, | ||
Error, | ||
}; | ||
use eth_types::{GethExecStep, ToWord}; | ||
|
||
/// Placeholder structure used to implement [`Opcode`] trait over it | ||
/// corresponding to the `OpcodeId::CALL` `OpcodeId`. | ||
#[derive(Debug, Copy, Clone)] | ||
pub(crate) struct InsufficientBalance; | ||
|
||
impl Opcode for InsufficientBalance { | ||
fn gen_associated_ops( | ||
state: &mut CircuitInputStateRef, | ||
geth_steps: &[GethExecStep], | ||
) -> Result<Vec<ExecStep>, Error> { | ||
let geth_step = &geth_steps[0]; | ||
let mut exec_step = state.new_step(geth_step)?; | ||
let next_step = if geth_steps.len() > 1 { | ||
Some(&geth_steps[1]) | ||
} else { | ||
None | ||
}; | ||
exec_step.error = state.get_step_err(geth_step, next_step).unwrap(); | ||
|
||
let args_offset = geth_step.stack.nth_last(3)?.as_usize(); | ||
let args_length = geth_step.stack.nth_last(4)?.as_usize(); | ||
let ret_offset = geth_step.stack.nth_last(5)?.as_usize(); | ||
let ret_length = geth_step.stack.nth_last(6)?.as_usize(); | ||
|
||
state.call_expand_memory(args_offset, args_length, ret_offset, ret_length)?; | ||
|
||
let call = state.parse_call(geth_step).unwrap(); | ||
let current_call = state.call()?.clone(); | ||
|
||
for i in 0..7 { | ||
state.stack_read( | ||
&mut exec_step, | ||
geth_step.stack.nth_last_filled(i), | ||
geth_step.stack.nth_last(i)?, | ||
)?; | ||
} | ||
|
||
state.stack_write( | ||
&mut exec_step, | ||
geth_step.stack.nth_last_filled(6), | ||
(0u64).into(), // must fail | ||
)?; | ||
|
||
state.call_context_read( | ||
&mut exec_step, | ||
current_call.call_id, | ||
CallContextField::CalleeAddress, | ||
current_call.address.to_word(), | ||
); | ||
|
||
let (_, callee_account) = state.sdb.get_account(¤t_call.address); | ||
|
||
state.account_read( | ||
&mut exec_step, | ||
current_call.address, | ||
AccountField::Balance, | ||
callee_account.balance, | ||
callee_account.balance, | ||
)?; | ||
|
||
state.push_call(call); | ||
state.handle_return(geth_step)?; | ||
Ok(vec![exec_step]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure what is done whith this new variable. Which seems to be dropped immediately and does nothing and is not passed anywhere.
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.
@CPerezz trying to merge this error state into
CallOp
code as found many of code shares with it especially for gas cost related stuff. if it works, will update spec accordingly.