code-423n4 / 2022-02-anchor-findings

0 stars 0 forks source link

Hardcoded nonces #40

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/code-423n4/2022-02-anchor/blob/7af353e3234837979a19ddc8093dc9ad3c63ab6b/contracts/cross-chain-contracts/terra/contracts/wormhole-bridge/src/contract.rs#L482-L483

Vulnerability details

Impact

Nonces should only be used once by definition. However, all token transfers use the same hardcoded nonce.

const TOKEN_TRANSFER_NONCE: u32 = 135792468u32;
const TOKEN_TRANSFER_INFO_NONCE: u32 = 24680135u32;

It's unclear why Wormhole requires a nonce in the first place if they increment a sequence counter on each PostMessage. The documentation also does not talk about it. We still recommend best practices of not reusing cryptographic nonces to avoid the same transfer parameters failing due to resulting in the same hash if the sequence was not incremented.

Recommended Mitigation Steps

Use a counter as a nonce that is incremented each time. Store it in the contract's state.

GalloDaSballo commented 2 years ago

Pretty odd, but seems like nonce is not a nonce if it can be reused, perhaps wrong documentation?