Skip to content

Commit

Permalink
Merge branch 'add-collateral-spending-constraint' into 'dev'
Browse files Browse the repository at this point in the history
Add collateral input constraint to limit the spending

See merge request ergo/rosen-bridge/contract!87
  • Loading branch information
vorujack committed Mar 14, 2024
2 parents 90bf12c + fe49a0d commit 44b53ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/scala/rosen/bridge/scripts/Collateral.es
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
sigmaProp(
allOf(
Coll(
SELF.id == INPUTS(1).id,
repo.tokens(0)._1 == repoNFT,
repo.tokens(3)._1 == SELF.tokens(0)._1,
outCollateral.value == SELF.value,
Expand Down
37 changes: 37 additions & 0 deletions src/test/scala/contracts/ContractTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,43 @@ class ContractTest extends TestSuite {
})
}

/**
* @target extend permit transaction should throw error when using fake collateral in inputs altering rwt count
* @dependencies
* @scenario
* - mock user input
* - mock valid input repo and wid box
* - mock fake collateral without AWC and different rwt count
* - mock valid collateral
* - mock valid output repo, permit and wid box
* - mock invalid collateral with AWC and altered rwt count
* - build and sign the extend permit transaction
* @expected
* - sign error for invalid rwt count in output collateral (110 != 200)
*/
property("extend permit transaction should throw error when using fake collateral in inputs altering rwt count") {
networkConfig._1.ergoClient.execute(ctx => {
val prover = getProver()
val WID = Base16.decode(Boxes.getRandomHexString()).get
val userBox = Boxes.createBoxForUser(ctx, prover.getAddress, 1e9.toLong, new ErgoToken(WID, 2L), new ErgoToken(networkConfig._3.RSN, 100L))
val repoBox = Boxes.createRepoInput(ctx, 100000, 5801L, 100L, 1)
val collateral = Boxes.createWatcherCollateralBoxInput(ctx, 1e9.toLong, 0, WID, 100)
val fakeCollateral = Boxes.createFakeWatcherCollateralBox(ctx, 1e9.toLong, 0, WID, 10).convertToInputWith(Boxes.getRandomHexString(), 1)
val repoOut = Boxes.createRepo(ctx, 99900, 5901L, 100L, 1)
val outCollateral = Boxes.createWatcherCollateralBox(ctx, 1e9.toLong, 0, WID, 110L)
val permitBox = Boxes.createPermitBox(ctx, 100L, WID)
val WIDBox = Boxes.createBoxCandidateForUser(ctx, prover.getAddress, Configs.minBoxValue, new ErgoToken(WID, 2L))
val tx = ctx.newTxBuilder().addInputs(repoBox, fakeCollateral, userBox, collateral)
.fee(Configs.fee)
.addOutputs(repoOut, outCollateral, permitBox, WIDBox)
.sendChangeTo(prover.getAddress)
.build()
assertThrows[AnyRef] {
prover.sign(tx)
}
})
}

/**
* @target extend permit transaction signing should throw error when rwt count is not updated correctly in collateral
* @dependencies
Expand Down

0 comments on commit 44b53ed

Please sign in to comment.