Skip to content

Commit

Permalink
[bug fix] Fix missing return in id_leak_verifier (MystenLabs#6526)
Browse files Browse the repository at this point in the history
- Fixed missing return
- Added another test
  • Loading branch information
tnowacki authored Dec 2, 2022
1 parent d34c417 commit 1559d5e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
processed 1 task

task 0 'publish'. lines 4-25:
created: object(103)
written: object(102)
Error: Transaction Effects Status: Move Bytecode Verification Error. Please run the Bytecode Verifier for more information.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: UNKNOWN_VERIFICATION_ERROR, sub_status: None, message: Some("Sui Move Bytecode Verification Error: ID leaked through function call."), exec_state: None, location: Module(ModuleId { address: _, name: Identifier("m") }), indices: [], offsets: [] }) } }
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
processed 1 task
processed 2 tasks

task 0 'publish'. lines 4-25:
created: object(103)
written: object(102)
Error: Transaction Effects Status: Move Bytecode Verification Error. Please run the Bytecode Verifier for more information.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: UNKNOWN_VERIFICATION_ERROR, sub_status: None, message: Some("Sui Move Bytecode Verification Error: ID leaked through function call."), exec_state: None, location: Module(ModuleId { address: _, name: Identifier("m") }), indices: [], offsets: [] }) } }

task 1 'publish'. lines 27-48:
Error: Transaction Effects Status: Move Bytecode Verification Error. Please run the Bytecode Verifier for more information.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: UNKNOWN_VERIFICATION_ERROR, sub_status: None, message: Some("Sui Move Bytecode Verification Error: ID leaked through function call."), exec_state: None, location: Module(ModuleId { address: _, name: Identifier("m") }), indices: [], offsets: [] }) } }
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,26 @@ module 0x0.m {
}

}

//# publish
module 0x0.m {
import 0x2.object;

struct Foo has key {
id: object.UID,
}

transfer(id: object.UID) {
label l0:
abort 0;
}

foo(f: Self.Foo, v: &mut vector<object.UID>) {
let id: object.UID;
label l0:
Foo { id } = move(f);
Self.transfer(move(id));
return;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
processed 1 task

task 0 'publish'. lines 4-28:
Error: Transaction Effects Status: Move Bytecode Verification Error. Please run the Bytecode Verifier for more information.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: UNKNOWN_VERIFICATION_ERROR, sub_status: None, message: Some("Sui Move Bytecode Verification Error: ID leaked through function call."), exec_state: None, location: Module(ModuleId { address: _, name: Identifier("m") }), indices: [], offsets: [] }) } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# publish
module 0x0.m {
import 0x2.object;
import 0x2.tx_context;
import 0x2.transfer;

struct Cat has key {
id: object.UID,
}

struct Dog has key {
id: object.UID,
}

public entry transmute(cat: Self.Cat, ctx: &mut tx_context.TxContext) {
let cat_id: object.UID;
let dog: Self.Dog;
label l0:
Cat { id: cat_id } = move(cat);
dog = Dog { id: move(cat_id) };
transfer.transfer<Self.Dog>(move(dog), tx_context.sender(freeze(copy(ctx))));
return;
}

}
3 changes: 2 additions & 1 deletion crates/sui-verifier/src/id_leak_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn call(verifier: &mut IDLeakAnalysis, function_handle: &FunctionHandle) -> Part
.signature_at(function_handle.parameters);
for _ in 0..parameters.len() {
if verifier.stack.pop().unwrap() == AbstractValue::ID && !guaranteed_safe {
move_verification_error("ID leaked through function call.");
return Err(move_verification_error("ID leaked through function call."));
}
}

Expand Down Expand Up @@ -421,6 +421,7 @@ fn expect_ok<T>(res: Result<T, PartialVMError>) -> PartialVMResult<T> {
}
}

#[must_use]
fn move_verification_error(msg: impl std::fmt::Display) -> PartialVMError {
PartialVMError::new(StatusCode::UNKNOWN_VERIFICATION_ERROR)
.with_message(format!("Sui Move Bytecode Verification Error: {}", msg))
Expand Down

0 comments on commit 1559d5e

Please sign in to comment.