Skip to content

Commit fe84b41

Browse files
committed
skip ecalls in compute block
1 parent 4df8169 commit fe84b41

File tree

6 files changed

+27
-171
lines changed

6 files changed

+27
-171
lines changed

go-cosmwasm/api/ecall_record.go

Lines changed: 0 additions & 155 deletions
This file was deleted.

go-cosmwasm/api/lib.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -175,6 +176,12 @@ func ReleaseCache(cache Cache) {
175176
}
176177

177178
func InitEnclaveRuntime(moduleCacheSize uint16) error {
179+
// Skip in non-SGX replay mode - there's no enclave
180+
if tmapi.GetRecorder().IsReplayMode() {
181+
fmt.Println("[InitEnclaveRuntime] Non-SGX replay mode: skipping (no enclave)")
182+
return nil
183+
}
184+
178185
errmsg := C.Buffer{}
179186

180187
config := C.EnclaveRuntimeConfig{
@@ -536,11 +543,11 @@ func CreateAttestationReport(no_epid bool, no_dcap bool, is_migration_report boo
536543
}
537544

538545
func GetEncryptedSeed(cert []byte) ([]byte, error) {
539-
recorder := GetRecorder()
546+
recorder := tmapi.GetRecorder()
540547

541548
// In replay mode, try to get from recorded data
542549
if recorder.IsReplayMode() {
543-
if output, err, found := ReplayGetEncryptedSeed(cert); found {
550+
if output, err, found := recorder.Replay("GetEncryptedSeed", cert); found {
544551
fmt.Printf("[GetEncryptedSeed] Replay mode: returning recorded result\n")
545552
return output, err
546553
}
@@ -562,7 +569,7 @@ func GetEncryptedSeed(cert []byte) ([]byte, error) {
562569
}
563570

564571
// Record the result for non-SGX nodes
565-
if recordErr := RecordGetEncryptedSeed(cert, output, callErr); recordErr != nil {
572+
if recordErr := recorder.Record("GetEncryptedSeed", cert, output, callErr); recordErr != nil {
566573
fmt.Printf("[GetEncryptedSeed] Warning: failed to record ecall: %v\n", recordErr)
567574
} else {
568575
fmt.Printf("[GetEncryptedSeed] SGX mode: recorded ecall result\n")

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ replace (
88
cosmossdk.io/api => github.com/scrtlabs/cosmos-sdk-api v0.7.6-secret.0
99
cosmossdk.io/store => github.com/scrtlabs/cosmos-sdk-store v1.1.1-secret.1
1010
cosmossdk.io/x/tx => github.com/scrtlabs/cosmos-sdk-x-tx v0.13.7-secret.0
11-
github.com/cometbft/cometbft => github.com/scrtlabs/tendermint v0.38.19-secret.1
11+
github.com/cometbft/cometbft => github.com/scrtlabs/tendermint v0.38.19-secret.1-non-sgx.0
1212
github.com/cosmos/cosmos-sdk => github.com/scrtlabs/cosmos-sdk v0.50.14-secret.7
1313
github.com/cosmos/iavl => github.com/scrtlabs/iavl v1.2.2-secret.0
14+
15+
// Use local tm-secret-enclave with recorder support
16+
github.com/scrtlabs/tm-secret-enclave => ../tm-secret-enclave
1417
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
1518

1619
github.com/zondax/ledger-go => github.com/zondax/ledger-go v1.0.0
@@ -76,7 +79,7 @@ require (
7679
github.com/gogo/protobuf v1.3.2
7780
github.com/golang/mock v1.6.0
7881
github.com/hashicorp/go-metrics v0.5.3
79-
github.com/scrtlabs/tm-secret-enclave v1.13.1
82+
github.com/scrtlabs/tm-secret-enclave v1.13.1-non-sgx.0
8083
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028
8184
gopkg.in/yaml.v2 v2.4.0
8285
)

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,10 +1619,8 @@ github.com/scrtlabs/cosmos-sdk-x-tx v0.13.7-secret.0 h1:i3k5706sDHKhaCvzokB+n33/
16191619
github.com/scrtlabs/cosmos-sdk-x-tx v0.13.7-secret.0/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w=
16201620
github.com/scrtlabs/iavl v1.2.2-secret.0 h1:P96PL1Lf8OBSW9pMrlaRxhceZ4z9Hc7jk12g9ShWeHw=
16211621
github.com/scrtlabs/iavl v1.2.2-secret.0/go.mod h1:GiM43q0pB+uG53mLxLDzimxM9l/5N9UuSY3/D0huuVw=
1622-
github.com/scrtlabs/tendermint v0.38.19-secret.1 h1:NxZ21CS6INBjL2QCL087/BJLb1NAIeoY07mHasTuqKs=
1623-
github.com/scrtlabs/tendermint v0.38.19-secret.1/go.mod h1:CZUJG1djTJUVbpjGS9JmQx9CFfF4goKi3LzYUQtxWO8=
1624-
github.com/scrtlabs/tm-secret-enclave v1.13.1 h1:0mXcBdoWyqEGhQEdbXMjSuTi9LKKMld2BqEj0eNpoxU=
1625-
github.com/scrtlabs/tm-secret-enclave v1.13.1/go.mod h1:nxZQtzzAqBNBLOEXSv4cKlUnVA4vRmHOn6ujr3kxVME=
1622+
github.com/scrtlabs/tendermint v0.38.19-secret.1-non-sgx.0 h1:Xcr8LzUDqFEZBs+9bezrOfRS+4eHShGYT9wQ8JdGMo0=
1623+
github.com/scrtlabs/tendermint v0.38.19-secret.1-non-sgx.0/go.mod h1:o8pxZlFnd7pwJ/awZi1wi1+9guKu7NpE97/iijSFNvk=
16261624
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
16271625
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
16281626
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=

x/compute/module.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/scrtlabs/SecretNetwork/x/compute/internal/keeper"
2121
"github.com/scrtlabs/SecretNetwork/x/compute/internal/types"
2222
tmenclave "github.com/scrtlabs/tm-secret-enclave"
23+
tmapi "github.com/scrtlabs/tm-secret-enclave/api"
2324

2425
crontypes "github.com/scrtlabs/SecretNetwork/x/cron/types"
2526
)
@@ -157,6 +158,10 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
157158

158159
// BeginBlock returns the begin blocker for the compute module.
159160
func (am AppModule) BeginBlock(c context.Context) error {
161+
if tmapi.GetRecorder().IsReplayMode() {
162+
return nil
163+
}
164+
160165
// Note: as of tendermint v0.38.0 block begin request info is no longer available
161166
ctx := c.(sdk.Context)
162167
block_header := ctx.BlockHeader()
@@ -217,6 +222,9 @@ func (am AppModule) BeginBlock(c context.Context) error {
217222

218223
// EndBlock returns the end blocker for the compute module.
219224
func (am AppModule) EndBlock(c context.Context) error {
225+
if tmapi.GetRecorder().IsReplayMode() {
226+
return nil
227+
}
220228
ctx := c.(sdk.Context)
221229

222230
_, bytesCronMsgs, err := am.keeper.GetScheduledMsgs(ctx, crontypes.ExecutionStage_EXECUTION_STAGE_END_BLOCKER)

x/registration/internal/keeper/keeper.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/hex"
66
"encoding/json"
77
"fmt"
8-
"os"
98
"path/filepath"
109

1110
"cosmossdk.io/core/store"
@@ -15,6 +14,7 @@ import (
1514
sdk "github.com/cosmos/cosmos-sdk/types"
1615
"github.com/scrtlabs/SecretNetwork/x/registration/internal/types"
1716
ra "github.com/scrtlabs/SecretNetwork/x/registration/remote_attestation"
17+
tmapi "github.com/scrtlabs/tm-secret-enclave/api"
1818
)
1919

2020
// Keeper will have a reference to Wasmer with it's own data directory.
@@ -25,16 +25,11 @@ type Keeper struct {
2525
router baseapp.MessageRouter
2626
}
2727

28-
// isNonSGXReplayMode returns true if running in non-SGX replay mode
29-
func isNonSGXReplayMode() bool {
30-
return os.Getenv("SECRET_NODE_MODE") == "replay"
31-
}
32-
3328
// NewKeeper creates a new contract Keeper instance
3429
func NewKeeper(cdc codec.Codec, storeService store.KVStoreService, router baseapp.MessageRouter, enclave EnclaveInterface, homeDir string, bootstrap bool) Keeper {
3530
if !bootstrap {
3631
// Skip seed initialization in non-SGX replay mode - there's no enclave to load seeds into
37-
if isNonSGXReplayMode() {
32+
if tmapi.GetRecorder().IsReplayMode() {
3833
fmt.Println("[Registration] Non-SGX replay mode: skipping seed initialization (no enclave)")
3934
} else {
4035
InitializeNode(homeDir, enclave)

0 commit comments

Comments
 (0)