@@ -5,7 +5,7 @@ use core::script::Script;
55use core:: transaction:: { CellInput , CellOutput } ;
66use flatbuffers:: FlatBufferBuilder ;
77use fnv:: FnvHashMap ;
8- use syscalls:: { build_tx, FetchScriptHash , MmapCell , MmapTx } ;
8+ use syscalls:: { build_tx, Debugger , FetchScriptHash , MmapCell , MmapTx } ;
99use vm:: { DefaultMachine , SparseMemory } ;
1010
1111// This struct leverages CKB VM to verify transaction inputs.
@@ -85,7 +85,7 @@ impl<'a> TransactionScriptsVerifier<'a> {
8585 Err ( ScriptError :: NoScript )
8686 }
8787
88- pub fn verify_script ( & self , script : & Script ) -> Result < ( ) , ScriptError > {
88+ pub fn verify_script ( & self , script : & Script , prefix : & str ) -> Result < ( ) , ScriptError > {
8989 self . extract_script ( script) . and_then ( |script_binary| {
9090 let mut args = vec ! [ b"verify" . to_vec( ) ] ;
9191 args. extend_from_slice ( & script. signed_args . as_slice ( ) ) ;
@@ -95,6 +95,7 @@ impl<'a> TransactionScriptsVerifier<'a> {
9595 machine. add_syscall_module ( Box :: new ( self . build_mmap_tx ( ) ) ) ;
9696 machine. add_syscall_module ( Box :: new ( self . build_mmap_cell ( ) ) ) ;
9797 machine. add_syscall_module ( Box :: new ( self . build_fetch_script_hash ( ) ) ) ;
98+ machine. add_syscall_module ( Box :: new ( Debugger :: new ( prefix) ) ) ;
9899 machine
99100 . run ( script_binary, & args)
100101 . map_err ( ScriptError :: VMError )
@@ -110,14 +111,16 @@ impl<'a> TransactionScriptsVerifier<'a> {
110111
111112 pub fn verify ( & self ) -> Result < ( ) , ScriptError > {
112113 for ( i, input) in self . inputs . iter ( ) . enumerate ( ) {
113- self . verify_script ( & input. unlock ) . map_err ( |e| {
114+ let prefix = format ! ( "Transaction {}, input {}" , self . hash, i) ;
115+ self . verify_script ( & input. unlock , & prefix) . map_err ( |e| {
114116 info ! ( target: "script" , "Error validating input {} of transaction {}: {:?}" , i, self . hash, e) ;
115117 e
116118 } ) ?;
117119 }
118120 for ( i, output) in self . outputs . iter ( ) . enumerate ( ) {
119121 if let Some ( ref contract) = output. contract {
120- self . verify_script ( contract) . map_err ( |e| {
122+ let prefix = format ! ( "Transaction {}, output {}" , self . hash, i) ;
123+ self . verify_script ( contract, & prefix) . map_err ( |e| {
121124 info ! ( target: "script" , "Error validating output {} of transaction {}: {:?}" , i, self . hash, e) ;
122125 e
123126 } ) ?;
0 commit comments