File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ func LoadELF(ctx *cli.Context) error {
3232	if  err  !=  nil  {
3333		return  fmt .Errorf ("failed to compute program metadata: %w" , err )
3434	}
35+ 	// Must set witness and stateHash after initial state is prepared 
36+ 	if  err  :=  state .SetWitnessAndStateHash (); err  !=  nil  {
37+ 		return  fmt .Errorf ("failed to set witness and stateHash: %w" , err )
38+ 	}
3539	if  err  :=  jsonutil .WriteJSON [* Metadata ](ctx .Path (cannon .LoadELFMetaFlag .Name ), meta , OutFilePerm ); err  !=  nil  {
3640		return  fmt .Errorf ("failed to output metadata: %w" , err )
3741	}
Original file line number Diff line number Diff line change @@ -223,6 +223,10 @@ func Run(ctx *cli.Context) error {
223223		}
224224	}
225225
226+ 	if  err  :=  state .SetWitnessAndStateHash (); err  !=  nil  {
227+ 		return  fmt .Errorf ("failed to set witness and stateHash: %w" , err )
228+ 	}
229+ 
226230	if  err  :=  jsonutil .WriteJSON (ctx .Path (cannon .RunOutputFlag .Name ), state , OutFilePerm ); err  !=  nil  {
227231		return  fmt .Errorf ("failed to write state output: %w" , err )
228232	}
Original file line number Diff line number Diff line change @@ -50,6 +50,11 @@ type VMState struct {
5050	// Warning: the hint MAY NOT BE COMPLETE. I.e. this is buffered, 
5151	// and should only be read when len(LastHint) > 4 && uint32(LastHint[:4]) >= len(LastHint[4:]) 
5252	LastHint  hexutil.Bytes  `json:"lastHint,omitempty"` 
53+ 
54+ 	// VMState must hold these values because if not, we must ask FPVM again to 
55+ 	// compute these values. 
56+ 	Witness    []byte    `json:"witness,omitempty"` 
57+ 	StateHash  [32 ]byte  `json:"stateHash,omitempty"` 
5358}
5459
5560func  NewVMState () * VMState  {
@@ -59,6 +64,17 @@ func NewVMState() *VMState {
5964	}
6065}
6166
67+ func  (state  * VMState ) SetWitnessAndStateHash () error  {
68+ 	witness  :=  state .EncodeWitness ()
69+ 	state .Witness  =  witness 
70+ 	stateHash , err  :=  witness .StateHash ()
71+ 	if  err  !=  nil  {
72+ 		return  fmt .Errorf ("failed to compute stateHash: %w" , err )
73+ 	}
74+ 	state .StateHash  =  stateHash 
75+ 	return  nil 
76+ }
77+ 
6278func  (state  * VMState ) GetStep () uint64  { return  state .Step  }
6379
6480func  (state  * VMState ) EncodeWitness () StateWitness  {
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments