Skip to content

Commit 82b1db0

Browse files
committed
[vm] New bytecode for aborting with message
1 parent 57a3903 commit 82b1db0

File tree

37 files changed

+223
-16
lines changed

37 files changed

+223
-16
lines changed

aptos-move/aptos-gas-meter/src/meter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ where
132132
Nop => NOP,
133133

134134
Abort => ABORT,
135+
AbortMsg => ABORT_MSG,
135136
Ret => RET,
136137

137138
LdU8 => LD_U8,

aptos-move/aptos-gas-schedule/src/gas_schedule/instr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ crate::gas_schedule::macros::define_gas_parameters!(
2222
// control flow
2323
[ret: InternalGas, "ret", 220],
2424
[abort: InternalGas, "abort", 220],
25+
[abort_msg: InternalGas, "abort_ msg", 220],
2526

2627
// Note(Gas): The costs of the branch instructions have been jacked up a bit intentionally
2728
// to prevent any single transaction from running for too long.

aptos-move/aptos-release-builder/src/components/feature_flags.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub enum FeatureFlag {
157157
EnableFrameworkForOption,
158158
SessionContinuation,
159159
EnableFunctionReflection,
160+
VMBinaryFormatV10,
160161
}
161162

162163
fn generate_features_blob(writer: &CodeWriter, data: &[u64]) {
@@ -413,6 +414,7 @@ impl From<FeatureFlag> for AptosFeatureFlag {
413414
FeatureFlag::EnableFrameworkForOption => AptosFeatureFlag::ENABLE_FRAMEWORK_FOR_OPTION,
414415
FeatureFlag::SessionContinuation => AptosFeatureFlag::SESSION_CONTINUATION,
415416
FeatureFlag::EnableFunctionReflection => AptosFeatureFlag::ENABLE_FUNCTION_REFLECTION,
417+
FeatureFlag::VMBinaryFormatV10 => AptosFeatureFlag::VM_BINARY_FORMAT_V10,
416418
}
417419
}
418420
}
@@ -596,6 +598,7 @@ impl From<AptosFeatureFlag> for FeatureFlag {
596598
AptosFeatureFlag::ENABLE_FRAMEWORK_FOR_OPTION => FeatureFlag::EnableFrameworkForOption,
597599
AptosFeatureFlag::SESSION_CONTINUATION => FeatureFlag::SessionContinuation,
598600
AptosFeatureFlag::ENABLE_FUNCTION_REFLECTION => FeatureFlag::EnableFunctionReflection,
601+
AptosFeatureFlag::VM_BINARY_FORMAT_V10 => FeatureFlag::VMBinaryFormatV10,
599602
}
600603
}
601604
}

aptos-move/aptos-vm/src/verifier/event_validation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ pub(crate) fn validate_emit_calls(
235235
| Le
236236
| Ge
237237
| Abort
238+
| AbortMsg
238239
| Nop
239240
| ImmBorrowVariantField(_)
240241
| ImmBorrowVariantFieldGeneric(_)

third_party/move/move-binary-format/src/check_bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ impl<'a> BoundsChecker<'a> {
673673
| LdI8(_) | LdI16(_) | LdI32(_) | LdI64(_) | LdI256(_) | LdI128(_) | CastI8
674674
| CastI16 | CastI32 | CastI64 | CastI128 | CastI256 | LdTrue | LdFalse
675675
| ReadRef | WriteRef | Add | Sub | Mul | Mod | Div | Negate | BitOr | BitAnd
676-
| Xor | Shl | Shr | Or | And | Not | Eq | Neq | Lt | Gt | Le | Ge | Abort | Nop => {
676+
| Xor | Shl | Shr | Or | And | Not | Eq | Neq | Lt | Gt | Le | Ge | Abort | AbortMsg | Nop => {
677677
},
678678
}
679679
}

third_party/move/move-binary-format/src/check_complexity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ impl BinaryComplexityMeter<'_> {
376376
| MoveTo(_)
377377
| MoveFrom(_)
378378
| Abort
379+
| AbortMsg
379380
| Nop => (),
380381
}
381382
}

third_party/move/move-binary-format/src/deserializer.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,14 @@ fn load_code(cursor: &mut VersionedCursor, code: &mut Vec<Bytecode>) -> BinaryLo
18311831
)),
18321832
);
18331833
},
1834+
Opcodes::ABORT_MSG if cursor.version() < VERSION_10 => {
1835+
return Err(
1836+
PartialVMError::new(StatusCode::MALFORMED).with_message(format!(
1837+
"aborting with message not available before bytecode version {}",
1838+
VERSION_10
1839+
)),
1840+
);
1841+
},
18341842
_ => {},
18351843
};
18361844

