// PKGPATH: gno.land/r/aib/main package main // Regression test: a voucher send must be rejected when it does not originate // from transfer.Transfer. OnSendPacket is reachable directly through the public // core.SendPacket router, so the direct-user-call guard in transfer.Transfer is // not sufficient on its own — OnSendPacket must also require that voucher (and // GRC20) sends were initiated through transfer.Transfer, mirroring the existing // native-branch pendingNativeEscrow check. // // Here core.SendPacket is invoked directly with a voucher payload whose Sender // equals OriginCaller; the immediate caller is a realm (this main), not a user. // Until the OnSendPacket-level guard lands this test FAILS because the send // succeeds and burns the owner's voucher. import ( "encoding/hex" "time" tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing" "gno.land/p/aib/ibc/types" "gno.land/p/aib/ics23" "gno.land/r/aib/ibc/apps/transfer" "gno.land/r/aib/ibc/core" ) func main(cur realm) { var ( chainID = "chain-id-2" trustedHeight = types.NewHeight(2, 2) clientState = tmtesting.NewClientState(chainID, trustedHeight) apphash, _ = hex.DecodeString("0eadf50c7992d8e1366b8ea63ab7d1346de4762c3d449764ef7dc404ba48381f") trustedValset = tmtesting.GenValset() consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash()) counterpartyID = "07-tendermint-42" ) clientID := core.CreateClient(cross(cur), clientState, consensusState) core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, counterpartyID) // The voucher owner is the signing EOA (OriginCaller). RecvPacket mints 100 // vouchers to it so the balance is non-zero. owner := cur.Previous().Address() recvPacket(cur, clientID, counterpartyID, trustedHeight, owner) // Build a voucher send packet and submit it straight to the core router, // bypassing transfer.Transfer and its guard. The guard must instead reject // this at the OnSendPacket layer. data := transfer.NewFungibleTokenPacketData("transfer/"+clientID+"/uphoton", "100", owner.String(), "atone1user", "") msg := types.MsgSendPacket{ SourceClient: clientID, Payloads: []types.Payload{{ SourcePort: transfer.PortID, DestinationPort: transfer.PortID, Encoding: transfer.EncodingProtobuf, Value: data.ProtoMarshal(), Version: transfer.V1, }}, TimeoutTimestamp: uint64(time.Now().Add(time.Hour).Unix()), } core.SendPacket(cross(cur), msg) } func recvPacket(cur realm, clientID, counterpartyID string, trustedHeight types.Height, receiver address) { payload := transfer.NewFungibleTokenPacketData("uphoton", "100", "atone1user", receiver.String(), "") payloadBz := payload.ProtoMarshal() specs := ics23.IavlSpec() // NOTE proof generated by: // go run -C ./cmd/gen-proof . 'prefix2' '07-tendermint-42' 'packet' '{"sequence":1,"source_client":"07-tendermint-42","destination_client":"07-tendermint-1","timeout_timestamp":1234571490,"payloads":[{"source_port":"transfer","destination_port":"transfer","encoding":"application/x-protobuf", "value":"Cgd1cGhvdG9uEgMxMDAaCmF0b25lMXVzZXIiKGcxd3ltdTQ3ZHJocjBrdXEyMDk4bTc5Mmx5dGd0ajJueXg3N3lyc20=","version":"ics20-1"}]}' proof := []ics23.CommitmentProof{ // iavl proof ics23.CommitmentProof_Exist{ Exist: &ics23.ExistenceProof{ Key: []byte("\x70\x72\x65\x66\x69\x78\x32\x30\x37\x2d\x74\x65\x6e\x64\x65\x72\x6d\x69\x6e\x74\x2d\x34\x32\x01\x00\x00\x00\x00\x00\x00\x00\x01"), Value: []byte("\x12\x6c\xcc\xff\x00\xd6\xb9\x73\x09\xb3\x8b\x1b\xec\x0f\xe2\xef\xc9\x54\xe5\xac\x1d\x90\x47\x36\xd0\x32\xbc\xc0\xb1\x66\xc4\x8f"), Leaf: &ics23.LeafOp{ Hash: specs.LeafSpec.Hash, PrehashKey: specs.LeafSpec.PrehashKey, PrehashValue: specs.LeafSpec.PrehashValue, Length: specs.LeafSpec.Length, Prefix: []byte("\x00\x02\x02"), }, Path: []*ics23.InnerOp{ { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x02\x04\x02\x20\x35\xf8\xea\x80\x53\x90\xe0\x84\x85\x4f\x39\x9b\x42\xcc\xde\xae\xa3\x3a\x1d\xed\xc1\x15\x63\x8a\xc4\x8d\x06\x00\x63\x7d\xba\x1f\x20"), Suffix: []byte(""), }, { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x04\x08\x02\x20"), Suffix: []byte("\x20\x79\x8e\x2c\xaa\x96\xfd\xfb\xa3\x76\xdd\xeb\x47\x99\x99\x54\xd2\xf4\x7e\x65\x16\x22\x64\xb0\x53\x6a\xb5\xdf\xf7\xfc\x0a\x2e\x07"), }, { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x06\x0c\x02\x20\x9a\xf3\x7d\xd5\x95\xa0\x19\x08\x03\xb5\xe0\x5a\xae\xf4\x2a\xe3\xfa\xd4\x99\xe4\xfb\xe3\x7f\x7c\xd3\x1c\xad\xff\x22\xa9\xee\x74\x20"), Suffix: []byte(""), }, }, }, }, // rootmulti proof ics23.CommitmentProof_Exist{ Exist: &ics23.ExistenceProof{ Key: []byte("\x69\x61\x76\x6c\x53\x74\x6f\x72\x65\x4b\x65\x79"), Value: []byte("\x4f\xa3\xdf\x13\x8a\x86\x32\xc8\x3f\xd8\x84\x92\x00\xe0\xf1\xd8\x8a\x05\x36\x85\x32\x15\x1b\x45\x67\xf6\x86\xec\xf1\xfb\x9f\x45"), Leaf: &ics23.LeafOp{ Hash: specs.LeafSpec.Hash, PrehashKey: specs.LeafSpec.PrehashKey, PrehashValue: specs.LeafSpec.PrehashValue, Length: specs.LeafSpec.Length, Prefix: []byte("\x00"), }, Path: []*ics23.InnerOp{}, }, }, } recvMsg := types.MsgRecvPacket{ Packet: types.Packet{ Sequence: 1, SourceClient: counterpartyID, DestinationClient: clientID, TimeoutTimestamp: uint64(time.Now().Add(time.Hour).Unix()), Payloads: []types.Payload{{ SourcePort: transfer.PortID, DestinationPort: transfer.PortID, Encoding: transfer.EncodingProtobuf, Value: payloadBz, Version: transfer.V1, }}, }, ProofCommitment: proof, ProofHeight: trustedHeight, } core.RecvPacket(cross(cur), recvMsg) } // Error: // send packet failed for payload #0 app "transfer": voucher packet must be initiated through transfer.Transfer