Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: attest turnstone messages #1259

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions x/evm/keeper/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ func attestTransactionIntegrity(
msg consensustypes.QueuedSignedMessageI,
k *Keeper,
proof *types.TxExecutedProof,
chainReferenceID string,
verifyTx func(context.Context, *ethtypes.Transaction, consensustypes.QueuedSignedMessageI, *types.Valset, *types.SmartContract) error,
chainReferenceID, relayer string,
verifyTx func(context.Context, *ethtypes.Transaction, consensustypes.QueuedSignedMessageI, *types.Valset, *types.SmartContract, string) error,
) (*ethtypes.Transaction, error) {
// check if correct thing was called
tx, err := proof.GetTX()
Expand Down Expand Up @@ -199,7 +199,7 @@ func attestTransactionIntegrity(
}
}

err = verifyTx(ctx, tx, msg, &valset, compass)
err = verifyTx(ctx, tx, msg, &valset, compass, relayer)
if err != nil {
// passed in transaction doesn't seem to be created from this smart contract
return nil, fmt.Errorf("tx failed to verify: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion x/evm/keeper/attest_submit_logic_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (a *submitLogicCallAttester) Execute(ctx sdk.Context) error {

func (a *submitLogicCallAttester) attest(ctx sdk.Context, evidence *types.TxExecutedProof) (err error) {
_, err = attestTransactionIntegrity(ctx, a.originalMessage, a.k, evidence,
a.chainReferenceID, a.action.VerifyAgainstTX)
a.chainReferenceID, a.msg.AssigneeRemoteAddress, a.action.VerifyAgainstTX)
if err != nil {
a.logger.WithError(err).Error("Failed to verify transaction integrity.")
return err
Expand Down
25 changes: 17 additions & 8 deletions x/evm/keeper/attest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ var (
contractAbi = string(whoops.Must(os.ReadFile("testdata/sample-abi.json")))
contractBytecodeStr = string(whoops.Must(os.ReadFile("testdata/sample-bytecode.out")))

sampleTx1RawBytes = common.FromHex(string(whoops.Must(os.ReadFile("testdata/sample-tx-raw.hex"))))

sampleTx1 = func() *ethcoretypes.Transaction {
uscAbi = string(whoops.Must(os.ReadFile("testdata/usc-abi.json")))
uscBytecodeStr = string(whoops.Must(os.ReadFile("testdata/usc-bytecode.out")))
uscTx1RawBytes = common.FromHex(string(whoops.Must(os.ReadFile("testdata/usc-tx-raw.hex"))))
uscTx1 = func() *ethcoretypes.Transaction {
tx := new(ethcoretypes.Transaction)
whoops.Assert(tx.UnmarshalBinary(sampleTx1RawBytes))
whoops.Assert(tx.UnmarshalBinary(uscTx1RawBytes))
return tx
}()

Expand Down Expand Up @@ -163,7 +164,9 @@ var _ = g.Describe("attest router", func() {
})

g.BeforeEach(func() {
consensusMsg = &types.Message{}
consensusMsg = &types.Message{
AssigneeRemoteAddress: "0x28E9e9bfedEd29747FCc33ccA25b4B75f05E434B",
}
})

g.JustBeforeEach(func() {
Expand All @@ -183,6 +186,7 @@ var _ = g.Describe("attest router", func() {
PublicAccessData: &consensustypes.PublicAccessData{
ValsetID: 1,
},
GasEstimate: 1000,
}
})

Expand Down Expand Up @@ -372,6 +376,11 @@ var _ = g.Describe("attest router", func() {
HexContractAddress: "0x51eca2efb15afacc612278c71f5edb35986f172f",
Abi: []byte(contractAbi),
Payload: common.FromHex(slcPayload),
Fees: &types.SubmitLogicCall_Fees{
RelayerFee: 1,
CommunityFee: 2,
SecurityFee: 3,
},
},
}
})
Expand Down Expand Up @@ -542,7 +551,7 @@ var _ = g.Describe("attest router", func() {

g.When("message is UploadSmartContract", func() {
g.BeforeEach(func() {
execTx = sampleTx1
execTx = uscTx1
proof := whoops.Must(codectypes.NewAnyWithValue(&types.TxExecutedProof{SerializedTX: whoops.Must(execTx.MarshalBinary())}))
evidence = []*consensustypes.Evidence{
{
Expand All @@ -561,8 +570,8 @@ var _ = g.Describe("attest router", func() {
consensusMsg.Action = &types.Message_UploadSmartContract{
UploadSmartContract: &types.UploadSmartContract{
Id: 1,
Abi: contractAbi,
Bytecode: common.FromHex(contractBytecodeStr),
Abi: uscAbi,
Bytecode: common.FromHex(uscBytecodeStr),
},
}
address, err := sdk.ValAddressFromBech32("cosmosvaloper1pzf9apnk8yw7pjw3v9vtmxvn6guhkslanh8r07")
Expand Down
2 changes: 1 addition & 1 deletion x/evm/keeper/attest_update_valset.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (a *updateValsetAttester) Execute(ctx sdk.Context) error {

func (a *updateValsetAttester) attest(ctx sdk.Context, evidence *types.TxExecutedProof) error {
_, err := attestTransactionIntegrity(ctx, a.originalMessage, a.k, evidence,
a.chainReferenceID, a.action.VerifyAgainstTX)
a.chainReferenceID, a.msg.AssigneeRemoteAddress, a.action.VerifyAgainstTX)
if err != nil {
a.logger.WithError(err).Error("Failed to verify transaction integrity.")
return err
Expand Down
2 changes: 1 addition & 1 deletion x/evm/keeper/attest_upload_smart_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (a *uploadSmartContractAttester) Execute(ctx sdk.Context) error {

func (a *uploadSmartContractAttester) attest(ctx sdk.Context, evidence *types.TxExecutedProof) error {
tx, err := attestTransactionIntegrity(ctx, a.originalMessage, a.k, evidence,
a.chainReferenceID, a.action.VerifyAgainstTX)
a.chainReferenceID, a.msg.AssigneeRemoteAddress, a.action.VerifyAgainstTX)
if err != nil {
a.logger.WithError(err).Error("Failed to verify transaction integrity.")
return err
Expand Down
Loading
Loading