Struct ckb_script::TransactionScriptsVerifier

source ·
pub struct TransactionScriptsVerifier<DL> { /* private fields */ }
Expand description

This struct leverages CKB VM to verify transaction inputs.

FlatBufferBuilder owned Vec<u8> that grows as needed, in the future, we might refactor this to share buffer to achieve zero-copy

Implementations§

source§

impl<DL: CellDataProvider + HeaderProvider + ExtensionProvider + Send + Sync + Clone + 'static> TransactionScriptsVerifier<DL>

source

pub fn new( rtx: Arc<ResolvedTransaction>, data_loader: DL, consensus: Arc<Consensus>, tx_env: Arc<TxVerifyEnv> ) -> TransactionScriptsVerifier<DL>

Creates a script verifier for the transaction.

§Params
  • rtx - transaction which cell out points have been resolved.
  • data_loader - used to load cell data.
source

pub fn set_debug_printer<F: Fn(&Byte32, &str) + Sync + Send + 'static>( &mut self, func: F )

Sets a callback to handle the debug syscall.

Script can print a message using the debug syscall.

The callback receives two parameters:

  • hash: &Byte32: this is the script hash of currently running script group.
  • message: &str: message passed to the debug syscall.
source

pub fn extract_script(&self, script: &Script) -> Result<Bytes, ScriptError>

Extracts actual script binary either in dep cells.

source

pub fn select_version( &self, script: &Script ) -> Result<ScriptVersion, ScriptError>

Returns the version of the machine based on the script and the consensus rules.

source

pub fn verify(&self, max_cycles: Cycle) -> Result<Cycle, Error>

Verifies the transaction by running scripts.

§Params
  • max_cycles - Maximum allowed cycles to run the scripts. The verification quits early when the consumed cycles exceed the limit.
§Returns

It returns the total consumed cycles on success, Otherwise it returns the verification error.

source

pub fn resumable_verify( &self, limit_cycles: Cycle ) -> Result<VerifyResult, Error>

Performing a resumable verification on the transaction scripts.

§Params
  • limit_cycles - Maximum allowed cycles to run the scripts. The verification quits early when the consumed cycles exceed the limit.
§Returns

It returns the total consumed cycles if verification completed, If verify is suspended, a state will returned.

source

pub fn resume_from_snap( &self, snap: &TransactionSnapshot, limit_cycles: Cycle ) -> Result<VerifyResult, Error>

Resuming an suspended verify from snapshot

§Params
  • snap - Captured transaction verification snapshot.

  • limit_cycles - Maximum allowed cycles to run the scripts. The verification quits early when the consumed cycles exceed the limit.

§Returns

It returns the total consumed cycles if verification completed, If verify is suspended, a borrowed state will returned.

source

pub fn resume_from_state( &self, state: TransactionState, limit_cycles: Cycle ) -> Result<VerifyResult, Error>

Resuming an suspended verify from vm state

§Params
  • state - vm state.

  • limit_cycles - Maximum allowed cycles to run the scripts. The verification quits early when the consumed cycles exceed the limit.

§Returns

It returns the total consumed cycles if verification completed, If verify is suspended, a borrowed state will returned.

source

pub fn complete( &self, snap: &TransactionSnapshot, max_cycles: Cycle ) -> Result<Cycle, Error>

Complete an suspended verify

§Params
  • snap - Captured transaction verification snapshot.

  • max_cycles - Maximum allowed cycles to run the scripts. The verification quits early when the consumed cycles exceed the limit.

§Returns

It returns the total consumed cycles on completed, Otherwise it returns the verification error.

source

pub fn verify_single( &self, script_group_type: ScriptGroupType, script_hash: &Byte32, max_cycles: Cycle ) -> Result<Cycle, ScriptError>

Runs a single script in current transaction, while this is not useful for CKB itself, it can be very helpful when building a CKB debugger.

source

pub fn groups(&self) -> impl Iterator<Item = (&Byte32, &ScriptGroup)>

Returns all script groups.

source

pub fn groups_with_type( &self ) -> impl Iterator<Item = (ScriptGroupType, &Byte32, &ScriptGroup)>

Returns all script groups with type.

source

pub fn find_script_group( &self, script_group_type: ScriptGroupType, script_hash: &Byte32 ) -> Option<&ScriptGroup>

Finds the script group from cell deps.

source

pub fn generate_syscalls( &self, script_version: ScriptVersion, script_group: &ScriptGroup, context: Arc<Mutex<MachineContext>> ) -> Vec<Box<dyn Syscalls<CoreMachine>>>

Prepares syscalls.

source

pub fn detailed_run( &self, script_group: &ScriptGroup, max_cycles: Cycle ) -> Result<(i8, AsmMachine), ScriptError>

Runs a single program, then returns the exit code together with the entire machine to the caller for more inspections.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsAny for T
where T: Any,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Cast to trait Any
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V