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

[Stress-06] Price Finalize Opcodes Based On Operand Types #2281

Merged
merged 22 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1c593a5
Implement size_in_bits for LiteralType
raychu86 Nov 28, 2023
fa25097
Finalize SET fees based on storage size
raychu86 Nov 28, 2023
5242e20
Add tests
d0cd Nov 28, 2023
15f8169
Rewrite expectations
raychu86 Nov 28, 2023
cc31f94
Merge branch 'feat/fee-based-on-size' of https://github.com/AleoHQ/sn…
raychu86 Nov 28, 2023
10e31d6
Merge branch 'testnet3' into feat/fee-based-on-size
iamalwaysuncomfortable Jan 5, 2024
0abc67b
Add alternate cost structure for finalize
iamalwaysuncomfortable Jan 5, 2024
57ce45a
Refine cost structure for finalize
iamalwaysuncomfortable Jan 8, 2024
44aa685
Add account for costs for Field & Scalar inputs for specific opcodes
iamalwaysuncomfortable Jan 8, 2024
c430173
Remove old branch artifacts
iamalwaysuncomfortable Jan 8, 2024
8969728
Update test expectations
iamalwaysuncomfortable Jan 10, 2024
53ab9f1
Fix size_in_bytes computation
howardwu Jan 21, 2024
40e29a7
Fix size_in_bytes_computation 2
howardwu Jan 21, 2024
e6b29ad
Merge branch 'testnet3' of https://github.com/AleoHQ/snarkVM into fea…
howardwu Jan 27, 2024
1c00b54
Resolve merge conflicts
howardwu Jan 27, 2024
cd54589
Fix merge conflict delta
howardwu Jan 27, 2024
9fbe463
Reduce to one stack lookup
howardwu Jan 27, 2024
e0b6e9c
Clippy
howardwu Jan 27, 2024
48ab38b
Improve cost safety, prevent overflows
howardwu Jan 27, 2024
4c87fd0
Clean up cost logic and error messages
howardwu Jan 27, 2024
e4646dd
Update cost on Inv and SignVerify
howardwu Jan 28, 2024
21c9ca1
Explicitly enumerate all match cases
howardwu Jan 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions console/program/src/data/literal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod parse;
mod sample;
mod serialize;
mod size_in_bits;
mod size_in_bytes;
mod to_bits;
mod to_type;
mod variant;
Expand Down
26 changes: 26 additions & 0 deletions console/program/src/data/literal/size_in_bytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the snarkVM library.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::*;

impl<N: Network> Literal<N> {
/// Returns the size in bytes of this literal.
#[allow(clippy::cast_possible_truncation)]
pub fn size_in_bytes(&self) -> u16 {
// Note: This upcast to u32 and downcast to u16 is safe because the size of a literal is
// always less than or equal to u16::MAX bits, and we are dividing by 8, so the result will
// always fit in a u16.
(((self.size_in_bits() as u32) + 7) / 8) as u16
}
}
4 changes: 4 additions & 0 deletions console/program/src/data_types/literal_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
mod bytes;
mod parse;
mod serialize;
mod size_in_bits;
mod size_in_bytes;

use snarkvm_console_account::Signature;
use snarkvm_console_network::prelude::*;
use snarkvm_console_types::{prelude::*, Boolean};

use core::fmt::{self, Debug, Display};
use num_derive::FromPrimitive;
Expand Down
43 changes: 43 additions & 0 deletions console/program/src/data_types/literal_type/size_in_bits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the snarkVM library.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::*;

impl LiteralType {
/// Returns the number of bits of this literal type.
///
/// For string literals, this method returns the maximum number of bits that can be stored in the string.
pub fn size_in_bits<N: Network>(&self) -> u16 {
let size = match self {
Self::Address => Address::<N>::size_in_bits(),
Self::Boolean => Boolean::<N>::size_in_bits(),
Self::Field => Field::<N>::size_in_bits(),
Self::Group => Group::<N>::size_in_bits(),
Self::I8 => I8::<N>::size_in_bits(),
Self::I16 => I16::<N>::size_in_bits(),
Self::I32 => I32::<N>::size_in_bits(),
Self::I64 => I64::<N>::size_in_bits(),
Self::I128 => I128::<N>::size_in_bits(),
Self::U8 => U8::<N>::size_in_bits(),
Self::U16 => U16::<N>::size_in_bits(),
Self::U32 => U32::<N>::size_in_bits(),
Self::U64 => U64::<N>::size_in_bits(),
Self::U128 => U128::<N>::size_in_bits(),
Self::Scalar => Scalar::<N>::size_in_bits(),
Self::Signature => Signature::<N>::size_in_bits(),
Self::String => N::MAX_STRING_BYTES.saturating_mul(8) as usize,
};
u16::try_from(size).or_halt_with::<N>("Literal exceeds u16::MAX bits.")
}
}
28 changes: 28 additions & 0 deletions console/program/src/data_types/literal_type/size_in_bytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the snarkVM library.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::*;

impl LiteralType {
/// Returns the number of bytes of this literal.
///
/// For string literals, this method returns the maximum number of bytes that can be stored in the string.
#[allow(clippy::cast_possible_truncation)]
pub fn size_in_bytes<N: Network>(&self) -> u16 {
// Note: This upcast to u32 and downcast to u16 is safe because the size of a literal is
// always less than or equal to u16::MAX bits, and we are dividing by 8, so the result will
// always fit in a u16.
(((self.size_in_bits::<N>() as u32) + 7) / 8) as u16
}
}
Binary file modified parameters/src/testnet3/resources/block.genesis
Binary file not shown.
2 changes: 1 addition & 1 deletion synthesizer/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl<N: Network, Instruction: InstructionTrait<N>, Command: CommandTrait<N>> Pro
/// Returns a reference to the function with the given name.
pub fn get_function_ref(&self, name: &Identifier<N>) -> Result<&FunctionCore<N, Instruction, Command>> {
// Attempt to retrieve the function.
let function = self.functions.get(name).ok_or_else(|| anyhow!("Function '{name}' is not defined."))?;
let function = self.functions.get(name).ok_or(anyhow!("Function '{}/{name}' is not defined.", self.id))?;
// Ensure the function name matches.
ensure!(function.name() == name, "Expected function '{name}', but found function '{}'", function.name());
// Ensure the number of inputs is within the allowed range.
Expand Down
Loading