-
Notifications
You must be signed in to change notification settings - Fork 598
feat(avm/public): user space PublicContext::get_args_hash #8292
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -2,14 +2,15 @@ use dep::protocol_types::traits::Empty; | |
|
|
||
| // These inputs will likely go away once the AVM processes 1 public kernel per enqueued call. | ||
| struct PublicContextInputs { | ||
| args_hash: Field, | ||
| // TODO: Remove this structure and get calldata size at compile time. | ||
| calldata_length: Field, | ||
|
Comment on lines
+5
to
+6
Contributor
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 thought we were making calldata size a runtime variable?
Contributor
Author
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. Yes yes, the difference is a bit subtle. The opcode takes an address (so, a runtime variable)
Contributor
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. Okay, but I'm a bit confused. How can the size be known at compile time if it's a runtime variable?
Contributor
Author
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. It's not known at compile time now, that's why the current code is different from the expected code (in the description). |
||
| is_static_call: bool | ||
| } | ||
|
|
||
| impl Empty for PublicContextInputs { | ||
| fn empty() -> Self { | ||
| PublicContextInputs { | ||
| args_hash: 0, | ||
| calldata_length: 0, | ||
| is_static_call: false | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,16 @@ use dep::protocol_types::traits::{Serialize, Deserialize, Empty}; | |
| use dep::protocol_types::abis::function_selector::FunctionSelector; | ||
| use crate::context::inputs::public_context_inputs::PublicContextInputs; | ||
| use crate::context::gas::GasOpts; | ||
| use crate::hash::ArgsHasher; | ||
|
|
||
| struct PublicContext { | ||
| inputs: PublicContextInputs, | ||
| args_hash: Option<Field> | ||
| } | ||
|
|
||
| impl PublicContext { | ||
| pub fn new(inputs: PublicContextInputs) -> Self { | ||
| PublicContext { inputs } | ||
| PublicContext { inputs, args_hash: Option::none() } | ||
| } | ||
|
|
||
| pub fn emit_unencrypted_log<T, let N: u32>(_self: &mut Self, log: T) where T: Serialize<N> { | ||
|
|
@@ -130,8 +132,20 @@ impl PublicContext { | |
| fn selector(_self: Self) -> FunctionSelector { | ||
| FunctionSelector::from_u32(function_selector()) | ||
| } | ||
| fn get_args_hash(self) -> Field { | ||
| self.inputs.args_hash | ||
| fn get_args_hash(mut self) -> Field { | ||
| if !self.args_hash.is_some() { | ||
| let mut hasher = ArgsHasher::new(); | ||
|
|
||
| // TODO: this should be replaced with the compile-time calldata size. | ||
|
Contributor
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 question about compile-time vs runtime |
||
| for i in 0..self.inputs.calldata_length as u32 { | ||
| let argn: [Field; 1] = calldata_copy((2 + i) as u32, 1); | ||
| hasher.add(argn[0]); | ||
| } | ||
|
|
||
| self.args_hash = Option::some(hasher.hash()); | ||
| } | ||
|
|
||
| self.args_hash.unwrap() | ||
| } | ||
| fn transaction_fee(_self: Self) -> Field { | ||
| transaction_fee() | ||
|
|
@@ -278,6 +292,10 @@ unconstrained fn call_static<let RET_SIZE: u32>( | |
| call_static_opcode(gas, address, args, function_selector) | ||
| } | ||
|
|
||
| unconstrained fn calldata_copy<let N: u32>(cdoffset: u32, copy_size: u32) -> [Field; N] { | ||
| calldata_copy_opcode(cdoffset, copy_size) | ||
| } | ||
|
|
||
| unconstrained fn storage_read(storage_slot: Field) -> Field { | ||
| storage_read_opcode(storage_slot) | ||
| } | ||
|
|
@@ -356,6 +374,9 @@ unconstrained fn l1_to_l2_msg_exists_opcode(msg_hash: Field, msg_leaf_index: Fie | |
| #[oracle(avmOpcodeSendL2ToL1Msg)] | ||
| unconstrained fn send_l2_to_l1_msg_opcode(recipient: EthAddress, content: Field) {} | ||
|
|
||
| #[oracle(avmOpcodeCalldataCopy)] | ||
| unconstrained fn calldata_copy_opcode<let N: u32>(cdoffset: u32, copy_size: u32) -> [Field; N] {} | ||
|
|
||
|
Comment on lines
+377
to
+379
Contributor
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. Why do we need this oracle now, but didn't need it before? There is no longer just a simple 1-1 mapping between the calldatacopy brillig opcode and the avm opcode? |
||
| #[oracle(avmOpcodeCall)] | ||
| unconstrained fn call_opcode<let RET_SIZE: u32>( | ||
| gas: [Field; 2], // gas allocation: [l2_gas, da_gas] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.