FP: Double withdrawal#290
Conversation
keyan-m
left a comment
There was a problem hiding this comment.
Not a full review, but just pointing out one thing I spotted :)
| pub fn get_withdrawals_root( | ||
| tx: Transaction, | ||
| state_queue_node_ref_input_index: Int, | ||
| ) -> ByteArray { | ||
| // Reference input with block_hash | ||
| expect Some(state_queue_node_input) = | ||
| list.at(tx.reference_inputs, state_queue_node_ref_input_index) |
There was a problem hiding this comment.
Validation on the NFT seems missing. We do have a helper:
midgard/onchain/aiken/lib/midgard/common/utils.ak
Lines 139 to 156 in ca46d75
| pub fn get_withdrawals_root( | |
| tx: Transaction, | |
| state_queue_node_ref_input_index: Int, | |
| ) -> ByteArray { | |
| // Reference input with block_hash | |
| expect Some(state_queue_node_input) = | |
| list.at(tx.reference_inputs, state_queue_node_ref_input_index) | |
| pub fn get_withdrawals_root( | |
| reference_inputs: List<Input>, | |
| state_queue_policy: PolicyId, | |
| state_queue_node_ref_input_index: Int, | |
| ) -> ByteArray { | |
| // Reference input with block_hash | |
| let state_queue_node_input = | |
| utils.get_authentic_input_with_policy_at( | |
| reference_inputs, | |
| state_queue_policy, | |
| state_queue_node_ref_input_index, | |
| ) |
It might make sense to also define a get_datum in /lib/midgard/state-queue.ak (similar to the one we have in hub-oracle.ak) and use it here.
There was a problem hiding this comment.
Hey @keyan-m
isn't this code doing the nft beacon verification?
let ct_token_asset_name = get_singleton_ct_token(own_input, ct_token_policy_id)
There was a problem hiding this comment.
Oh nevermind I see
I get the asset name but I never use it
There was a problem hiding this comment.
That line seems fine and is validating authenticity of the input (own_input). For the withdrawals root, we're reading the datum off of a reference input, so its state token must also be validated.
There was a problem hiding this comment.
Isn't that missing also here then?
midgard\fraud-proof\common\utils.ak
pub fn get_tx_root_validate_block_hash(
tx: Transaction,
state_queue_node_ref_input_index: Int,
ct_token_asset_name: ByteArray,
) -> ByteArray {
// Reference input with block_hash
expect Some(state_queue_node_input) =
list.at(tx.reference_inputs, state_queue_node_ref_input_index)
// Extract tx_root via the state queue block hash
expect InlineDatum(state_queue_datum_data) =
state_queue_node_input.output.datum
expect state_queue_node_datum: unordered.NodeDatum = state_queue_datum_data
expect parsed_state_queue_datum: Header = state_queue_node_datum.data
expect unordered.Key { key: block_hash } = state_queue_node_datum.key
let extracted_tx_root = parsed_state_queue_datum.transactions_root
// Get CT token and check match with the block hash
expect drop(ct_token_asset_name, n: 4) == block_hash
extracted_tx_root
}
There was a problem hiding this comment.
It seems to be, yeah. I would suggest defining get_confirmed_datum and get_block_datum helpers under /lib/midgard/state-queue.ak so that they can be reused for such validations.
No description provided.