Skip to content

Commit 2624aec

Browse files
committed
enforce reference script being None to avoid utxo size attacks
1 parent b37761f commit 2624aec

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/calculation/process.ak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ pub fn find_pool_output(outputs: List<Output>) -> (Output, PoolDatum) {
780780
// - We check that the datum is the correct type, meaning we can't construct an invalid pool output
781781
// - Later, we check that the pool output has the correct value, meaning it *must* contain the pool token, so we can't pay to the pool script multiple times
782782
expect Some(pool_output) = list.head(outputs)
783+
expect pool_output.reference_script == None
783784
expect InlineDatum(output_datum) = pool_output.datum
784785
expect output_datum: PoolDatum = output_datum
785786
(pool_output, output_datum)

validators/pool.ak

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ validator pool(
141141
// Make sure it's not negative, for example if base_fee was negative
142142
expect amortized_base_fee >= 0
143143

144+
let order_outputs =
145+
// The outputs that the scooper is expected to process, which are the outputs after the pool output
146+
// This is a list of outputs, so we can use it to check that the scooper processed the right outputs
147+
list.drop(outputs, 1)
148+
149+
// Make sure that the scooper didn't provide any outputs with a reference script
150+
expect list.all(order_outputs, fn(o) { o.reference_script == None })
151+
144152
// Construct the initial pool state from the datum and the locked values
145153
// This intermediate state will be updated as we process each order, allowing us to do a scan over each input
146154
// In particular, it calculates what fees we should be charging (because of the linear fee decay) and the actual tradable reserves
@@ -210,7 +218,7 @@ validator pool(
210218
// *All* inputs, so we can start over at the beginning of the list if we want
211219
inputs,
212220
// *Remaining* inputs, so we can advance through the list one by one so long as the orders are in order
213-
list.drop(outputs, 1),
221+
order_outputs,
214222
// The list of outputs we should be comparing orders against
215223
0,
216224
// A uniqueness bit-flag, to detect which orders have already been processed; see lib/calculation/InputSorting.md

0 commit comments

Comments
 (0)