NFTBridge
60,000 USDC
View results
Submission Details
Severity: low
Invalid

Nonce is missing in depositTokens hash

Summary

Missing nonce when computing the hash of the request, which allows the same hash to be created, since all parameters are passed with the function call.

Vulnerability Details

When Request.hash is created, all the parameters that the hash is based on are passed from the function call, and anyone can pass the same values. There is no value that is not available to the user as a nonce, which is automatically incremented on every request.

bytes32 hash = keccak256(
abi.encodePacked(
salt,
// Cairo uses felts, which are converted into u256 to compute keccak.
// As we use abi.encodePacked, we want the address to also be 32 bytes long.
uint256(uint160(collection)),
snaddress.unwrap(toL2Address),
tokenIds
)
);
fn compute_request_hash(
salt: felt252,
collection: ContractAddress,
to_l1_address: EthAddress,
token_ids: Span<u256>,
) -> u256 {
let c_felt: felt252 = collection.into();
let mut buf: Array<u256> = array![salt.into(), c_felt.into(), to_l1_address.address.into()];
// Don't add the length of the array because we use abi.encodePacked,
// where arrays are encoded without length.
let mut i: usize = 0;
loop {
if i == token_ids.len() {
break ();
}
buf.append(*token_ids[i]);
i += 1;
};
let mut span = buf.span();
let hash = keccak_u256s_be_inputs(span);
// Ensure keccak endianness compatibility.
u256 {
low: integer::u128_byte_reverse(hash.high),
high: integer::u128_byte_reverse(hash.low)
}
}

Impact

The same hash can be recalculated due to a missing auto-increment value.

Tools Used

Manual

Recommendations

Add the nonce to the hash calculation of both chains.

Updates

Lead Judging Commences

n0kto Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

invalid-replay-attack-hash-not-stored-nonce-not-used

There is no impact here: Transaction cannot be replayed because the blockchain use the nonce in the signature. Hash is computed on-chain. Using or trying to have the same hash mean you need to buy the token, and they will be sent to their origin owner. Why an attacker would buy tokens to give them back ? No real impact.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.