Skip to content

Commit 2040373

Browse files
authored
Merge pull request #38 from algorandfoundation/feat/mimc
feat: add stub for v11 op code mimc
2 parents 5e6478b + ec581cb commit 2040373

File tree

10 files changed

+504
-399
lines changed

10 files changed

+504
-399
lines changed

package-lock.json

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"eslint-plugin-prettier": "^5.2.1",
5252
"npm-run-all": "4.1.5",
5353
"patch-package": "^8.0.0",
54+
"polytype": "^0.17.0",
5455
"prettier": "3.3.3",
5556
"rimraf": "6.0.1",
5657
"rollup": "^4.24.0",
@@ -63,8 +64,8 @@
6364
"tslib": "^2.6.2"
6465
},
6566
"dependencies": {
66-
"@algorandfoundation/algorand-typescript": "^1.0.0-beta.7",
67-
"@algorandfoundation/puya-ts": "^1.0.0-beta.11",
67+
"@algorandfoundation/algorand-typescript": "^1.0.0-beta.9",
68+
"@algorandfoundation/puya-ts": "^1.0.0-beta.13",
6869
"elliptic": "^6.5.7",
6970
"js-sha256": "^0.11.0",
7071
"js-sha3": "^0.9.3",

src/impl/crypto.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { arc4, bytes, Bytes, Ecdsa, gtxn, internal, VrfVerify } from '@algorandfoundation/algorand-typescript'
1+
import { arc4, bytes, Bytes, Ecdsa, gtxn, internal, MimcConfigurations, VrfVerify } from '@algorandfoundation/algorand-typescript'
22
import elliptic from 'elliptic'
33
import js_sha256 from 'js-sha256'
44
import js_sha3 from 'js-sha3'
@@ -143,6 +143,10 @@ export const EllipticCurve = new Proxy({} as internal.opTypes.EllipticCurveType,
143143
},
144144
})
145145

146+
export const mimc = (_c: MimcConfigurations, _a: internal.primitives.StubBytesCompat): bytes => {
147+
notImplementedError('mimc')
148+
}
149+
146150
const curveMap = {
147151
[Ecdsa.Secp256k1]: 'secp256k1',
148152
[Ecdsa.Secp256r1]: 'p256',

tests/arc4/struct.spec.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getABIEncodedValue } from '@algorandfoundation/algokit-utils/types/app-
22
import { Bytes, internal } from '@algorandfoundation/algorand-typescript'
33
import { Bool, DynamicArray, interpretAsArc4, StaticArray, Str, Struct, Tuple, UintN } from '@algorandfoundation/algorand-typescript/arc4'
44
import { encodingUtil } from '@algorandfoundation/puya-ts'
5-
import { describe, expect, it, test } from 'vitest'
5+
import { describe, expect, test } from 'vitest'
66
import { AccountCls } from '../../src/impl/account'
77
import { DeliberateAny } from '../../src/typescript-helpers'
88
import { asBytes } from '../../src/util'
@@ -251,49 +251,6 @@ describe('arc4.Struct', async () => {
251251
compareARC4AndABIValue(result.d, nativeValues[i++])
252252
compareARC4AndABIValue(result.a, nativeValues[i++])
253253
})
254-
255-
it('set item in struct', async () => {
256-
const data = testData[5]
257-
const nativeValues = data.nativeValues() as DeliberateAny
258-
nativeValues[0] = 43
259-
nativeValues[2] = 'world'
260-
nativeValues[3][0][1][0][1] = 'hello, world'
261-
nativeValues[3][0][1][0].push('test')
262-
nativeValues[3][1][1][0] = 24
263-
const sdkResult = getABIEncodedValue(nativeValues, data.abiTypeString, {})
264-
265-
const abiValues = data.struct() as Swapped6
266-
abiValues.b = new UintN<64>(43)
267-
abiValues.d = new Str('world')
268-
abiValues.a.at(0).at(1).at(0)[1] = new Str('hello, world')
269-
abiValues.a.at(0).at(1).at(0).push(new Str('test'))
270-
abiValues.a.at(1).at(1)[0] = new UintN<64>(24)
271-
const result = abiValues.bytes
272-
273-
expect(result).toEqual(Bytes(sdkResult))
274-
})
275-
276-
it('set item in struct created from bytes', async () => {
277-
const data = testData[5]
278-
const nativeValues = data.nativeValues() as DeliberateAny
279-
nativeValues[0] = 43
280-
nativeValues[2] = 'world'
281-
nativeValues[3][0][1][0][1] = 'hello, world'
282-
nativeValues[3][0][1][0].push('test')
283-
nativeValues[3][1][1][0] = 24
284-
const sdkResult = getABIEncodedValue(nativeValues, data.abiTypeString, {})
285-
286-
const bytes = Bytes(getABIEncodedValue(data.nativeValues(), data.abiTypeString, {}))
287-
const abiValues = data.create(bytes) as Swapped6
288-
abiValues.b = new UintN<64>(43)
289-
abiValues.d = new Str('world')
290-
abiValues.a.at(0).at(1).at(0)[1] = new Str('hello, world')
291-
abiValues.a.at(0).at(1).at(0).push(new Str('test'))
292-
abiValues.a.at(1).at(1)[0] = new UintN<64>(24)
293-
const result = abiValues.bytes
294-
295-
expect(result).toEqual(Bytes(sdkResult))
296-
})
297254
})
298255

299256
const compareARC4AndABIValue = (arc4Value: DeliberateAny, nativeValue: DeliberateAny) => {

tests/artifacts/crypto-ops/contract.algo.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { arc4, bytes, Ecdsa, ensureBudget, op, OpUpFeeSource, uint64, VrfVerify } from '@algorandfoundation/algorand-typescript'
1+
import {
2+
arc4,
3+
bytes,
4+
Ecdsa,
5+
ensureBudget,
6+
MimcConfigurations,
7+
op,
8+
OpUpFeeSource,
9+
uint64,
10+
VrfVerify,
11+
} from '@algorandfoundation/algorand-typescript'
212
import { Bool } from '@algorandfoundation/algorand-typescript/arc4'
313

414
export class CryptoOpsContract extends arc4.Contract {
@@ -91,4 +101,11 @@ export class CryptoOpsContract extends arc4.Contract {
91101
const result = op.vrfVerify(VrfVerify.VrfAlgorand, a, b, c)
92102
return result
93103
}
104+
105+
@arc4.abimethod()
106+
public verify_mimc(a: bytes): bytes {
107+
ensureBudget(5700, OpUpFeeSource.GroupCredit)
108+
const result = op.mimc(MimcConfigurations.BN254Mp110, a)
109+
return result
110+
}
94111
}

0 commit comments

Comments
 (0)