@@ -61,31 +61,54 @@ export class Controller {
6161 }
6262
6363 async addSource ( verificationPayload : SourceVerifyPayload ) : Promise < VerifyResult > {
64+ logger . info ( "Starting source verification" , {
65+ compiler : verificationPayload . compiler ,
66+ knownContractHash : verificationPayload . knownContractHash ,
67+ sourcesCount : verificationPayload . sources . length ,
68+ } ) ;
69+
6470 // Compile
71+ logger . debug ( "Compiling sources" , { compiler : verificationPayload . compiler } ) ;
6572 const compiler = this . compilers [ verificationPayload . compiler ] ;
6673 const compileResult = await compiler . verify ( verificationPayload ) ;
74+
6775 if ( compileResult . error || compileResult . result !== "similar" || ! compileResult . hash ) {
76+ logger . warn ( "Compilation failed or hash mismatch" , {
77+ result : compileResult . result ,
78+ error : compileResult . error ,
79+ hash : compileResult . hash ,
80+ } ) ;
6881 return {
6982 compileResult,
7083 } ;
7184 }
7285
86+ logger . info ( "Compilation successful" , {
87+ hash : compileResult . hash ,
88+ result : compileResult . result ,
89+ } ) ;
90+
7391 if ( ! this . config . allowReverification ) {
92+ logger . debug ( "Checking if proof already deployed" ) ;
7493 const isDeployed = await this . tonReaderClient . isProofDeployed (
7594 verificationPayload . knownContractHash ,
7695 this . config . verifierId ,
7796 ) ;
7897 if ( isDeployed ) {
98+ logger . warn ( "Contract already verified" , {
99+ knownContractHash : verificationPayload . knownContractHash ,
100+ } ) ;
79101 return {
80102 compileResult : {
81103 result : "unknown_error" ,
82- error : "Contract is already deployed" ,
104+ error : "Proof has already been deployed" ,
83105 hash : null ,
84106 compilerSettings : compileResult . compilerSettings ,
85107 sources : compileResult . sources ,
86108 } ,
87109 } ;
88110 }
111+ logger . debug ( "Proof not deployed, proceeding" ) ;
89112 }
90113
91114 // Upload sources to IPFS
@@ -101,7 +124,14 @@ export class Controller {
101124 name : s . filename ,
102125 } ) ,
103126 ) ;
127+
128+ logger . info ( "Uploading sources to IPFS" , {
129+ sourcesCount : sourcesToUpload . length ,
130+ } ) ;
104131 const fileLocators = await this . ipfsProvider . write ( sourcesToUpload , true ) ;
132+ logger . info ( "Sources uploaded to IPFS" , {
133+ filesUploaded : fileLocators . length ,
134+ } ) ;
105135
106136 const sourceSpec : SourceItem = {
107137 compilerSettings : compileResult . compilerSettings ,
@@ -118,14 +148,16 @@ export class Controller {
118148 } ;
119149
120150 // Upload source spec JSON to IPFS
151+ logger . debug ( "Uploading source spec to IPFS" ) ;
121152 const [ ipfsLink ] = await this . ipfsProvider . writeFromContent (
122153 [ Buffer . from ( JSON . stringify ( sourceSpec ) ) ] ,
123154 true ,
124155 ) ;
125156
126- logger . info ( ipfsLink ) ;
157+ logger . info ( "Source spec uploaded" , { ipfsLink } ) ;
127158
128159 const queryId = random64BitNumber ( ) ;
160+ logger . debug ( "Signing message" , { queryId } ) ;
129161
130162 // This is the message that will be forwarded to verifier registry
131163 const msgToSign = cellToSign (
@@ -139,6 +171,11 @@ export class Controller {
139171
140172 const { sig, sigCell } = signatureCell ( msgToSign , this . keypair ) ;
141173
174+ logger . info ( "Source verification completed successfully" , {
175+ ipfsLink,
176+ hash : compileResult . hash ,
177+ } ) ;
178+
142179 return {
143180 compileResult,
144181 sig : sig . toString ( "base64" ) ,
@@ -148,13 +185,17 @@ export class Controller {
148185 }
149186
150187 public async sign ( { messageCell, tmpDir } : { messageCell : Buffer ; tmpDir : string } ) {
188+ logger . info ( "Starting message signing" ) ;
189+
151190 const cell = Cell . fromBoc ( Buffer . from ( messageCell ) ) [ 0 ] ;
152191
192+ logger . debug ( "Getting verifier config" ) ;
153193 const verifierConfig = await this . tonReaderClient . getVerifierConfig (
154194 this . config . verifierId ,
155195 this . config . sourcesRegistryAddress ,
156196 ) ;
157197
198+ logger . debug ( "Validating message cell" ) ;
158199 const { ipfsPointer, codeCellHash, senderAddress, queryId } = validateMessageCell (
159200 cell ,
160201 this . VERIFIER_SHA256 ,
@@ -163,16 +204,31 @@ export class Controller {
163204 verifierConfig ,
164205 ) ;
165206
207+ logger . debug ( "Reading source spec from IPFS" , { ipfsPointer } ) ;
166208 const sourceTemp = await this . ipfsProvider . read ( ipfsPointer ) ;
167209
168210 const json : SourceItem = JSON . parse ( sourceTemp ) ;
169211
212+ logger . debug ( "Verifying code hash" , {
213+ expectedHash : codeCellHash ,
214+ actualHash : json . hash ,
215+ } ) ;
216+
170217 if ( json . hash !== codeCellHash ) {
218+ logger . error ( "Code hash mismatch" , {
219+ expectedHash : codeCellHash ,
220+ actualHash : json . hash ,
221+ } ) ;
171222 throw new Error ( "Code hash mismatch" ) ;
172223 }
173224
174225 const compiler = this . compilers [ json . compiler ] ;
175226
227+ logger . debug ( "Reading sources from IPFS" , {
228+ sourcesCount : json . sources . length ,
229+ compiler : json . compiler ,
230+ } ) ;
231+
176232 const sources = await Promise . all (
177233 json . sources . map ( async ( s ) => {
178234 const content = await this . ipfsProvider . read ( s . url ) ;
@@ -188,6 +244,10 @@ export class Controller {
188244 } ) ,
189245 ) ;
190246
247+ logger . info ( "Sources downloaded from IPFS" , {
248+ sourcesCount : sources . length ,
249+ } ) ;
250+
191251 const sourceToVerify : SourceVerifyPayload = {
192252 sources : sources ,
193253 compiler : json . compiler ,
@@ -203,17 +263,27 @@ export class Controller {
203263 senderAddress : senderAddress . toString ( ) ,
204264 } ;
205265
266+ logger . debug ( "Verifying compilation" ) ;
206267 const compileResult = await compiler . verify ( sourceToVerify ) ;
207268
208269 if ( compileResult . result !== "similar" ) {
270+ logger . error ( "Compilation verification failed" , {
271+ result : compileResult . result ,
272+ error : compileResult . error ,
273+ } ) ;
209274 throw new Error ( "Invalid compilation result: " + compileResult . result ) ;
210275 }
211276
277+ logger . info ( "Compilation verified successfully" ) ;
278+
279+ logger . debug ( "Creating signature cell" ) ;
212280 const slice = cell . beginParse ( ) ;
213281 const msgToSign = slice . loadRef ( ) ;
214282 const { sigCell } = signatureCell ( msgToSign , this . keypair ) ;
215283 let updateSigCell = addSignatureCell ( slice . loadRef ( ) , sigCell ) ;
216284
285+ logger . info ( "Message signing completed successfully" ) ;
286+
217287 return {
218288 msgCell : slice . asBuilder ( ) . storeRef ( msgToSign ) . storeRef ( updateSigCell ) . asCell ( ) . toBoc ( ) ,
219289 } ;
0 commit comments