@@ -1943,6 +1951,7 @@ fn load_code(cursor: &mut VersionedCursor, code: &mut Vec<Bytecode>) -> BinaryLo
19431951
Opcodes::LE => Bytecode::Le,
19441952
Opcodes::GE => Bytecode::Ge,
19451953
Opcodes::ABORT => Bytecode::Abort,
1954+
Opcodes::ABORT_MSG => Bytecode::AbortMsg,
19461955
Opcodes::NOP => Bytecode::Nop,
19471956
Opcodes::EXISTS => Bytecode::Exists(load_struct_def_index(cursor)?),
19481957
Opcodes::EXISTS_GENERIC => Bytecode::ExistsGeneric(load_struct_def_inst_index(cursor)?),
@@ -2226,6 +2235,8 @@ impl Opcodes {
22262235
0x65 => Ok(Opcodes::CAST_I128),
22272236
0x66 => Ok(Opcodes::CAST_I256),
22282237
0x67 => Ok(Opcodes::NEGATE),
2238+
// Since bytecode version 10
2239+
0x68 => Ok(Opcodes::ABORT_MSG),
22292240
_ => Err(PartialVMError::new(StatusCode::UNKNOWN_OPCODE)
22302241
.with_message(format!("code {:X}", value))),
22312242
}

third_party/move/move-binary-format/src/file_format.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3050,6 +3050,18 @@ pub enum Bytecode {
30503050
ty_stack << ty
30513051
"#]
30523052
Negate,
3053+
3054+
#[group = "control_flow"]
3055+
#[description = r#"
3056+
Abort the transaction with an error code and message.
3057+
"#]
3058+
#[semantics = r#"
3059+
stack >> (error_message: &vector<u8>)
3060+
stack >> (error_code: u64)
3061+
abort transaction with error_code and error_message
3062+
"#]
3063+
#[runtime_check_prologue = "ty_stack >> _"]
3064+
AbortMsg,
30533065
}
30543066

30553067
impl ::std::fmt::Debug for Bytecode {
@@ -3149,6 +3161,7 @@ impl ::std::fmt::Debug for Bytecode {
31493161
Bytecode::Le => write!(f, "Le"),
31503162
Bytecode::Ge => write!(f, "Ge"),
31513163
Bytecode::Abort => write!(f, "Abort"),
3164+
Bytecode::AbortMsg => write!(f, "AbortMsg"),
31523165
Bytecode::Nop => write!(f, "Nop"),
31533166
Bytecode::Exists(a) => write!(f, "Exists({:?})", a),
31543167
Bytecode::ExistsGeneric(a) => write!(f, "ExistsGeneric({:?})", a),
@@ -3171,7 +3184,10 @@ impl ::std::fmt::Debug for Bytecode {
31713184
impl Bytecode {
31723185
/// Return true if this bytecode instruction always branches
31733186
pub fn is_unconditional_branch(&self) -> bool {
3174-
matches!(self, Bytecode::Ret | Bytecode::Abort | Bytecode::Branch(_))
3187+
matches!(
3188+
self,
3189+
Bytecode::Ret | Bytecode::Abort | Bytecode::AbortMsg | Bytecode::Branch(_)
3190+
)
31753191
}
31763192

31773193
/// Return true if the branching behavior of this bytecode instruction depends on a runtime
@@ -3328,6 +3344,7 @@ impl Bytecode {
33283344
| Le
33293345
| Ge
33303346
| Abort
3347+
| AbortMsg
33313348
| Nop
33323349
| ImmBorrowVariantField(_)
33333350
| ImmBorrowVariantFieldGeneric(_)

third_party/move/move-binary-format/src/file_format_common.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ pub enum Opcodes {
335335
CAST_I64 = 0x64,
336336
CAST_I128 = 0x65,
337337
CAST_I256 = 0x66,
338-
NEGATE = 0x67
338+
NEGATE = 0x67,
339+
// Since bytecode version 10
340+
ABORT_MSG = 0x68,
339341
}
340342

341343
/// Upper limit on the binary size
@@ -552,8 +554,12 @@ pub const VERSION_8: u32 = 8;
552554
/// + allow `$` in identifiers
553555
pub const VERSION_9: u32 = 9;
554556

557+
/// Version 10: changes compared to version 9
558+
/// + abort with message instruction
559+
pub const VERSION_10: u32 = 10;
560+
555561
/// Mark which version is the latest version.
556-
pub const VERSION_MAX: u32 = VERSION_9;
562+
pub const VERSION_MAX: u32 = VERSION_10;
557563

558564
/// Mark which version is the default version. This is the version used by default by tools like
559565
/// the compiler. Notice that this version might be different from the one supported on nodes.
@@ -798,6 +804,7 @@ pub fn instruction_key(instruction: &Bytecode) -> u8 {
798804
Le => Opcodes::LE,
799805
Ge => Opcodes::GE,
800806
Abort => Opcodes::ABORT,
807+
AbortMsg => Opcodes::ABORT_MSG,
801808
Nop => Opcodes::NOP,
802809
Exists(_) => Opcodes::EXISTS,
803810
ExistsGeneric(_) => Opcodes::EXISTS_GENERIC,

third_party/move/move-binary-format/src/serializer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ fn serialize_instruction_inner(
11681168
Bytecode::Le => binary.push(Opcodes::LE as u8),
11691169
Bytecode::Ge => binary.push(Opcodes::GE as u8),
11701170
Bytecode::Abort => binary.push(Opcodes::ABORT as u8),
1171+
Bytecode::AbortMsg => binary.push(Opcodes::ABORT_MSG as u8),
11711172
Bytecode::Nop => binary.push(Opcodes::NOP as u8),
11721173
Bytecode::Exists(class_idx) => {
11731174
binary.push(Opcodes::EXISTS as u8)?;

0 commit comments

Comments
 (0)