Skip to content

Commit bf4d583

Browse files
committed
runtime: Add conditional SGX attestation parsing for rofl.Register txs
1 parent 171ab2a commit bf4d583

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

.changelog/876.feature.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
runtime: Add conditional SGX attestation parsing for rofl.Register txs

analyzer/runtime/extract.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/ethereum/go-ethereum/accounts/abi"
1818
ethCommon "github.com/ethereum/go-ethereum/common"
1919
"github.com/oasisprotocol/oasis-core/go/common/cbor"
20+
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
2021
"github.com/oasisprotocol/oasis-core/go/common/quantity"
2122
sdkConfig "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config"
2223
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/accounts"
@@ -35,6 +36,7 @@ import (
3536
"github.com/oasisprotocol/nexus/analyzer/util/eth"
3637
apiTypes "github.com/oasisprotocol/nexus/api/v1/types"
3738
"github.com/oasisprotocol/nexus/common"
39+
"github.com/oasisprotocol/nexus/coreapi/v24.0/common/node"
3840
"github.com/oasisprotocol/nexus/log"
3941
"github.com/oasisprotocol/nexus/storage"
4042
"github.com/oasisprotocol/nexus/storage/oasis/nodeapi"
@@ -534,7 +536,42 @@ func ExtractRound(blockHeader nodeapi.RuntimeBlockHeader, txrs []nodeapi.Runtime
534536
return nil
535537
},
536538
RoflRegister: func(body *rofl.Register) error {
537-
blockTransactionData.Body = body
539+
// Serialize the transaction body with enhanced attestation parsing for SGX hardware.
540+
// If the CapabilityTEE's hardware type is SGX, attempts to parse the attestation field,
541+
// replacing it with a structured SGXAttestation. If parsing fails or the hardware type
542+
// is not SGX, the original transaction body is returned unchanged.
543+
customSerialize := func(body *rofl.Register) interface{} {
544+
// If not SGX attestation, return original body.
545+
if uint8(body.EndorsedCapability.CapabilityTEE.Hardware) != uint8(node.TEEHardwareIntelSGX) {
546+
return body
547+
}
548+
549+
// Try parsing the SGX Attestation.
550+
var sa node.SGXAttestation
551+
if err := cbor.Unmarshal(body.EndorsedCapability.CapabilityTEE.Attestation, &sa); err != nil {
552+
logger.Error("error unmarshalling SGX attestation", "err", err)
553+
return body
554+
}
555+
556+
wrapper := struct {
557+
rofl.Register
558+
// Override Attestation field.
559+
EndorsedCapability struct {
560+
CapabilityTEE struct {
561+
node.CapabilityTEE
562+
Attestation node.SGXAttestation `json:"attestation"`
563+
} `json:"capability_tee"`
564+
NodeEndorsement signature.Signature `json:"node_endorsement"`
565+
} `json:"ect"`
566+
}{
567+
Register: *body,
568+
}
569+
wrapper.EndorsedCapability.CapabilityTEE.Attestation = sa
570+
571+
return wrapper
572+
}
573+
574+
blockTransactionData.Body = customSerialize(body)
538575
return nil
539576
},
540577
UnknownMethod: func(methodName string) error {

0 commit comments

Comments
 (0)