Repository: MystenLabs/sui
File: sui-execution/latest/sui-move-natives/src/event.rs (Rust)

Code before:
            return Err(
                PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR)
                    .with_message("Sui verifier guarantees this is a struct".to_string()),
            );
        }
    };
    let tag_size = tag.abstract_size_for_gas_metering();

    // Converting type to typetag be expensive due to recursion overhead
    native_charge_gas_early_exit!(
        context,
        event_emit_cost_params.event_emit_tag_size_derivation_cost_per_byte
            * u64::from(tag_size).into()
    );

    if stream_ref.is_some() {
        native_charge_gas_early_exit!(
            context,
            // this code cannot be reached in protocol versions which don't define
            // event_emit_auth_stream_cost
            event_emit_cost_params.event_emit_auth_stream_cost.unwrap()
        );
    }

    // Get the type tag before getting the mutable reference to avoid borrowing issues
    let stream_head_type_tag = if let Some(ref stream_ref) = stream_ref {
        Some(context.type_to_type_tag(&stream_ref.stream_head_ty)?)
    } else {
        None
    };

    let obj_runtime: &mut ObjectRuntime = get_extension_mut!(context)?;
    let max_event_emit_size = obj_runtime.protocol_config.max_event_emit_size();
    let ev_size = u64::from(tag_size + event_value_size);
    // Check if the event size is within the limit
    if ev_size > max_event_emit_size {
        return Err(PartialVMError::new(StatusCode::MEMORY_LIMIT_EXCEEDED)
            .with_message(format!(
                "Emitting event of size {ev_size} bytes. Limit is {max_event_emit_size} bytes."
            ))
            .with_sub_status(
                VMMemoryLimitExceededSubStatusCode::EVENT_SIZE_LIMIT_EXCEEDED as u64,
            ));
    }

    // Check that the size contribution of the event is within the total size limit
    // This feature is guarded as its only present in some versions
    if let Some(max_event_emit_size_total) = obj_runtime
        .protocol_config
        .max_event_emit_size_total_as_option()
    {

Review comment (suggestion):
```suggestion
    let stream_head_type_tag = if let Some(stream_ref) = &stream_ref {
```

Code after:
            return Err(
                PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR)
                    .with_message("Sui verifier guarantees this is a struct".to_string()),
            );
        }
    };
    let tag_size = tag.abstract_size_for_gas_metering();

    // Converting type to typetag be expensive due to recursion overhead
    native_charge_gas_early_exit!(
        context,
        event_emit_cost_params.event_emit_tag_size_derivation_cost_per_byte
            * u64::from(tag_size).into()
    );

    if stream_ref.is_some() {
        native_charge_gas_early_exit!(
            context,
            // this code cannot be reached in protocol versions which don't define
            // event_emit_auth_stream_cost
            event_emit_cost_params.event_emit_auth_stream_cost.unwrap()
        );
    }

    // Get the type tag before getting the mutable reference to avoid borrowing issues
    let stream_head_type_tag = if let Some(stream_ref) = &stream_ref {
        Some(context.type_to_type_tag(&stream_ref.stream_head_ty)?)
    } else {
        None
    };

    let obj_runtime: &mut ObjectRuntime = get_extension_mut!(context)?;
    let max_event_emit_size = obj_runtime.protocol_config.max_event_emit_size();
    let ev_size = u64::from(tag_size + event_value_size);
    // Check if the event size is within the limit
    if ev_size > max_event_emit_size {
        return Err(PartialVMError::new(StatusCode::MEMORY_LIMIT_EXCEEDED)
            .with_message(format!(
                "Emitting event of size {ev_size} bytes. Limit is {max_event_emit_size} bytes."
            ))
            .with_sub_status(
                VMMemoryLimitExceededSubStatusCode::EVENT_SIZE_LIMIT_EXCEEDED as u64,
            ));
    }

    // Check that the size contribution of the event is within the total size limit
    // This feature is guarded as its only present in some versions
    if let Some(max_event_emit_size_total) = obj_runtime
        .protocol_config
        .max_event_emit_size_total_as_option()
    {