@@ -17,6 +17,7 @@ import (
1717 v1types "github.com/scrtlabs/SecretNetwork/go-cosmwasm/types/v1"
1818
1919 "github.com/scrtlabs/SecretNetwork/go-cosmwasm/types"
20+ tmapi "github.com/scrtlabs/tm-secret-enclave/api"
2021)
2122
2223// nice aliases to the rust names
@@ -48,6 +49,32 @@ func HealthCheck() ([]byte, error) {
4849}
4950
5051func SubmitBlockSignatures (header []byte , commit []byte , txs []byte , encRandom []byte /* valSet []byte, nextValSet []byte */ ) ([]byte , []byte , error ) {
52+ recorder := tmapi .GetRecorder ()
53+
54+ // Create combined input for recording/replay (hash all inputs together)
55+ input := make ([]byte , 0 , len (header )+ len (commit )+ len (txs )+ len (encRandom ))
56+ input = append (input , header ... )
57+ input = append (input , commit ... )
58+ input = append (input , txs ... )
59+ input = append (input , encRandom ... )
60+
61+ // In replay mode, try to get from recorded data
62+ if recorder .IsReplayMode () {
63+ if output , err , found := recorder .Replay ("SubmitBlockSignatures" , input ); found {
64+ fmt .Printf ("[SubmitBlockSignatures] Replay mode: returning recorded result\n " )
65+ if err != nil {
66+ return nil , nil , err
67+ }
68+ // Output is 64 bytes: [32 bytes decrypted][32 bytes next_validator_set_evidence]
69+ if len (output ) == 64 {
70+ return output [:32 ], output [32 :], nil
71+ }
72+ return nil , nil , fmt .Errorf ("SubmitBlockSignatures: invalid recorded data (expected 64 bytes, got %d)" , len (output ))
73+ }
74+ return nil , nil , fmt .Errorf ("SubmitBlockSignatures: no recorded data found for input (replay mode)" )
75+ }
76+
77+ // SGX mode: call the actual enclave
5178 errmsg := C.Buffer {}
5279 spidSlice := sendSlice (header )
5380 defer freeAfterSend (spidSlice )
@@ -59,10 +86,33 @@ func SubmitBlockSignatures(header []byte, commit []byte, txs []byte, encRandom [
5986 defer freeAfterSend (txsSlice )
6087
6188 res , err := C .submit_block_signatures (spidSlice , apiKeySlice , txsSlice , encRandomSlice /* valSetSlice, nextValSetSlice,*/ , & errmsg )
89+
90+ var buf1 , buf2 []byte
91+ var callErr error
6292 if err != nil {
63- return nil , nil , errorWithMessage (err , errmsg )
93+ callErr = errorWithMessage (err , errmsg )
94+ } else {
95+ buf1 = receiveVector (res .buf1 )
96+ buf2 = receiveVector (res .buf2 )
97+ }
98+
99+ // Record the result - 64 bytes: [32 bytes buf1][32 bytes buf2]
100+ if callErr == nil {
101+ output := make ([]byte , 64 )
102+ copy (output [:32 ], buf1 )
103+ copy (output [32 :], buf2 )
104+ if recordErr := recorder .Record ("SubmitBlockSignatures" , input , output , nil ); recordErr != nil {
105+ fmt .Printf ("[SubmitBlockSignatures] Warning: failed to record ecall: %v\n " , recordErr )
106+ } else {
107+ fmt .Printf ("[SubmitBlockSignatures] SGX mode: recorded ecall result\n " )
108+ }
109+ } else {
110+ if recordErr := recorder .Record ("SubmitBlockSignatures" , input , nil , callErr ); recordErr != nil {
111+ fmt .Printf ("[SubmitBlockSignatures] Warning: failed to record ecall error: %v\n " , recordErr )
112+ }
64113 }
65- return receiveVector (res .buf1 ), receiveVector (res .buf2 ), nil
114+
115+ return buf1 , buf2 , callErr
66116}
67117
68118func SubmitValidatorSetEvidence (evidence []byte ) error {
@@ -175,6 +225,12 @@ func ReleaseCache(cache Cache) {
175225}
176226
177227func InitEnclaveRuntime (moduleCacheSize uint16 ) error {
228+ // Skip in non-SGX replay mode - there's no enclave
229+ if tmapi .GetRecorder ().IsReplayMode () {
230+ fmt .Println ("[InitEnclaveRuntime] Non-SGX replay mode: skipping (no enclave)" )
231+ return nil
232+ }
233+
178234 errmsg := C.Buffer {}
179235
180236 config := C.EnclaveRuntimeConfig {
@@ -536,11 +592,11 @@ func CreateAttestationReport(no_epid bool, no_dcap bool, is_migration_report boo
536592}
537593
538594func GetEncryptedSeed (cert []byte ) ([]byte , error ) {
539- recorder := GetRecorder ()
595+ recorder := tmapi . GetRecorder ()
540596
541597 // In replay mode, try to get from recorded data
542598 if recorder .IsReplayMode () {
543- if output , err , found := ReplayGetEncryptedSeed ( cert ); found {
599+ if output , err , found := recorder . Replay ( "GetEncryptedSeed" , cert ); found {
544600 fmt .Printf ("[GetEncryptedSeed] Replay mode: returning recorded result\n " )
545601 return output , err
546602 }
@@ -562,7 +618,7 @@ func GetEncryptedSeed(cert []byte) ([]byte, error) {
562618 }
563619
564620 // Record the result for non-SGX nodes
565- if recordErr := RecordGetEncryptedSeed ( cert , output , callErr ); recordErr != nil {
621+ if recordErr := recorder . Record ( "GetEncryptedSeed" , cert , output , callErr ); recordErr != nil {
566622 fmt .Printf ("[GetEncryptedSeed] Warning: failed to record ecall: %v\n " , recordErr )
567623 } else {
568624 fmt .Printf ("[GetEncryptedSeed] SGX mode: recorded ecall result\n " )
0 commit comments