-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2281 from AleoHQ/feat/fee-based-on-operand-size
Price Finalize Opcodes Based On Operand Types
- Loading branch information
Showing
19 changed files
with
418 additions
and
144 deletions.
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,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 | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
console/program/src/data_types/literal_type/size_in_bits.rs
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,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
28
console/program/src/data_types/literal_type/size_in_bytes.rs
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,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 not shown.
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.