Skip to content

Commit

Permalink
Fix inconsistent sui system state object id (MystenLabs#2845)
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind authored Jun 30, 2022
1 parent 7fa4731 commit 63ce032
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/sui-adapter/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use sui_types::{
messages::{CallArg, InputObjectKind, ObjectArg},
object::{self, Data, MoveObject, Object, Owner},
storage::{DeleteKind, Storage},
SUI_SYSTEM_STATE_OBJECT_ID,
};
use sui_verifier::{
entry_points_verifier::{is_tx_context, INIT_FN_NAME, RESOLVED_STD_OPTION, RESOLVED_SUI_ID},
Expand Down Expand Up @@ -431,6 +432,10 @@ fn process_successful_execution<
}
let tx_digest = ctx.digest();
// newly_generated_ids contains all object IDs generated in this transaction.
// TODO: In the case of the special system transaction that creates the system state object,
// there is one extra object created with ID hardcoded at 0x5, and it won't be included in
// `newly_generated_ids`. To cope with this, we special check the ID inside `handle_transfer`.
// It's a bit hacky. Ideally, we want `newly_generated_ids` to include it. But it's unclear how.
let newly_generated_ids = ctx.recreate_all_ids();
state_view.set_create_object_ids(newly_generated_ids.clone());
// process events to identify transfers, freezes
Expand Down Expand Up @@ -598,7 +603,7 @@ fn handle_transfer<
// The following condition checks if this object was unwrapped in this transaction.
if old_object.is_none() {
// Newly created object
if newly_generated_ids.contains(&obj_id) {
if newly_generated_ids.contains(&obj_id) || obj_id == SUI_SYSTEM_STATE_OBJECT_ID {
state_view.log_event(Event::new_object(
module_id.address(),
module_id.name(),
Expand Down
1 change: 1 addition & 0 deletions crates/sui-core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,7 @@ async fn test_genesis_sui_sysmtem_state_object() {
.await
.unwrap()
.unwrap();
assert_eq!(sui_system_object.version(), SequenceNumber::from(1));
let move_object = sui_system_object.data.try_as_move().unwrap();
let _sui_system_state = bcs::from_bytes::<SuiSystemState>(move_object.contents()).unwrap();
assert_eq!(move_object.type_, SuiSystemState::type_());
Expand Down

0 comments on commit 63ce032

Please sign in to comment.