From 8d8de760b70c8730535deca936eb8aa36a821046 Mon Sep 17 00:00:00 2001 From: Cesar Date: Thu, 28 Sep 2023 13:47:15 -0400 Subject: [PATCH 1/2] Remove destinationAddress and destinationChainID from Warp Message --- contracts/contracts/ExampleWarp.sol | 30 ++++------------ .../contracts/interfaces/IWarpMessenger.sol | 25 ++++---------- plugin/evm/ExampleWarp.abi | 20 ----------- plugin/evm/ExampleWarp.bin | 2 +- plugin/evm/vm_warp_test.go | 22 +----------- tests/warp/warp_test.go | 8 ++--- warp/payload/README.md | 8 +---- warp/payload/addressed_payload.go | 14 +++----- warp/payload/payload_test.go | 12 ++----- x/warp/README.md | 6 ---- x/warp/contract.abi | 34 +------------------ x/warp/contract.go | 32 +++++------------ x/warp/contract_test.go | 19 +---------- x/warp/contract_warp_handler.go | 2 -- x/warp/predicate_test.go | 11 +++--- 15 files changed, 40 insertions(+), 205 deletions(-) diff --git a/contracts/contracts/ExampleWarp.sol b/contracts/contracts/ExampleWarp.sol index 726b00c1c4..8701681fd9 100644 --- a/contracts/contracts/ExampleWarp.sol +++ b/contracts/contracts/ExampleWarp.sol @@ -8,13 +8,9 @@ contract ExampleWarp { address constant WARP_ADDRESS = 0x0200000000000000000000000000000000000005; IWarpMessenger warp = IWarpMessenger(WARP_ADDRESS); - // sendWarpMessage sends a warp message to the specified destination chain and address pair containing the payload - function sendWarpMessage( - bytes32 destinationChainID, - address destinationAddress, - bytes calldata payload - ) external { - warp.sendWarpMessage(destinationChainID, destinationAddress, payload); + // sendWarpMessage sends a warp message containing the payload + function sendWarpMessage(bytes calldata payload) external { + warp.sendWarpMessage(payload); } // validateWarpMessage retrieves the warp message attached to the transaction and verifies all of its attributes. @@ -22,47 +18,33 @@ contract ExampleWarp { uint32 index, bytes32 sourceChainID, address originSenderAddress, - bytes32 destinationChainID, - address destinationAddress, bytes calldata payload ) external view { (WarpMessage memory message, bool valid) = warp.getVerifiedWarpMessage(index); require(valid); require(message.sourceChainID == sourceChainID); require(message.originSenderAddress == originSenderAddress); - require(message.destinationChainID == destinationChainID); - require(message.destinationAddress == destinationAddress); require(keccak256(message.payload) == keccak256(payload)); } - function validateInvalidWarpMessage( - uint32 index - ) external view { + function validateInvalidWarpMessage(uint32 index) external view { (WarpMessage memory message, bool valid) = warp.getVerifiedWarpMessage(index); require(!valid); require(message.sourceChainID == bytes32(0)); require(message.originSenderAddress == address(0)); - require(message.destinationChainID == bytes32(0)); - require(message.destinationAddress == address(0)); require(keccak256(message.payload) == keccak256(bytes(""))); } // validateWarpBlockHash retrieves the warp block hash attached to the transaction and verifies it matches the // expected block hash. - function validateWarpBlockHash( - uint32 index, - bytes32 sourceChainID, - bytes32 blockHash - ) external view { + function validateWarpBlockHash(uint32 index, bytes32 sourceChainID, bytes32 blockHash) external view { (WarpBlockHash memory warpBlockHash, bool valid) = warp.getVerifiedWarpBlockHash(index); require(valid); require(warpBlockHash.sourceChainID == sourceChainID); require(warpBlockHash.blockHash == blockHash); } - function validateInvalidWarpBlockHash( - uint32 index - ) external view { + function validateInvalidWarpBlockHash(uint32 index) external view { (WarpBlockHash memory warpBlockHash, bool valid) = warp.getVerifiedWarpBlockHash(index); require(!valid); require(warpBlockHash.sourceChainID == bytes32(0)); diff --git a/contracts/contracts/interfaces/IWarpMessenger.sol b/contracts/contracts/interfaces/IWarpMessenger.sol index 7cf925ee35..5c67e0d1d4 100644 --- a/contracts/contracts/interfaces/IWarpMessenger.sol +++ b/contracts/contracts/interfaces/IWarpMessenger.sol @@ -8,8 +8,6 @@ pragma solidity ^0.8.0; struct WarpMessage { bytes32 sourceChainID; address originSenderAddress; - bytes32 destinationChainID; - address destinationAddress; bytes payload; } @@ -19,12 +17,7 @@ struct WarpBlockHash { } interface IWarpMessenger { - event SendWarpMessage( - bytes32 indexed destinationChainID, - address indexed destinationAddress, - address indexed sender, - bytes message - ); + event SendWarpMessage(address indexed sender, bytes message); // sendWarpMessage emits a request for the subnet to send a warp message from [msg.sender] // with the specified parameters. @@ -33,29 +26,23 @@ interface IWarpMessenger { // precompile. // Each validator then adds the UnsignedWarpMessage encoded in the log to the set of messages // it is willing to sign for an off-chain relayer to aggregate Warp signatures. - function sendWarpMessage( - bytes32 destinationChainID, - address destinationAddress, - bytes calldata payload - ) external; + function sendWarpMessage(bytes calldata payload) external; // getVerifiedWarpMessage parses the pre-verified warp message in the // predicate storage slots as a WarpMessage and returns it to the caller. // If the message exists and passes verification, returns the verified message // and true. // Otherwise, returns false and the empty value for the message. - function getVerifiedWarpMessage(uint32 index) - external view - returns (WarpMessage calldata message, bool valid); + function getVerifiedWarpMessage(uint32 index) external view returns (WarpMessage calldata message, bool valid); // getVerifiedWarpBlockHash parses the pre-verified WarpBlockHash message in the // predicate storage slots as a WarpBlockHash message and returns it to the caller. // If the message exists and passes verification, returns the verified message // and true. // Otherwise, returns false and the empty value for the message. - function getVerifiedWarpBlockHash(uint32 index) - external view - returns (WarpBlockHash calldata warpBlockHash, bool valid); + function getVerifiedWarpBlockHash( + uint32 index + ) external view returns (WarpBlockHash calldata warpBlockHash, bool valid); // getBlockchainID returns the snow.Context BlockchainID of this chain. // This blockchainID is the hash of the transaction that created this blockchain on the P-Chain diff --git a/plugin/evm/ExampleWarp.abi b/plugin/evm/ExampleWarp.abi index a45ea8088b..9d4b442caa 100644 --- a/plugin/evm/ExampleWarp.abi +++ b/plugin/evm/ExampleWarp.abi @@ -1,16 +1,6 @@ [ { "inputs": [ - { - "internalType": "bytes32", - "name": "destinationChainID", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "destinationAddress", - "type": "address" - }, { "internalType": "bytes", "name": "payload", @@ -101,16 +91,6 @@ "name": "originSenderAddress", "type": "address" }, - { - "internalType": "bytes32", - "name": "destinationChainID", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "destinationAddress", - "type": "address" - }, { "internalType": "bytes", "name": "payload", diff --git a/plugin/evm/ExampleWarp.bin b/plugin/evm/ExampleWarp.bin index 6aa001f4d4..c5963ac7ea 100644 --- a/plugin/evm/ExampleWarp.bin +++ b/plugin/evm/ExampleWarp.bin @@ -1 +1 @@ -60806040527302000000000000000000000000000000000000056000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555034801561006457600080fd5b50610eef806100746000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c806315f0c9591461006757806324b9c5a2146100835780636f57e4c41461009f57806377ca84db146100bb578063e519286f146100d7578063f25ec06a146100f3575b600080fd5b610081600480360381019061007c919061073a565b61010f565b005b61009d6004803603810190610098919061082a565b6101ac565b005b6100b960048036038101906100b491906108da565b610243565b005b6100d560048036038101906100d09190610989565b6103c4565b005b6100f160048036038101906100ec91906109b6565b61049b565b005b61010d60048036038101906101089190610989565b61056d565b005b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634213cf786040518163ffffffff1660e01b8152600401602060405180830381865afa15801561017a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061019e9190610a1e565b81146101a957600080fd5b50565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166324b9c5a2858585856040518563ffffffff1660e01b815260040161020b9493929190610ac7565b600060405180830381600087803b15801561022557600080fd5b505af1158015610239573d6000803e3d6000fd5b5050505050505050565b60008060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636f8253508a6040518263ffffffff1660e01b815260040161029f9190610b16565b600060405180830381865afa1580156102bc573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052508101906102e59190610d84565b91509150806102f357600080fd5b8782600001511461030357600080fd5b8673ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff161461033f57600080fd5b8582604001511461034f57600080fd5b8473ffffffffffffffffffffffffffffffffffffffff16826060015173ffffffffffffffffffffffffffffffffffffffff161461038b57600080fd5b838360405161039b929190610e10565b6040518091039020826080015180519060200120146103b957600080fd5b505050505050505050565b60008060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ce7f5929846040518263ffffffff1660e01b81526004016104209190610b16565b606060405180830381865afa15801561043d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104619190610e79565b91509150801561047057600080fd5b6000801b82600001511461048357600080fd5b6000801b82602001511461049657600080fd5b505050565b60008060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ce7f5929866040518263ffffffff1660e01b81526004016104f79190610b16565b606060405180830381865afa158015610514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105389190610e79565b915091508061054657600080fd5b8382600001511461055657600080fd5b8282602001511461056657600080fd5b5050505050565b60008060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636f825350846040518263ffffffff1660e01b81526004016105c99190610b16565b600060405180830381865afa1580156105e6573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061060f9190610d84565b91509150801561061e57600080fd5b6000801b82600001511461063157600080fd5b600073ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff161461066e57600080fd5b6000801b82604001511461068157600080fd5b600073ffffffffffffffffffffffffffffffffffffffff16826060015173ffffffffffffffffffffffffffffffffffffffff16146106be57600080fd5b6040518060200160405280600081525080519060200120826080015180519060200120146106eb57600080fd5b505050565b6000604051905090565b600080fd5b600080fd5b6000819050919050565b61071781610704565b811461072257600080fd5b50565b6000813590506107348161070e565b92915050565b6000602082840312156107505761074f6106fa565b5b600061075e84828501610725565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061079282610767565b9050919050565b6107a281610787565b81146107ad57600080fd5b50565b6000813590506107bf81610799565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f8401126107ea576107e96107c5565b5b8235905067ffffffffffffffff811115610807576108066107ca565b5b602083019150836001820283011115610823576108226107cf565b5b9250929050565b60008060008060608587031215610844576108436106fa565b5b600061085287828801610725565b9450506020610863878288016107b0565b935050604085013567ffffffffffffffff811115610884576108836106ff565b5b610890878288016107d4565b925092505092959194509250565b600063ffffffff82169050919050565b6108b78161089e565b81146108c257600080fd5b50565b6000813590506108d4816108ae565b92915050565b600080600080600080600060c0888a0312156108f9576108f86106fa565b5b60006109078a828b016108c5565b97505060206109188a828b01610725565b96505060406109298a828b016107b0565b955050606061093a8a828b01610725565b945050608061094b8a828b016107b0565b93505060a088013567ffffffffffffffff81111561096c5761096b6106ff565b5b6109788a828b016107d4565b925092505092959891949750929550565b60006020828403121561099f5761099e6106fa565b5b60006109ad848285016108c5565b91505092915050565b6000806000606084860312156109cf576109ce6106fa565b5b60006109dd868287016108c5565b93505060206109ee86828701610725565b92505060406109ff86828701610725565b9150509250925092565b600081519050610a188161070e565b92915050565b600060208284031215610a3457610a336106fa565b5b6000610a4284828501610a09565b91505092915050565b610a5481610704565b82525050565b610a6381610787565b82525050565b600082825260208201905092915050565b82818337600083830152505050565b6000601f19601f8301169050919050565b6000610aa68385610a69565b9350610ab3838584610a7a565b610abc83610a89565b840190509392505050565b6000606082019050610adc6000830187610a4b565b610ae96020830186610a5a565b8181036040830152610afc818486610a9a565b905095945050505050565b610b108161089e565b82525050565b6000602082019050610b2b6000830184610b07565b92915050565b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610b6e82610a89565b810181811067ffffffffffffffff82111715610b8d57610b8c610b36565b5b80604052505050565b6000610ba06106f0565b9050610bac8282610b65565b919050565b600080fd5b600081519050610bc581610799565b92915050565b600080fd5b600067ffffffffffffffff821115610beb57610bea610b36565b5b610bf482610a89565b9050602081019050919050565b60005b83811015610c1f578082015181840152602081019050610c04565b83811115610c2e576000848401525b50505050565b6000610c47610c4284610bd0565b610b96565b905082815260208101848484011115610c6357610c62610bcb565b5b610c6e848285610c01565b509392505050565b600082601f830112610c8b57610c8a6107c5565b5b8151610c9b848260208601610c34565b91505092915050565b600060a08284031215610cba57610cb9610b31565b5b610cc460a0610b96565b90506000610cd484828501610a09565b6000830152506020610ce884828501610bb6565b6020830152506040610cfc84828501610a09565b6040830152506060610d1084828501610bb6565b606083015250608082015167ffffffffffffffff811115610d3457610d33610bb1565b5b610d4084828501610c76565b60808301525092915050565b60008115159050919050565b610d6181610d4c565b8114610d6c57600080fd5b50565b600081519050610d7e81610d58565b92915050565b60008060408385031215610d9b57610d9a6106fa565b5b600083015167ffffffffffffffff811115610db957610db86106ff565b5b610dc585828601610ca4565b9250506020610dd685828601610d6f565b9150509250929050565b600081905092915050565b6000610df78385610de0565b9350610e04838584610a7a565b82840190509392505050565b6000610e1d828486610deb565b91508190509392505050565b600060408284031215610e3f57610e3e610b31565b5b610e496040610b96565b90506000610e5984828501610a09565b6000830152506020610e6d84828501610a09565b60208301525092915050565b60008060608385031215610e9057610e8f6106fa565b5b6000610e9e85828601610e29565b9250506040610eaf85828601610d6f565b915050925092905056fea2646970667358221220fc88d6f0cab27cb1721b87381fb14f8f41246682162ff9bd7d2d6a6a46dcf29264736f6c634300080d0033 \ No newline at end of file +60806040527302000000000000000000000000000000000000055f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550348015610062575f80fd5b50610d15806100705f395ff3fe608060405234801561000f575f80fd5b5060043610610060575f3560e01c806315f0c959146100645780635bd05f061461008057806377ca84db1461009c578063e519286f146100b8578063ee5b48eb146100d4578063f25ec06a146100f0575b5f80fd5b61007e60048036038101906100799190610658565b61010c565b005b61009a60048036038101906100959190610777565b6101a5565b005b6100b660048036038101906100b191906107fb565b6102cd565b005b6100d260048036038101906100cd9190610826565b61039a565b005b6100ee60048036038101906100e99190610876565b610464565b005b61010a600480360381019061010591906107fb565b6104ef565b005b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634213cf786040518163ffffffff1660e01b8152600401602060405180830381865afa158015610174573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019891906108d5565b81146101a2575f80fd5b50565b5f805f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636f825350886040518263ffffffff1660e01b81526004016101ff919061090f565b5f60405180830381865afa158015610219573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906102419190610b48565b915091508061024e575f80fd5b85825f01511461025c575f80fd5b8473ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff1614610297575f80fd5b83836040516102a7929190610bde565b6040518091039020826040015180519060200120146102c4575f80fd5b50505050505050565b5f805f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ce7f5929846040518263ffffffff1660e01b8152600401610327919061090f565b606060405180830381865afa158015610342573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103669190610c43565b915091508015610374575f80fd5b5f801b825f015114610384575f80fd5b5f801b826020015114610395575f80fd5b505050565b5f805f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ce7f5929866040518263ffffffff1660e01b81526004016103f4919061090f565b606060405180830381865afa15801561040f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104339190610c43565b9150915080610440575f80fd5b83825f01511461044e575f80fd5b8282602001511461045d575f80fd5b5050505050565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ee5b48eb83836040518363ffffffff1660e01b81526004016104be929190610cbd565b5f604051808303815f87803b1580156104d5575f80fd5b505af11580156104e7573d5f803e3d5ffd5b505050505050565b5f805f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636f825350846040518263ffffffff1660e01b8152600401610549919061090f565b5f60405180830381865afa158015610563573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061058b9190610b48565b915091508015610599575f80fd5b5f801b825f0151146105a9575f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff16146105e4575f80fd5b60405180602001604052805f815250805190602001208260400151805190602001201461060f575f80fd5b505050565b5f604051905090565b5f80fd5b5f80fd5b5f819050919050565b61063781610625565b8114610641575f80fd5b50565b5f813590506106528161062e565b92915050565b5f6020828403121561066d5761066c61061d565b5b5f61067a84828501610644565b91505092915050565b5f63ffffffff82169050919050565b61069b81610683565b81146106a5575f80fd5b50565b5f813590506106b681610692565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6106e5826106bc565b9050919050565b6106f5816106db565b81146106ff575f80fd5b50565b5f81359050610710816106ec565b92915050565b5f80fd5b5f80fd5b5f80fd5b5f8083601f84011261073757610736610716565b5b8235905067ffffffffffffffff8111156107545761075361071a565b5b6020830191508360018202830111156107705761076f61071e565b5b9250929050565b5f805f805f608086880312156107905761078f61061d565b5b5f61079d888289016106a8565b95505060206107ae88828901610644565b94505060406107bf88828901610702565b935050606086013567ffffffffffffffff8111156107e0576107df610621565b5b6107ec88828901610722565b92509250509295509295909350565b5f602082840312156108105761080f61061d565b5b5f61081d848285016106a8565b91505092915050565b5f805f6060848603121561083d5761083c61061d565b5b5f61084a868287016106a8565b935050602061085b86828701610644565b925050604061086c86828701610644565b9150509250925092565b5f806020838503121561088c5761088b61061d565b5b5f83013567ffffffffffffffff8111156108a9576108a8610621565b5b6108b585828601610722565b92509250509250929050565b5f815190506108cf8161062e565b92915050565b5f602082840312156108ea576108e961061d565b5b5f6108f7848285016108c1565b91505092915050565b61090981610683565b82525050565b5f6020820190506109225f830184610900565b92915050565b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6109728261092c565b810181811067ffffffffffffffff821117156109915761099061093c565b5b80604052505050565b5f6109a3610614565b90506109af8282610969565b919050565b5f80fd5b5f815190506109c6816106ec565b92915050565b5f80fd5b5f67ffffffffffffffff8211156109ea576109e961093c565b5b6109f38261092c565b9050602081019050919050565b5f5b83811015610a1d578082015181840152602081019050610a02565b5f8484015250505050565b5f610a3a610a35846109d0565b61099a565b905082815260208101848484011115610a5657610a556109cc565b5b610a61848285610a00565b509392505050565b5f82601f830112610a7d57610a7c610716565b5b8151610a8d848260208601610a28565b91505092915050565b5f60608284031215610aab57610aaa610928565b5b610ab5606061099a565b90505f610ac4848285016108c1565b5f830152506020610ad7848285016109b8565b602083015250604082015167ffffffffffffffff811115610afb57610afa6109b4565b5b610b0784828501610a69565b60408301525092915050565b5f8115159050919050565b610b2781610b13565b8114610b31575f80fd5b50565b5f81519050610b4281610b1e565b92915050565b5f8060408385031215610b5e57610b5d61061d565b5b5f83015167ffffffffffffffff811115610b7b57610b7a610621565b5b610b8785828601610a96565b9250506020610b9885828601610b34565b9150509250929050565b5f81905092915050565b828183375f83830152505050565b5f610bc58385610ba2565b9350610bd2838584610bac565b82840190509392505050565b5f610bea828486610bba565b91508190509392505050565b5f60408284031215610c0b57610c0a610928565b5b610c15604061099a565b90505f610c24848285016108c1565b5f830152506020610c37848285016108c1565b60208301525092915050565b5f8060608385031215610c5957610c5861061d565b5b5f610c6685828601610bf6565b9250506040610c7785828601610b34565b9150509250929050565b5f82825260208201905092915050565b5f610c9c8385610c81565b9350610ca9838584610bac565b610cb28361092c565b840190509392505050565b5f6020820190508181035f830152610cd6818486610c91565b9050939250505056fea2646970667358221220d2f09e48f2e77361389456025f7337767127dc73767d50ff2f46bc5273493cec64736f6c63430008150033 \ No newline at end of file diff --git a/plugin/evm/vm_warp_test.go b/plugin/evm/vm_warp_test.go index 1f010ecb79..c880705905 100644 --- a/plugin/evm/vm_warp_test.go +++ b/plugin/evm/vm_warp_test.go @@ -64,11 +64,7 @@ func TestSendWarpMessage(t *testing.T) { payload := utils.RandomBytes(100) - warpSendMessageInput, err := warp.PackSendWarpMessage(warp.SendWarpMessageInput{ - DestinationChainID: common.Hash(vm.ctx.CChainID), - DestinationAddress: testEthAddrs[1], - Payload: payload, - }) + warpSendMessageInput, err := warp.PackSendWarpMessage(payload) require.NoError(err) // Submit a transaction to trigger sending a warp message @@ -96,8 +92,6 @@ func TestSendWarpMessage(t *testing.T) { require.Len(receipts[0].Logs, 1) expectedTopics := []common.Hash{ warp.WarpABI.Events["SendWarpMessage"].ID, - common.Hash(vm.ctx.CChainID), - testEthAddrs[1].Hash(), testEthAddrs[0].Hash(), } require.Equal(expectedTopics, receipts[0].Logs[0].Topics) @@ -134,13 +128,9 @@ func TestValidateWarpMessage(t *testing.T) { require := require.New(t) sourceChainID := ids.GenerateTestID() sourceAddress := common.HexToAddress("0x376c47978271565f56DEB45495afa69E59c16Ab2") - destinationChainID := ids.GenerateTestID() - destinationAddress := common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87") payload := []byte{1, 2, 3} addressedPayload, err := warpPayload.NewAddressedPayload( sourceAddress, - common.Hash(destinationChainID), - destinationAddress, payload, ) require.NoError(err) @@ -153,8 +143,6 @@ func TestValidateWarpMessage(t *testing.T) { uint32(0), sourceChainID, sourceAddress, - destinationChainID, - destinationAddress, payload, ) require.NoError(err) @@ -166,13 +154,9 @@ func TestValidateInvalidWarpMessage(t *testing.T) { require := require.New(t) sourceChainID := ids.GenerateTestID() sourceAddress := common.HexToAddress("0x376c47978271565f56DEB45495afa69E59c16Ab2") - destinationChainID := ids.GenerateTestID() - destinationAddress := common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87") payload := []byte{1, 2, 3} addressedPayload, err := warpPayload.NewAddressedPayload( sourceAddress, - common.Hash(destinationChainID), - destinationAddress, payload, ) require.NoError(err) @@ -409,8 +393,6 @@ func TestReceiveWarpMessage(t *testing.T) { addressedPayload, err := warpPayload.NewAddressedPayload( testEthAddrs[0], - common.Hash(vm.ctx.CChainID), - testEthAddrs[1], payload, ) require.NoError(err) @@ -549,8 +531,6 @@ func TestReceiveWarpMessage(t *testing.T) { Message: warp.WarpMessage{ SourceChainID: common.Hash(vm.ctx.ChainID), OriginSenderAddress: testEthAddrs[0], - DestinationChainID: common.Hash(vm.ctx.CChainID), - DestinationAddress: testEthAddrs[1], Payload: payload, }, Valid: true, diff --git a/tests/warp/warp_test.go b/tests/warp/warp_test.go index 2de777af29..38524565f9 100644 --- a/tests/warp/warp_test.go +++ b/tests/warp/warp_test.go @@ -166,7 +166,7 @@ var _ = ginkgo.Describe("[Warp]", ginkgo.Ordered, func() { subnetB := subnetIDs[1] subnetBDetails, ok := manager.GetSubnet(subnetB) gomega.Expect(ok).Should(gomega.BeTrue()) - blockchainIDB := subnetBDetails.BlockchainID + blockchainIDB = subnetBDetails.BlockchainID gomega.Expect(len(subnetBDetails.ValidatorURIs)).Should(gomega.Equal(5)) chainBURIs = append(chainBURIs, subnetBDetails.ValidatorURIs...) @@ -199,11 +199,7 @@ var _ = ginkgo.Describe("[Warp]", ginkgo.Ordered, func() { startingNonce, err := chainAWSClient.NonceAt(ctx, fundedAddress, nil) gomega.Expect(err).Should(gomega.BeNil()) - packedInput, err := warp.PackSendWarpMessage(warp.SendWarpMessageInput{ - DestinationChainID: common.Hash(blockchainIDB), - DestinationAddress: fundedAddress, - Payload: payload, - }) + packedInput, err := warp.PackSendWarpMessage(payload) gomega.Expect(err).Should(gomega.BeNil()) tx := types.NewTx(&types.DynamicFeeTx{ ChainID: chainID, diff --git a/warp/payload/README.md b/warp/payload/README.md index 71f89c2c6e..1da3b92712 100644 --- a/warp/payload/README.md +++ b/warp/payload/README.md @@ -13,21 +13,15 @@ AddressedPayload: +---------------------+----------+-------------------+ | sourceAddress : [20]byte | 20 bytes | +---------------------+----------+-------------------+ -| destinationChainID : [32]byte | 32 bytes | -+---------------------+----------+-------------------+ -| destinationAddress : [20]byte | 20 bytes | -+---------------------+----------+-------------------+ | payload : []byte | 4 + len(payload) | +---------------------+----------+-------------------+ - | 82 + len(payload) | + | 30 + len(payload) | +-------------------+ ``` - `codecID` is the codec version used to serialize the payload and is hardcoded to `0x0000` - `typeID` is the payload type identifier and is `0x00000000` for `AddressedPayload` - `sourceAddress` is the address that called `sendWarpPrecompile` on the source chain -- `destinationChainID` is the blockchainID that the message is intended for -- `destinationAddress` is the address that should be called on the destination chain - `payload` is an arbitrary byte array payload ## BlockHashPayload diff --git a/warp/payload/addressed_payload.go b/warp/payload/addressed_payload.go index 41afbad847..a0ed6767d6 100644 --- a/warp/payload/addressed_payload.go +++ b/warp/payload/addressed_payload.go @@ -12,21 +12,17 @@ import ( // AddressedPayload defines the format for delivering a point to point message across VMs // ie. (ChainA, AddressA) -> (ChainB, AddressB) type AddressedPayload struct { - SourceAddress common.Address `serialize:"true"` - DestinationChainID common.Hash `serialize:"true"` - DestinationAddress common.Address `serialize:"true"` - Payload []byte `serialize:"true"` + SourceAddress common.Address `serialize:"true"` + Payload []byte `serialize:"true"` bytes []byte } // NewAddressedPayload creates a new *AddressedPayload and initializes it. -func NewAddressedPayload(sourceAddress common.Address, destinationChainID common.Hash, destinationAddress common.Address, payload []byte) (*AddressedPayload, error) { +func NewAddressedPayload(sourceAddress common.Address, payload []byte) (*AddressedPayload, error) { ap := &AddressedPayload{ - SourceAddress: sourceAddress, - DestinationChainID: destinationChainID, - DestinationAddress: destinationAddress, - Payload: payload, + SourceAddress: sourceAddress, + Payload: payload, } return ap, ap.initialize() } diff --git a/warp/payload/payload_test.go b/warp/payload/payload_test.go index 01a590e3e9..69856538cb 100644 --- a/warp/payload/payload_test.go +++ b/warp/payload/payload_test.go @@ -17,8 +17,6 @@ func TestAddressedPayload(t *testing.T) { require := require.New(t) addressedPayload, err := NewAddressedPayload( - common.Address(ids.GenerateTestShortID()), - common.Hash(ids.GenerateTestID()), common.Address(ids.GenerateTestShortID()), []byte{1, 2, 3}, ) @@ -36,12 +34,10 @@ func TestParseAddressedPayloadJunk(t *testing.T) { } func TestParseAddressedPayload(t *testing.T) { - base64Payload := "AAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAEBQYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcICQAAAAAAAAAAAAAAAAAAAAAAAAAAAwoLDA==" + base64Payload := "AAAAAAAAAQIDAAAAAAAAAAAAAAAAAAAAAAAAAAADCgsM" payload := &AddressedPayload{ - SourceAddress: common.Address{1, 2, 3}, - DestinationChainID: common.Hash{4, 5, 6}, - DestinationAddress: common.Address{7, 8, 9}, - Payload: []byte{10, 11, 12}, + SourceAddress: common.Address{1, 2, 3}, + Payload: []byte{10, 11, 12}, } require.NoError(t, payload.initialize()) @@ -91,8 +87,6 @@ func TestParseWrongPayloadType(t *testing.T) { require.NoError(err) addressedPayload, err := NewAddressedPayload( - common.Address(ids.GenerateTestShortID()), - common.Hash(ids.GenerateTestID()), common.Address(ids.GenerateTestShortID()), []byte{1, 2, 3}, ) diff --git a/x/warp/README.md b/x/warp/README.md index 975e2ecd27..846a258650 100644 --- a/x/warp/README.md +++ b/x/warp/README.md @@ -40,8 +40,6 @@ The Warp Precompile is broken down into three functions defined in the Solidity - `SourceChainID` - blockchainID of the sourceChain on the Avalanche P-Chain - `SourceAddress` - `msg.sender` encoded as a 32 byte value that calls `sendWarpMessage` -- `DestinationChainID` - `bytes32` argument specifies the blockchainID on the Avalanche P-Chain that should receive the message -- `DestinationAddress` - 32 byte value that represents the destination address that should receive the message (on the EVM this is the 20 byte address left zero extended) - `Payload` - `payload` argument specified in the call to `sendWarpMessage` emitted as the unindexed data of the resulting log Calling this function will issue a `SendWarpMessage` event from the Warp Precompile. Since the EVM limits the number of topics to 4 including the EventID, this message includes only the topics that would be expected to help filter messages emitted from the Warp Precompile the most. @@ -50,8 +48,6 @@ Specifically, the `payload` is not emitted as a topic because each topic must be Additionally, the `SourceChainID` is excluded because anyone parsing the chain can be expected to already know the blockchainID. Therefore, the `SendWarpMessage` event includes the indexable attributes: -- `destinationChainID` -- `destinationAddress` - `sender` The actual `message` is the entire [Avalanche Warp Unsigned Message](https://github.com/ava-labs/avalanchego/blob/master/vms/platformvm/warp/unsigned_message.go#L14) including the Subnet-EVM [Addressed Payload](../../../warp/payload/payload.go). @@ -72,8 +68,6 @@ This leads to the following advantages: This pre-verification is performed using the ProposerVM Block header during [block verification](../../../plugin/evm/block.go#L220) and [block building](../../../miner/worker.go#L200). -Note: in order to support the notion of an `AnycastID` for the `DestinationChainID`, `getVerifiedMessage` and the predicate DO NOT require that the `DestinationChainID` matches the `blockchainID` currently running. Instead, callers of `getVerifiedMessage` should use `getBlockchainID()` to decide how they should interpret the message. In other words, does the `destinationChainID` match either the local `blockchainID` or the `AnycastID`. - #### getBlockchainID `getBlockchainID` returns the blockchainID of the blockchain that Subnet-EVM is running on. diff --git a/x/warp/contract.abi b/x/warp/contract.abi index 7e83a4de69..04aa755c32 100644 --- a/x/warp/contract.abi +++ b/x/warp/contract.abi @@ -2,18 +2,6 @@ { "anonymous": false, "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "destinationChainID", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "address", - "name": "destinationAddress", - "type": "address" - }, { "indexed": true, "internalType": "address", @@ -101,16 +89,6 @@ "name": "originSenderAddress", "type": "address" }, - { - "internalType": "bytes32", - "name": "destinationChainID", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "destinationAddress", - "type": "address" - }, { "internalType": "bytes", "name": "payload", @@ -132,16 +110,6 @@ }, { "inputs": [ - { - "internalType": "bytes32", - "name": "destinationChainID", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "destinationAddress", - "type": "address" - }, { "internalType": "bytes", "name": "payload", @@ -153,4 +121,4 @@ "stateMutability": "nonpayable", "type": "function" } -] \ No newline at end of file +] diff --git a/x/warp/contract.go b/x/warp/contract.go index cb22b40aba..e5ce9450be 100644 --- a/x/warp/contract.go +++ b/x/warp/contract.go @@ -68,8 +68,6 @@ type GetVerifiedWarpBlockHashOutput struct { type WarpMessage struct { SourceChainID common.Hash OriginSenderAddress common.Address - DestinationChainID common.Hash - DestinationAddress common.Address Payload []byte } @@ -77,11 +75,6 @@ type GetVerifiedWarpMessageOutput struct { Message WarpMessage Valid bool } -type SendWarpMessageInput struct { - DestinationChainID common.Hash - DestinationAddress common.Address - Payload []byte -} // PackGetBlockchainID packs the include selector (first 4 func signature bytes). // This function is mostly used for tests. @@ -191,18 +184,18 @@ func getVerifiedWarpMessage(accessibleState contract.AccessibleState, caller com return handleWarpMessage(accessibleState, input, suppliedGas, addressedPayloadHandler{}) } -// UnpackSendWarpMessageInput attempts to unpack [input] as SendWarpMessageInput +// UnpackSendWarpMessageInput attempts to unpack [input] as []byte // assumes that [input] does not include selector (omits first 4 func signature bytes) -func UnpackSendWarpMessageInput(input []byte) (SendWarpMessageInput, error) { - inputStruct := SendWarpMessageInput{} +func UnpackSendWarpMessageInput(input []byte) ([]byte, error) { + inputStruct := []byte{} err := WarpABI.UnpackInputIntoInterface(&inputStruct, "sendWarpMessage", input) return inputStruct, err } -// PackSendWarpMessage packs [inputStruct] of type SendWarpMessageInput into the appropriate arguments for sendWarpMessage. -func PackSendWarpMessage(inputStruct SendWarpMessageInput) ([]byte, error) { - return WarpABI.Pack("sendWarpMessage", inputStruct.DestinationChainID, inputStruct.DestinationAddress, inputStruct.Payload) +// PackSendWarpMessage packs [inputStruct] of type []byte into the appropriate arguments for sendWarpMessage. +func PackSendWarpMessage(payload []byte) ([]byte, error) { + return WarpABI.Pack("sendWarpMessage", payload) } // sendWarpMessage constructs an Avalanche Warp Message containing an AddressedPayload and emits a log to signal validators that they should @@ -224,23 +217,18 @@ func sendWarpMessage(accessibleState contract.AccessibleState, caller common.Add return nil, remainingGas, vmerrs.ErrWriteProtection } // unpack the arguments - inputStruct, err := UnpackSendWarpMessageInput(input) + payload, err := UnpackSendWarpMessageInput(input) if err != nil { return nil, remainingGas, fmt.Errorf("%w: %s", errInvalidSendInput, err) } var ( - sourceChainID = accessibleState.GetSnowContext().ChainID - destinationChainID = inputStruct.DestinationChainID - sourceAddress = caller - destinationAddress = inputStruct.DestinationAddress - payload = inputStruct.Payload + sourceChainID = accessibleState.GetSnowContext().ChainID + sourceAddress = caller ) addressedPayload, err := warpPayload.NewAddressedPayload( sourceAddress, - destinationChainID, - destinationAddress, payload, ) if err != nil { @@ -260,8 +248,6 @@ func sendWarpMessage(accessibleState contract.AccessibleState, caller common.Add ContractAddress, []common.Hash{ WarpABI.Events["SendWarpMessage"].ID, - destinationChainID, - destinationAddress.Hash(), sourceAddress.Hash(), }, unsignedWarpMessage.Bytes(), diff --git a/x/warp/contract_test.go b/x/warp/contract_test.go index 3ba6b0f670..1cb8844268 100644 --- a/x/warp/contract_test.go +++ b/x/warp/contract_test.go @@ -83,18 +83,12 @@ func TestGetBlockchainID(t *testing.T) { func TestSendWarpMessage(t *testing.T) { callerAddr := common.HexToAddress("0x0123") - receiverAddr := common.HexToAddress("0x456789") defaultSnowCtx := snow.DefaultContextTest() blockchainID := defaultSnowCtx.ChainID - destinationChainID := ids.GenerateTestID() sendWarpMessagePayload := utils.RandomBytes(100) - sendWarpMessageInput, err := PackSendWarpMessage(SendWarpMessageInput{ - DestinationChainID: common.Hash(destinationChainID), - DestinationAddress: receiverAddr, - Payload: sendWarpMessagePayload, - }) + sendWarpMessageInput, err := PackSendWarpMessage(sendWarpMessagePayload) require.NoError(t, err) tests := map[string]testutils.PrecompileTest{ @@ -146,8 +140,6 @@ func TestSendWarpMessage(t *testing.T) { require.Equal(t, addressedPayload.SourceAddress, callerAddr) require.Equal(t, unsignedWarpMsg.SourceChainID, blockchainID) - require.Equal(t, addressedPayload.DestinationChainID, common.Hash(destinationChainID)) - require.Equal(t, addressedPayload.DestinationAddress, receiverAddr) require.Equal(t, addressedPayload.Payload, sendWarpMessagePayload) }, }, @@ -160,13 +152,10 @@ func TestGetVerifiedWarpMessage(t *testing.T) { networkID := uint32(54321) callerAddr := common.HexToAddress("0x0123") sourceAddress := common.HexToAddress("0x456789") - destinationAddress := common.HexToAddress("0x987654") sourceChainID := ids.GenerateTestID() packagedPayloadBytes := []byte("mcsorley") addressedPayload, err := warpPayload.NewAddressedPayload( sourceAddress, - common.Hash(destinationChainID), - destinationAddress, packagedPayloadBytes, ) require.NoError(t, err) @@ -195,8 +184,6 @@ func TestGetVerifiedWarpMessage(t *testing.T) { Message: WarpMessage{ SourceChainID: common.Hash(sourceChainID), OriginSenderAddress: sourceAddress, - DestinationChainID: common.Hash(destinationChainID), - DestinationAddress: destinationAddress, Payload: packagedPayloadBytes, }, Valid: true, @@ -254,8 +241,6 @@ func TestGetVerifiedWarpMessage(t *testing.T) { Message: WarpMessage{ SourceChainID: common.Hash(sourceChainID), OriginSenderAddress: sourceAddress, - DestinationChainID: common.Hash(destinationChainID), - DestinationAddress: destinationAddress, Payload: packagedPayloadBytes, }, Valid: true, @@ -298,8 +283,6 @@ func TestGetVerifiedWarpMessage(t *testing.T) { Message: WarpMessage{ SourceChainID: common.Hash(sourceChainID), OriginSenderAddress: sourceAddress, - DestinationChainID: common.Hash(destinationChainID), - DestinationAddress: destinationAddress, Payload: packagedPayloadBytes, }, Valid: true, diff --git a/x/warp/contract_warp_handler.go b/x/warp/contract_warp_handler.go index 7348f5c1fc..ade22ee2fa 100644 --- a/x/warp/contract_warp_handler.go +++ b/x/warp/contract_warp_handler.go @@ -108,8 +108,6 @@ func (addressedPayloadHandler) handleMessage(warpMessage *warp.Message) ([]byte, Message: WarpMessage{ SourceChainID: common.Hash(warpMessage.SourceChainID), OriginSenderAddress: addressedPayload.SourceAddress, - DestinationChainID: addressedPayload.DestinationChainID, - DestinationAddress: addressedPayload.DestinationAddress, Payload: addressedPayload.Payload, }, Valid: true, diff --git a/x/warp/predicate_test.go b/x/warp/predicate_test.go index 96b0079fc1..b31a19d560 100644 --- a/x/warp/predicate_test.go +++ b/x/warp/predicate_test.go @@ -34,11 +34,10 @@ const pChainHeight uint64 = 1337 var ( _ utils.Sortable[*testValidator] = (*testValidator)(nil) - errTest = errors.New("non-nil error") - networkID = uint32(54321) - sourceChainID = ids.GenerateTestID() - sourceSubnetID = ids.GenerateTestID() - destinationChainID = ids.GenerateTestID() + errTest = errors.New("non-nil error") + networkID = uint32(54321) + sourceChainID = ids.GenerateTestID() + sourceSubnetID = ids.GenerateTestID() // valid unsigned warp message used throughout testing unsignedMsg *avalancheWarp.UnsignedMessage @@ -83,8 +82,6 @@ func init() { var err error addressedPayload, err = warpPayload.NewAddressedPayload( - common.Address(ids.GenerateTestShortID()), - common.Hash(destinationChainID), common.Address(ids.GenerateTestShortID()), []byte{1, 2, 3}, ) From fc2f57375abd3b22be186a0b034e40d9a6da0d5a Mon Sep 17 00:00:00 2001 From: Cesar Date: Tue, 3 Oct 2023 14:31:05 -0300 Subject: [PATCH 2/2] Use UnpackInput instead of UnpackInputIntoInterface The generated code now matches the output of generate_procompile.sh script --- x/warp/contract.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/x/warp/contract.go b/x/warp/contract.go index e5ce9450be..6f076a136e 100644 --- a/x/warp/contract.go +++ b/x/warp/contract.go @@ -187,10 +187,12 @@ func getVerifiedWarpMessage(accessibleState contract.AccessibleState, caller com // UnpackSendWarpMessageInput attempts to unpack [input] as []byte // assumes that [input] does not include selector (omits first 4 func signature bytes) func UnpackSendWarpMessageInput(input []byte) ([]byte, error) { - inputStruct := []byte{} - err := WarpABI.UnpackInputIntoInterface(&inputStruct, "sendWarpMessage", input) - - return inputStruct, err + res, err := WarpABI.UnpackInput("sendWarpMessage", input) + if err != nil { + return []byte{}, err + } + unpacked := *abi.ConvertType(res[0], new([]byte)).(*[]byte) + return unpacked, nil } // PackSendWarpMessage packs [inputStruct] of type []byte into the appropriate arguments for sendWarpMessage.