-
Notifications
You must be signed in to change notification settings - Fork 18
add permissioned signer module and update existing modules to use dot… #211
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
Open
sh-cha
wants to merge
2
commits into
main
Choose a base branch
from
feat/permissioned-signer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+7,075
−813
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,74 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Copyright (c) The Diem Core Contributors | ||
// Copyright (c) The Move Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! Implementation of native functions for value comparison. | ||
|
||
use crate::interface::{ | ||
RawSafeNative, SafeNativeBuilder, SafeNativeContext, SafeNativeError, SafeNativeResult, | ||
}; | ||
use move_core_types::vm_status::StatusCode; | ||
use move_vm_runtime::native_functions::NativeFunction; | ||
use move_vm_types::{ | ||
loaded_data::runtime_types::Type, | ||
natives::function::PartialVMError, | ||
values::{Struct, Value}, | ||
}; | ||
use smallvec::{smallvec, SmallVec}; | ||
use std::collections::VecDeque; | ||
|
||
const ORDERING_LESS_THAN_VARIANT: u16 = 0; | ||
const ORDERING_EQUAL_VARIANT: u16 = 1; | ||
const ORDERING_GREATER_THAN_VARIANT: u16 = 2; | ||
|
||
/*************************************************************************************************** | ||
* native fun native_compare | ||
* | ||
* gas cost: CMP_COMPARE_BASE + CMP_COMPARE_PER_ABS_VAL_UNIT * dereferenced_size_of_both_values | ||
* | ||
**************************************************************************************************/ | ||
fn native_compare( | ||
context: &mut SafeNativeContext, | ||
_ty_args: Vec<Type>, | ||
args: VecDeque<Value>, | ||
) -> SafeNativeResult<SmallVec<[Value; 1]>> { | ||
debug_assert!(args.len() == 2); | ||
let gas_params = &context.native_gas_params.move_stdlib; | ||
|
||
if args.len() != 2 { | ||
return Err(SafeNativeError::InvariantViolation(PartialVMError::new( | ||
StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR, | ||
))); | ||
} | ||
|
||
let cost = gas_params.cmp_compare_base | ||
+ gas_params.cmp_compare_per_abs_val_unit | ||
* (context.abs_val_size_dereferenced(&args[0]) | ||
+ context.abs_val_size_dereferenced(&args[1])); | ||
context.charge(cost)?; | ||
|
||
let ordering = args[0].compare(&args[1])?; | ||
let ordering_move_variant = match ordering { | ||
std::cmp::Ordering::Less => ORDERING_LESS_THAN_VARIANT, | ||
std::cmp::Ordering::Equal => ORDERING_EQUAL_VARIANT, | ||
std::cmp::Ordering::Greater => ORDERING_GREATER_THAN_VARIANT, | ||
}; | ||
|
||
Ok(smallvec![Value::struct_(Struct::pack(vec![Value::u16( | ||
ordering_move_variant | ||
)]))]) | ||
} | ||
|
||
/*************************************************************************************************** | ||
* module | ||
**************************************************************************************************/ | ||
pub fn make_all( | ||
builder: &SafeNativeBuilder, | ||
) -> impl Iterator<Item = (String, NativeFunction)> + '_ { | ||
let natives = [("compare", native_compare as RawSafeNative)]; | ||
|
||
builder.make_named_natives(natives) | ||
} |
This file contains hidden or 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,53 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! Implementation of native functions for memory manipulation. | ||
|
||
use crate::{interface::{ | ||
RawSafeNative, SafeNativeBuilder, SafeNativeContext, | ||
SafeNativeResult, | ||
}, safely_pop_arg}; | ||
use move_vm_runtime::native_functions::NativeFunction; | ||
use move_vm_types::{ | ||
loaded_data::runtime_types::Type, | ||
values::{Reference, Value}, | ||
}; | ||
use smallvec::{smallvec, SmallVec}; | ||
use std::collections::VecDeque; | ||
|
||
|
||
/*************************************************************************************************** | ||
* native fun native_swap | ||
* | ||
* gas cost: MEM_SWAP_BASE | ||
* | ||
**************************************************************************************************/ | ||
fn native_swap( | ||
context: &mut SafeNativeContext, | ||
_ty_args: Vec<Type>, | ||
mut args: VecDeque<Value>, | ||
) -> SafeNativeResult<SmallVec<[Value; 1]>> { | ||
let gas_params = &context.native_gas_params.move_stdlib; | ||
|
||
debug_assert!(args.len() == 2); | ||
|
||
context.charge(gas_params.mem_swap_base)?; | ||
|
||
let left = safely_pop_arg!(args, Reference); | ||
let right = safely_pop_arg!(args, Reference); | ||
|
||
left.swap_values(right)?; | ||
|
||
Ok(smallvec![]) | ||
} | ||
|
||
/*************************************************************************************************** | ||
* module | ||
**************************************************************************************************/ | ||
pub fn make_all( | ||
builder: &SafeNativeBuilder, | ||
) -> impl Iterator<Item = (String, NativeFunction)> + '_ { | ||
let natives = [("swap", native_swap as RawSafeNative)]; | ||
|
||
builder.make_named_natives(natives) | ||
} |
Oops, something went wrong.
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.
& references are off by one level – will not compile
VecDeque::index
returns&Value
.Passing
&args[0]
therefore yields&&Value
. The same applies to&args[1]
.Without this fix the crate will fail to compile with a “mismatched types: expected
&Value
, found&&Value
” error.📝 Committable suggestion
🤖 Prompt for AI Agents