Skip to content

Commit 51b87b7

Browse files
fix: attest turnstone messages (#1259)
# Background Adapt turnstone message attestation test code to the new compass ABI. # Testing completed - [x] test coverage exists or has been added/updated - [ ] tested in a private testnet # Breaking changes - [x] I have checked my code for breaking changes - [x] If there are breaking changes, there is a supporting migration. --------- Co-authored-by: Christian Lohr <[email protected]>
1 parent 8ece2ab commit 51b87b7

13 files changed

+1017
-22
lines changed

x/evm/keeper/attest.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ func attestTransactionIntegrity(
156156
msg consensustypes.QueuedSignedMessageI,
157157
k *Keeper,
158158
proof *types.TxExecutedProof,
159-
chainReferenceID string,
160-
verifyTx func(context.Context, *ethtypes.Transaction, consensustypes.QueuedSignedMessageI, *types.Valset, *types.SmartContract) error,
159+
chainReferenceID, relayer string,
160+
verifyTx func(context.Context, *ethtypes.Transaction, consensustypes.QueuedSignedMessageI, *types.Valset, *types.SmartContract, string) error,
161161
) (*ethtypes.Transaction, error) {
162162
// check if correct thing was called
163163
tx, err := proof.GetTX()
@@ -199,7 +199,7 @@ func attestTransactionIntegrity(
199199
}
200200
}
201201

202-
err = verifyTx(ctx, tx, msg, &valset, compass)
202+
err = verifyTx(ctx, tx, msg, &valset, compass, relayer)
203203
if err != nil {
204204
// passed in transaction doesn't seem to be created from this smart contract
205205
return nil, fmt.Errorf("tx failed to verify: %w", err)

x/evm/keeper/attest_submit_logic_call.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (a *submitLogicCallAttester) Execute(ctx sdk.Context) error {
4242

4343
func (a *submitLogicCallAttester) attest(ctx sdk.Context, evidence *types.TxExecutedProof) (err error) {
4444
_, err = attestTransactionIntegrity(ctx, a.originalMessage, a.k, evidence,
45-
a.chainReferenceID, a.action.VerifyAgainstTX)
45+
a.chainReferenceID, a.msg.AssigneeRemoteAddress, a.action.VerifyAgainstTX)
4646
if err != nil {
4747
a.logger.WithError(err).Error("Failed to verify transaction integrity.")
4848
return err

x/evm/keeper/attest_test.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ var (
2929
contractAbi = string(whoops.Must(os.ReadFile("testdata/sample-abi.json")))
3030
contractBytecodeStr = string(whoops.Must(os.ReadFile("testdata/sample-bytecode.out")))
3131

32-
sampleTx1RawBytes = common.FromHex(string(whoops.Must(os.ReadFile("testdata/sample-tx-raw.hex"))))
33-
34-
sampleTx1 = func() *ethcoretypes.Transaction {
32+
// Keeping the upload_smart_contract test on the old ABI until compass becomes more stable as
33+
// updates to this test harness are tedious.
34+
uscAbi = string(whoops.Must(os.ReadFile("testdata/usc-abi.json")))
35+
uscBytecodeStr = string(whoops.Must(os.ReadFile("testdata/usc-bytecode.out")))
36+
uscTx1RawBytes = common.FromHex(string(whoops.Must(os.ReadFile("testdata/usc-tx-raw.hex"))))
37+
uscTx1 = func() *ethcoretypes.Transaction {
3538
tx := new(ethcoretypes.Transaction)
36-
whoops.Assert(tx.UnmarshalBinary(sampleTx1RawBytes))
39+
whoops.Assert(tx.UnmarshalBinary(uscTx1RawBytes))
3740
return tx
3841
}()
3942

@@ -163,7 +166,9 @@ var _ = g.Describe("attest router", func() {
163166
})
164167

165168
g.BeforeEach(func() {
166-
consensusMsg = &types.Message{}
169+
consensusMsg = &types.Message{
170+
AssigneeRemoteAddress: "0x28E9e9bfedEd29747FCc33ccA25b4B75f05E434B",
171+
}
167172
})
168173

169174
g.JustBeforeEach(func() {
@@ -183,6 +188,7 @@ var _ = g.Describe("attest router", func() {
183188
PublicAccessData: &consensustypes.PublicAccessData{
184189
ValsetID: 1,
185190
},
191+
GasEstimate: 1000,
186192
}
187193
})
188194

@@ -372,6 +378,11 @@ var _ = g.Describe("attest router", func() {
372378
HexContractAddress: "0x51eca2efb15afacc612278c71f5edb35986f172f",
373379
Abi: []byte(contractAbi),
374380
Payload: common.FromHex(slcPayload),
381+
Fees: &types.SubmitLogicCall_Fees{
382+
RelayerFee: 1,
383+
CommunityFee: 2,
384+
SecurityFee: 3,
385+
},
375386
},
376387
}
377388
})
@@ -542,7 +553,7 @@ var _ = g.Describe("attest router", func() {
542553

543554
g.When("message is UploadSmartContract", func() {
544555
g.BeforeEach(func() {
545-
execTx = sampleTx1
556+
execTx = uscTx1
546557
proof := whoops.Must(codectypes.NewAnyWithValue(&types.TxExecutedProof{SerializedTX: whoops.Must(execTx.MarshalBinary())}))
547558
evidence = []*consensustypes.Evidence{
548559
{
@@ -561,8 +572,8 @@ var _ = g.Describe("attest router", func() {
561572
consensusMsg.Action = &types.Message_UploadSmartContract{
562573
UploadSmartContract: &types.UploadSmartContract{
563574
Id: 1,
564-
Abi: contractAbi,
565-
Bytecode: common.FromHex(contractBytecodeStr),
575+
Abi: uscAbi,
576+
Bytecode: common.FromHex(uscBytecodeStr),
566577
},
567578
}
568579
address, err := sdk.ValAddressFromBech32("cosmosvaloper1pzf9apnk8yw7pjw3v9vtmxvn6guhkslanh8r07")

x/evm/keeper/attest_update_valset.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (a *updateValsetAttester) Execute(ctx sdk.Context) error {
5252

5353
func (a *updateValsetAttester) attest(ctx sdk.Context, evidence *types.TxExecutedProof) error {
5454
_, err := attestTransactionIntegrity(ctx, a.originalMessage, a.k, evidence,
55-
a.chainReferenceID, a.action.VerifyAgainstTX)
55+
a.chainReferenceID, a.msg.AssigneeRemoteAddress, a.action.VerifyAgainstTX)
5656
if err != nil {
5757
a.logger.WithError(err).Error("Failed to verify transaction integrity.")
5858
return err

x/evm/keeper/attest_upload_smart_contract.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (a *uploadSmartContractAttester) Execute(ctx sdk.Context) error {
6565

6666
func (a *uploadSmartContractAttester) attest(ctx sdk.Context, evidence *types.TxExecutedProof) error {
6767
tx, err := attestTransactionIntegrity(ctx, a.originalMessage, a.k, evidence,
68-
a.chainReferenceID, a.action.VerifyAgainstTX)
68+
a.chainReferenceID, a.msg.AssigneeRemoteAddress, a.action.VerifyAgainstTX)
6969
if err != nil {
7070
a.logger.WithError(err).Error("Failed to verify transaction integrity.")
7171
return err

0 commit comments

Comments
 (0)