Commit Graph

85 Commits

Author SHA1 Message Date
heyitaki 0ecc427d6f docker: build CLI in shared image
Co-authored-by: Evan Gray <battledingo@gmail.com>
2023-06-01 15:33:07 +01:00
bruce-riley 1514d7cd79
Scripts: For upgrading testnet (#2984) 2023-05-26 08:29:14 -05:00
Kevin Peters 1937691afe terra2: Fix broken CI tests due to LocalTerra v2.4.0 update
LocalTerra was updated to v2.4.0 and the LCD no longer returns
HTTP errors on some transaction failures (not enough gas still returns
an HTTP error). This caused some of the integration tests to break, because
the typescript SDK would throw on those HTTP errors.

https://github.com/terra-money/LocalTerra/releases/tag/v2.4.0
2023-05-25 13:14:10 -04:00
Nikhil Suri f6f93bf35e
tilt: devnet deployment for ibc generic messaging (#2593)
* Tilt devnet deployment for ibc generic messaging

* Address review comments from kcsongor and hendrikhofstadt

* Add IBC channel whitelist updates to wormchain and terra devnet deploy scripts

* VAAs had guardian set index three instead of zero

* ci: update addresses

* Remove message.block_height and message.tx_index from attributes

* Remove unnecessary contracts from terra2 devnet deployment

* Update wormhole-ibc address on terra2

* Update wormhole-ibc guardian set on terra2 devnet deployment

* IBC relayer testnet deployment fixes

* Wormchain update whitelist fix

---------

Co-authored-by: Bruce Riley <briley@jumptrading.com>
Co-authored-by: Evan Gray <battledingo@gmail.com>
2023-05-18 18:56:18 -04:00
Nikhil Suri 892274ffa4
cosmwasm: ibc contracts (#2591)
* cosmwasm: add wormchain-ibc-receiver and wormhole-ibc contracts

* Address review comments from jynnantonix and hendrikhofstadt

* Fix lint errors and test failures

* Update naming to reflect new mapping of channelId -> chainId

* Return errors in ibc handlers that should never be called

* Remove contract name and version logic from migration handlers

* Add query handlers to wormhole-ibc contract

* Add wormchain channel id whitelisting to wormhole-ibc contract

* Increase packet timeout to 1 year

* Rebase on main, update imports to new names

* Add governance replay protection to both contracts

* wormhole_ibc SubmitUpdateChannelChain should only handle a single VAA

* better error messages

* Better logging and strip null characters from channel_id from governance VAA

* add brackets back for empty query methods

* Update Cargo.lock

* Only send wormhole wasm event attributes via IBC and add attribute whitelist on the receiver end

* tilt: fix terra2 deploy

* Update based on comments from jynnantonix

---------

Co-authored-by: Evan Gray <battledingo@gmail.com>
2023-05-18 07:34:15 -04:00
Nikhil Suri 842462fd78
cosmwasm: remove terraswap dependency (#2739)
* cosmwasm: remove terraswap dependency

* add test to ensure serialization is the same
2023-05-04 07:56:01 -07:00
Nikhil Suri c5df4dbfe6
cosmwasm: token bridge: add new CompleteTransferResponse struct as data to complete_transfer executions (#2653) 2023-04-20 07:13:49 -07:00
Nikhil Suri d7b6be7358
Cosmwasm package naming updates (#2641)
* sdk: update wormhole-core to wormhole-sdk and fix lib name to be wormhole_sdk

* cosmwasm: update wormhole and token bridge cosmwasm package/lib names

* Fix terra2 deployment script with new artifact names
2023-04-18 09:31:38 -07:00
Nikhil Suri 8837a9af50
cosmwasm: bump k256 dependency to 0.11 (#2630)
* cosmwasm: add test for keys_equal

* cosmwasm: bump k256 from 0.9.4 to 0.11

* Update bad_signature tests to use new error messages
2023-04-14 15:04:49 -05:00
Nikhil Suri 56b847c41d
cosmwasm: clean up unused dependencies (#2629) 2023-04-13 12:34:08 +01:00
Conor Patrick 26839604c8 accountant: export governance modules from sdk to double check in contract 2023-03-16 08:48:25 -05:00
Conor Patrick 6324a239f9 accountant: address comments from #2513 2023-03-16 08:48:25 -05:00
Conor Patrick 3a1bc456e3 accountant: separate modify_balance into separate module and check test errors 2023-03-16 08:48:25 -05:00
Evan Gray c07cba2836 cosmwasm: acct: fix emitter requirements 2023-03-10 14:44:17 -06:00
Conor Patrick a64e4717de accountant: review comments 2023-02-27 08:52:42 -06:00
Conor Patrick 7c5bdb1863 accountant: remove double keccak for submitting observations 2023-02-27 08:52:42 -06:00
Conor Patrick b35480f966 accountant: address review comments for modify governance vaa 2023-02-15 06:23:25 -08:00
Conor Patrick a3a8e3ea87 accountant: use token bridge governance vaa to make modifications 2023-02-15 06:23:25 -08:00
A5 Pickle ce9c70682c cosmwasm: add prefix handling for observations verification 2023-01-31 21:16:18 -05:00
A5 Pickle 1b40fdb7b9 cosmwasm: fix clippy error 2023-01-26 18:36:03 -06:00
Chirantan Ekbote 9f0109388a cosmwasm: accountant: Allow transfers on the same chain
While sending tokens to another address on the same chain via wormhole
is quite inefficient, it's not strictly disallowed and we do have some
VAAs on solana that do this.  Explicitly check for this case and allow
it.

There are no restrictions on native tokens sent in this way but wrapped
transfers are still subject to some checks: the wrapped account for
the token must exist and it must have a balance larger than the amount
being transferred.  If either of those checks fails then that means
that the sender acquired some wrapped tokens that did not go through
the accountant and so that transfer should be blocked and require manual
intervention.
2023-01-26 09:35:43 -05:00
Chirantan Ekbote dd95954fc3 cosmwasm: Rename accounting -> accountant
Also change wormchain -> global.
2023-01-23 16:42:47 -05:00
Chirantan Ekbote 1f8055adfa cosmwasm: accounting: Use hex-encoding for TokenAddress
Use hex rather than base64 when serializing / deserializing
`TokenAddress` so that it's more consistent with the other address
types.
2023-01-23 14:27:08 -05:00
Chirantan Ekbote 1e3356b4c9 cosmwasm: accounting: Don't store Observation on-chain
Now that we can calculate the digest of an Observation there's no need
to store the whole thing on-chain.  Instead only store the observation
digest, tx_hash, and emitter chain (the tx_hash is necessary because
it's not included in the digest and the emitter chain is used for
servicing missing observation queries).  When adding new observations
we can check for equality by comparing the digests and tx hashes rather
than comparing the whole object.

This should further reduce the size of the on-chain state.
2023-01-23 14:27:08 -05:00
Chirantan Ekbote 2ee213254f cosmwasm: accounting: Don't store signature data on-chain
When submitting observations to the accounting contract, clients sign
the entire batch once.  There's no point storing this signature in the
on-chain data for each observation because it's already stored as part
of the chain's transaction history and the signature would be different
if an observation was submitted as part of a different batch (or the
same batch in a different order) even if the observation itself didn't
change.

Also, nothing actually made use of this signature data.  (Yes,
technically it was returned by some queries but the usefulness of
the signature by itself is questionable without the full batch of
observations that were signed).

All we really care about is the index of the guardian anyway so use
a bitset to keep track of the indices of all the guardians that have
signed an observation.  We use a u128 for the bitset out of an abundance
of caution in case the number of guardians increases in the future.
Dealing with more than 128 guardians is left as a problem for future
wormhole contributors if we ever get to that point.
2023-01-23 14:27:08 -05:00
Chirantan Ekbote 289d37771d cosmwasm: accounting: Return transfer status for observations
When submitting a batch of observations, we don't want an observation
for an already committed transfer to fail the entire batch.  This leads
to more complexity in the guardian and also delays all the legitimate
observations by at least one more block (~5 seconds).

Fix this by returning the transfer status of each observation as part
of the response data.  Observations for committed transfers will get
a `TransferStatus::Committed` response without failing the tx as long
as the digest of the observation matches the digest of the committed
transfer.  Digest mismatches are still an error and will fail the entire
batch.
2023-01-23 14:27:08 -05:00
Chirantan Ekbote d19fc98091 sdk/rust: Properly support tokenbridge payload3 messages
Add the payload as an explicit field to the `TransferWithPayload` enum
variant.  This is a generic parameter that defaults to `Box<RawMessage>`
for maximum flexibility (and to avoid leaking lifetimes higher up the
stack) but users are encouraged to replace this default type parameter
with an explicit `&RawMessage` in places where the serde_wormhole data
format is used.

The main benefit of this change is that the payload is now included as
part of the actual message and no longer requires callers to awkwardly
append it after serialization.  This is especially useful in human-
readable formats like JSON (see the `transfer_with_payload` test in
token.rs for an example of this simplification).

The main downside is that this now requires explicit type annotations
when using the non-payload3 variants so that the compiler will pick up
the default generic parameter.  This is a relatively minor inconvenience
and the benefit appears to be worth the cost.

There should be no functional change.
2023-01-20 18:12:41 +09:00
justinschuldt 9db82e310f cosmwasm - separate deploy code per chain 2023-01-19 09:32:13 -06:00
Nikhil Suri a7976136b7
tilt: add ibc relayer which connects wormchain and terra2 to dev environment (#2215)
- updates terra2 devnet chain timeout_commit to "1s" since the timeout_commit of "0.5s" is too fast and leads to Terra2's clock going into the future.
- updates terra2 devnet chain unbonding_time to "1814400s" which is the default value and translates to a valid trusting period for IBC connectivity.
2023-01-18 07:57:09 -08:00
Chirantan Ekbote 421a030dca sdk/rust: Remove `*_with_payload` methods
The RawMessage type provides a more flexible way to handle trailing
payloads so replace all usage of the `*_with_payload` functions to use
`RawMessage` instead.

There should be no functional change.
2023-01-18 09:33:10 +09:00
Chirantan Ekbote 3c6702b6f7 sdk/rust: Add serde_wormhole::RawMessage
Add a RawMessage type that can be used to defer parsing parts of a
payload, similar to the `json.RawMessage` from Go.  The implementation
is inspired by `serde_json::RawValue`, which does a similar thing.

When serializing, RawMessage will serialize to a base64-encoded string
if it detects that the data format is human readable (like JSON).
Otherwise it will simply forward the raw bytes to the serializer.

RawMessage has both borrowed and boxed versions.  The borrowed version
is the most efficient as it enables zero-copy handling of the input data
but also requires that the input data already contains raw bytes and is
not suitable when dealing with human-readable formats like JSON.

The boxed version is more flexible as it supports byte slices, base64-
encoded strings, and byte sequences but is slightly less efficient as it
requires copying or decoding the input data.
2023-01-18 09:29:05 +09:00
Chirantan Ekbote 8777c22d32 cosmwasm: accounting: Use cw_transcode for events
Use cw_transcode to ensure that event attribute values are always
encoded as proper json, making it easier for clients to parse them back
into structured data.

This also lets us reuse the input messages for the events, reducing the
number of different structs that we need to track.
2023-01-16 09:28:43 +09:00
Chirantan Ekbote b1050f69ee cosmwasm: accounting: Simply transfer queries
Rather than forcing clients to guess whether a transfer is pending or
committed use a single `TransferStatus` query that will return whether
the transfer is still pending or already committed.

This will make it easier for clients to keep the pending and committed
transfer state in sync to avoid unnecessary overhead.
2023-01-13 11:41:54 +09:00
Chirantan Ekbote 3c914c725a cosmwasm: Add cw_transcode crate
The cw_transcode crate provides a way to transcode any arbitrary rust
struct into a `cosmwasm_std::Event` via that struct's `Serialize` impl,
ensuring that the event attribute values are encoded as proper json.

This will make it easier for client code to parse the event back into
structured data without having to write custom parsing code for each
individual event type.
2023-01-12 10:29:29 +09:00
Chirantan Ekbote 72e3a103b8 cosmwasm: accounting: Identify failed transfer in batch
When we fail to handle an observation in a batch, include the transfer
key as part of the error context so that it's easier to figure out which
observation caused the error.
2023-01-05 16:24:58 +09:00
Chirantan Ekbote 5d8072e3da cosmwasm: accounting: Change error message for duplicate observation
Change the error message when handling duplicate observations from
"message already processed" -> "transfer already committed".
2023-01-04 16:17:54 +09:00
Chirantan Ekbote e3192a09b1 cosmwasm: accounting: Add query for missing observations
Add a query for guardians to check if there are any pending transfers
with missing observations.  The guardians can use this information to
trigger re-observations of those transactions.
2023-01-04 16:17:37 +09:00
Chirantan Ekbote ab172b4da5 sdk/rust: Ensure chain conversions are isomorphic
Ensure that converting `Chain` to/from a u16 or to/from a string is
always isomorphic.  This requires changing the `FromStr` impl so that in
can handle strings like "Unknown(27)".
2023-01-04 16:17:14 +09:00
heyitaki b7d870efcb docker: reorganize dockerfiles 2022-12-21 10:58:22 -08:00
Chirantan Ekbote d53085abec cosmwasm: accounting: Include digests in transfer queries
When querying transfer details, return the digest in addition to the
details of the tokens being transferred.
2022-12-21 13:59:01 +09:00
Chirantan Ekbote d6dadb195a cosmwasm: accounting: Remove `InstantiateMsg`
Now that we're keeping track of transfer digests, initializing any on-
chain state through the `InstantiateMsg` doesn't make a lot of sense:
any state initialized this way is unverified and this message doesn't
contain enough information to generate the transfer digests.

Rather than trying to add in the necessary fields, just drop the message
completely since it won't be used in production.  It's currently only
used to initialize on-chain state for tests but the same thing can be
accomplished through the `ModifyBalance` and `SubmitVAAs` methods.
2022-12-21 13:59:01 +09:00
Chirantan Ekbote 29d28a75c0 cosmwasm: accounting: Store transfer digests
Keep track of the digests of committed transfers so that they can be
used later when handling duplicate observations / VAAs.  When processing
an observation or VAA with the same (chain, address, sequence) tuple as
a committed transfer, return a "message already processed" error when
the digests match and a "digest mismatch" error when they don't.  The
latter implies a very serious issue because transfer details shouldn't
change once they have been observed by a quorum of guardians.
2022-12-21 13:59:01 +09:00
Chirantan Ekbote acc3ec14d8 cosmwasm: accounting: Drop dependency on the tokenbridge contract
Now that the accounting contract can handle chain registrations on
its own, there's no need to query the tokenbridge contract.  Remove
references to it from `InstantiateMsg` and the internal state.
2022-12-19 17:14:33 +09:00
Chirantan Ekbote 9a559f3fbd cosmwasm: accounting: Add support for chain registration
Add support for handling chain registration VAAs for the tokenbridge
contract.  This will let us deploy accounting without also having to
deploy the tokenbridge.
2022-12-19 17:14:33 +09:00
Nikhil Suri ee2b6d0c17 cosmwasm: wormhole: remove unecessary cast to usize 2022-12-15 14:51:54 -05:00
Chirantan Ekbote fba2f48dee cosmwasm: accounting: Fix chain registration query return type
The tokenbridge chain registration query returns a
`ChainRegistrationResponse` struct and not a `Vec<u8>`.  Use the proper
return type when sending the query.
2022-12-15 10:01:08 -05:00
Chirantan Ekbote ac9c8cd743 cosmwasm: Add backfill method for accounting
Add a mechanism to backfill missing transfer messages by submitting
signed VAAs.  This will also be used to initialize the on-chain state
as there is too much data to initialize the contract via the normal
`instantiate` mechanism.

Fixes #1883, fixes #1884.
2022-12-15 12:22:37 +09:00
Chirantan Ekbote 16b22a8cfc cosmwasm: wormhole-bindings: Use the Signature type from the SDK
Use the `Signature` type from the core SDK to avoid unnecessary
type conversions.  Cosmwasm requires its message types to implement
`JsonSchema` so also derive that impl for the `Signature` type behind a
feature flag.

This change uncovered a separate issue where the fake `WormholeKeeper`
was using regular ecdsa signatures rather than recoverable signatures
so fix the signing and verification methods to use the recoverable
signatures.
2022-12-15 12:22:37 +09:00
Chirantan Ekbote 88549b6849 cosmwasm: accounting: Add ValidateTransfer query
Add a query to validate transfers.  This can be useful for guardians to
sanity check a transfer before submitting a signed observation for it.
2022-12-15 12:21:35 +09:00
Chirantan Ekbote 7cd3e14e99 cosmwasm: accounting: Rename CommitTransferError -> TransferError
This error will also be returned by the `validate_transfer` query so
rename it.
2022-12-15 12:21:35 +09:00