Analog Ergo#
This project aims to use cryptographic primitives (well established, low level algorithms) as the basis for a cross-chain peer-to-peer marketplace. It will enable users to set and agree to listing prices and other parameters in a private and fungible manner, without the involvement of intermediaries.
ScalarLock#
Successfully tested a Scalar Lock contract, this allows you to lock funds to a scalar value like a random 256bit number that you can test by comparing it with an Elliptic curve multiplication operation against the Secp256k1 Generator. A key component of how values are checked when verifying cryptographic signatures and will enable the final step to Atomic Swaps!. ErgoScript makes this quite easy (Once the constants and registers are figured out):
val scalarLockScript: String = {
s"""
{
val xBYTES = OUTPUTS(0).R4[Coll[Byte]].get
val x = byteArrayToBigInt(xBYTES)
val G = decodePoint(generator)
sigmaProp(
receiver &&
G.exp(x) == xG
)
}
""".stripMargin
It compares a given scalar value (x) to an elliptic curve multiplication operation of Secp256k1 generator (G) and checks if they are equal.
It decodes the generator point and extracts a scalar value from the transaction output. It then checks if the point computed from the scalar multiplication of the generator point and the extracted scalar value is equal to a predefined point. If the two points are equal, the transaction is valid.
2-Party Atomic Swap#
A working python example of a 2-party atomic swap that you can simulate from 2 shell/terminal windows is available at 2pAtomicSwapExample. This might help people reason about the way in which secrets are shared through this protocol and at what steps what data transfer or blockchain interaction is supposed to occur.