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

Use ObjectID over AccountAddress #468

Merged
merged 9 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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: 0 additions & 1 deletion sui_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use move_bytecode_utils::module_cache::ModuleCache;
use move_core_types::{
account_address::AccountAddress,
language_storage::{ModuleId, StructTag},
resolver::{ModuleResolver, ResourceResolver},
};
Expand Down
2 changes: 1 addition & 1 deletion sui_core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl ModuleResolver for AuthorityStore {
type Error = SuiError;

fn get_module(&self, module_id: &ModuleId) -> Result<Option<Vec<u8>>, Self::Error> {
match self.get_object(module_id.address())? {
match self.get_object(&ObjectID::from(*module_id.address()))? {
Some(o) => match &o.data {
Data::Package(c) => Ok(c
.get(module_id.name().as_str())
Expand Down
8 changes: 4 additions & 4 deletions sui_core/src/authority/temporary_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl Storage for AuthorityTemporaryStore {
impl ModuleResolver for AuthorityTemporaryStore {
type Error = SuiError;
fn get_module(&self, module_id: &ModuleId) -> Result<Option<Vec<u8>>, Self::Error> {
match self.read_object(module_id.address()) {
match self.read_object(&ObjectID::from(*module_id.address())) {
Some(o) => match &o.data {
Data::Package(c) => Ok(c
.get(module_id.name().as_str())
Expand All @@ -283,12 +283,12 @@ impl ResourceResolver for AuthorityTemporaryStore {

fn get_resource(
&self,
address: &AccountAddress,
id: &move_core_types::account_address::AccountAddress,
struct_tag: &StructTag,
) -> Result<Option<Vec<u8>>, Self::Error> {
let object = match self.read_object(address) {
let object = match self.read_object(&ObjectID::from(*id)) {
Some(x) => x,
None => match self.read_object(address) {
None => match self.read_object(&ObjectID::from(*id)) {
None => return Ok(None),
Some(x) => {
if !x.is_read_only() {
Expand Down
6 changes: 3 additions & 3 deletions sui_core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,9 @@ async fn test_publish_non_existing_dependent_module() {
// create a module that depends on a genesis module
let mut dependent_module = make_dependent_module(&genesis_module);
// Add another dependent module that points to a random address, hence does not exist on-chain.
dependent_module
.address_identifiers
.push(AccountAddress::random());
dependent_module.address_identifiers.push(
move_core_types::account_address::AccountAddress::from(ObjectID::random()),
);
dependent_module.module_handles.push(ModuleHandle {
address: AddressIdentifierIndex((dependent_module.address_identifiers.len() - 1) as u16),
name: IdentifierIndex(0),
Expand Down
5 changes: 2 additions & 3 deletions sui_core/src/unit_tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use sui_types::object::{Data, Object, GAS_VALUE_FOR_TESTING, OBJECT_START_VERSIO
use tokio::runtime::Runtime;
use typed_store::Map;

use move_core_types::account_address::AccountAddress;
use std::env;
use std::fs;
use sui_types::error::SuiError::ObjectNotFound;
Expand Down Expand Up @@ -369,7 +368,7 @@ async fn fund_account_with_same_objects(
authorities: Vec<&LocalAuthorityClient>,
client: &mut ClientState<LocalAuthorityClient>,
object_ids: Vec<ObjectID>,
) -> HashMap<AccountAddress, Object> {
) -> HashMap<ObjectID, Object> {
let objs: Vec<_> = (0..authorities.len()).map(|_| object_ids.clone()).collect();
fund_account(authorities, client, objs).await
}
Expand All @@ -379,7 +378,7 @@ async fn fund_account(
authorities: Vec<&LocalAuthorityClient>,
client: &mut ClientState<LocalAuthorityClient>,
object_ids: Vec<Vec<ObjectID>>,
) -> HashMap<AccountAddress, Object> {
) -> HashMap<ObjectID, Object> {
let mut created_objects = HashMap::new();
for (authority, object_ids) in authorities.into_iter().zip(object_ids.into_iter()) {
for object_id in object_ids {
Expand Down
21 changes: 15 additions & 6 deletions sui_programmability/adapter/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use sui_verifier::verifier;

use move_cli::sandbox::utils::get_gas_status;
use move_core_types::{
account_address::AccountAddress,
ident_str,
identifier::{IdentStr, Identifier},
language_storage::{ModuleId, StructTag, TypeTag},
Expand Down Expand Up @@ -148,7 +147,7 @@ fn execute_internal<
type_args: Vec<TypeTag>,
args: Vec<Vec<u8>>,
mutable_ref_objects: Vec<Object>,
by_value_objects: BTreeMap<AccountAddress, Object>,
by_value_objects: BTreeMap<ObjectID, Object>,
object_owner_map: HashMap<SuiAddress, SuiAddress>,
gas_budget: u64, // gas budget for the current call operation
ctx: &mut TxContext,
Expand Down Expand Up @@ -400,7 +399,11 @@ pub fn verify_and_link<
})
.collect();
session
.publish_module_bundle(new_module_bytes, package_id, &mut gas_status)
.publish_module_bundle(
new_module_bytes,
move_core_types::account_address::AccountAddress::from(package_id),
&mut gas_status,
)
.map_err(|e| SuiError::ModulePublishFailure {
error: e.to_string(),
})?;
Expand Down Expand Up @@ -428,12 +431,15 @@ pub fn generate_package_id(
for module in modules.iter() {
let old_module_id = module.self_id();
let old_address = *old_module_id.address();
if old_address != AccountAddress::ZERO {
if old_address != move_core_types::account_address::AccountAddress::from(ObjectID::ZERO) {
return Err(SuiError::ModulePublishFailure {
error: "Publishing modules with non-zero address is not allowed".to_string(),
});
}
let new_module_id = ModuleId::new(package_id, old_module_id.name().to_owned());
let new_module_id = ModuleId::new(
move_core_types::account_address::AccountAddress::from(package_id),
old_module_id.name().to_owned(),
);
if sub_map.insert(old_module_id, new_module_id).is_some() {
return Err(SuiError::ModulePublishFailure {
error: "Publishing two modules with the same ID".to_string(),
Expand Down Expand Up @@ -801,7 +807,10 @@ fn is_param_tx_context(param: &Type) -> bool {
module,
name,
type_arguments,
} if address == &SUI_FRAMEWORK_ADDRESS
} if address
== &move_core_types::account_address::AccountAddress::from(
SUI_FRAMEWORK_ADDRESS,
)
&& module.as_ident_str() == TX_CONTEXT_MODULE_NAME
&& name.as_ident_str() == TX_CONTEXT_STRUCT_NAME
&& type_arguments.is_empty() =>
Expand Down
6 changes: 4 additions & 2 deletions sui_programmability/adapter/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ pub fn clone_genesis_data() -> (Vec<Object>, NativeFunctionTable) {
fn create_genesis_module_objects() -> Genesis {
let sui_modules = sui_framework::get_sui_framework_modules();
let std_modules = sui_framework::get_move_stdlib_modules();
let native_functions =
sui_framework::natives::all_natives(MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS);
let native_functions = sui_framework::natives::all_natives(
move_core_types::account_address::AccountAddress::from(MOVE_STDLIB_ADDRESS),
move_core_types::account_address::AccountAddress::from(SUI_FRAMEWORK_ADDRESS),
);
let owner = SuiAddress::default();
let objects = vec![
Object::new_package(sui_modules, owner, TransactionDigest::genesis()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl ModuleResolver for InMemoryStorage {
type Error = ();
fn get_module(&self, module_id: &ModuleId) -> Result<Option<Vec<u8>>, Self::Error> {
Ok(self
.read_object(module_id.address())
.read_object(&ObjectID::from(*module_id.address()))
.map(|o| match &o.data {
Data::Package(m) => m[module_id.name().as_str()].clone().into_vec(),
Data::Move(_) => panic!("Type error"),
Expand Down
5 changes: 4 additions & 1 deletion sui_programmability/framework/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ pub fn run_move_unit_tests(path: &Path) -> SuiResult {
path,
BuildConfig::default(),
UnitTestingConfig::default_with_bound(Some(MAX_UNIT_TEST_INSTRUCTIONS)),
natives::all_natives(MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS),
natives::all_natives(
move_core_types::account_address::AccountAddress::from(MOVE_STDLIB_ADDRESS),
move_core_types::account_address::AccountAddress::from(SUI_FRAMEWORK_ADDRESS),
),
/* compute_coverage */ false,
)
.map_err(|err| SuiError::MoveUnitTestFailure {
Expand Down
4 changes: 3 additions & 1 deletion sui_programmability/framework/src/natives/tx_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ pub fn fresh_id(
// TODO(https://github.com/MystenLabs/fastnft/issues/58): finalize digest format
// unwrap safe because all digests in Move are serialized from the Rust `TransactionDigest`
let digest = TransactionDigest::try_from(inputs_hash.as_slice()).unwrap();
let id = Value::address(digest.derive_id(ids_created));
let id = Value::address(move_core_types::account_address::AccountAddress::from(
digest.derive_id(ids_created),
));

// TODO: choose cost
let cost = native_gas(context.cost_table(), NativeCostIndex::CREATE_SIGNER, 0);
Expand Down
3 changes: 2 additions & 1 deletion sui_programmability/verifier/src/id_leak_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ fn is_call_safe_to_leak(verifier: &IDLeakAnalysis, function_handle: &FunctionHan
let m = verifier
.binary_view
.module_handle_at(function_handle.module);
verifier.binary_view.address_identifier_at(m.address) == &SUI_FRAMEWORK_ADDRESS
verifier.binary_view.address_identifier_at(m.address)
== &move_core_types::account_address::AccountAddress::from(SUI_FRAMEWORK_ADDRESS)
&& verifier.binary_view.identifier_at(m.name).as_str() == "ID"
&& verifier
.binary_view
Expand Down
5 changes: 4 additions & 1 deletion sui_programmability/verifier/src/struct_with_key_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ fn verify_key_structs(module: &CompiledModule) -> SuiResult {
let id_type_module_name = module.identifier_at(id_type_module.name).to_string();
fp_ensure!(
id_type_struct_name == "ID"
&& id_type_module_address == &SUI_FRAMEWORK_ADDRESS
&& id_type_module_address
== &move_core_types::account_address::AccountAddress::from(
SUI_FRAMEWORK_ADDRESS
)
&& id_type_module_name == "ID",
verification_failure(format!(
"First field of struct {} must be of type {}::ID::ID, {}::{}::{} type found",
Expand Down
5 changes: 4 additions & 1 deletion sui_programmability/verifier/tests/common/module_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ impl ModuleBuilder {
/// Creates the "ID" module in framework address, along with the "ID" struct.
/// Both the module and the ID struct information are returned.
pub fn default() -> (Self, StructInfo) {
let mut module = Self::new(SUI_FRAMEWORK_ADDRESS, "ID");
let mut module = Self::new(
move_core_types::account_address::AccountAddress::from(SUI_FRAMEWORK_ADDRESS),
"ID",
);
let id = module.add_struct(
module.get_self_index(),
"ID",
Expand Down
Loading