Skip to content

Commit 49e73b0

Browse files
authored
[vm] New bytecode for aborting with message (#18347)
* [vm] New VM instruction for aborting with message * Fix hashing * Add type checks for Abort/AbortMsg * Add comment * Do not change `ExecutionStatus` * Revert changes * Cursor feedback * Fix formatting * Fix macro * Return error on message type mismatch * Include abort message in prologue/epilogue for debugging * [vm] New bytecode for aborting with message * Cursor feedback * Rustfmt * More cursor feedback * More places to handle `AbortMsg` variant * Feature gate abort messages * Use feature flag to enable abort messages in VM * Add comment * Replace `&vector<u8>` with `vector<u8>` * Replace `&vector<u8>` with `vector<u8>` * Fix error for invalid abort messages * Combine `Abort` and `AbortMsg` in stackless buytecode * Wolfgang feedback * George feedback * Add test for invalid message * Charge gas per byte * Clippy * Add to default features * Update tests * Fix gas profiler * Simplify gas model * Fix sourcifier * Cap length of abort message * Update limit * Update abort_msg_per_byte
1 parent 99d5c8d commit 49e73b0

File tree

480 files changed

+924
-585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

480 files changed

+924
-585
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,12 @@ where
547547

548548
self.algebra.charge_execution(cost)
549549
}
550+
551+
fn charge_abort_message(&mut self, bytes: &[u8]) -> PartialVMResult<()> {
552+
let num_bytes = NumBytes::new(bytes.len() as u64);
553+
let cost = ABORT_MSG_BASE + ABORT_MSG_PER_BYTE * num_bytes;
554+
self.algebra.charge_execution(cost)
555+
}
550556
}
551557

552558
impl<A> AptosGasMeter for StandardGasMeter<A>

aptos-move/aptos-gas-profiling/src/profiler.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ where
367367

368368
[VEC_SWAP]
369369
fn charge_vec_swap(&mut self) -> PartialVMResult<()>;
370+
371+
[ABORT_MSG]
372+
fn charge_abort_message(&mut self, bytes: &[u8]) -> PartialVMResult<()>;
370373
}
371374

372375
fn balance_internal(&self) -> InternalGas {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! This module defines the gas parameters for all Move instructions.
55
66
use crate::{
7-
gas_feature_versions::{RELEASE_V1_18, RELEASE_V1_33, RELEASE_V1_38},
7+
gas_feature_versions::{RELEASE_V1_18, RELEASE_V1_33, RELEASE_V1_38, RELEASE_V1_40},
88
gas_schedule::VMGasParameters,
99
};
1010
use aptos_gas_algebra::{
@@ -22,6 +22,8 @@ crate::gas_schedule::macros::define_gas_parameters!(
2222
// control flow
2323
[ret: InternalGas, "ret", 220],
2424
[abort: InternalGas, "abort", 220],
25+
[abort_msg_base: InternalGas, { RELEASE_V1_40.. => "abort_msg.base" }, 440],
26+
[abort_msg_per_byte: InternalGasPerByte, { RELEASE_V1_40.. => "abort_msg.per_byte" }, 45],
2527

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

aptos-move/aptos-memory-usage-tracker/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,17 @@ where
343343
.charge_native_function_before_execution(ty_args, args)
344344
}
345345

346+
fn charge_abort_message(&mut self, bytes: &[u8]) -> PartialVMResult<()> {
347+
self.release_heap_memory(
348+
self.vm_gas_params()
349+
.misc
350+
.abs_val
351+
.abstract_heap_size(bytes, self.feature_version())?,
352+
);
353+
354+
self.base.charge_abort_message(bytes)
355+
}
356+
346357
#[inline]
347358
fn charge_native_function(
348359
&mut self,

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-transactional-test-harness/tests/aptos_test_harness/diamond_clicker.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
processed 4 tasks
22
task 1 lines 4-35: print-bytecode --input=module [module Alice::game {]
3-
// Bytecode version v9
3+
// Bytecode version v10
44
module 0xf75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6::game
55
use 0x1::signer
66
use 0x1::debug

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,8 @@ 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 => {
677-
},
676+
| Xor | Shl | Shr | Or | And | Not | Eq | Neq | Lt | Gt | Le | Ge | Abort
677+
| AbortMsg | Nop => {},
678678
}
679679
}
680680
Ok(())

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
}

0 commit comments

Comments
 (0)