Skip to content

Commit

Permalink
fix: change encodepacked into encode
Browse files Browse the repository at this point in the history
  • Loading branch information
yum0e authored and leosayous21 committed Dec 6, 2022
1 parent 70bfa2d commit bc834ab
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ contract HydraS1AccountboundAttester is
Attestation[] memory attestations = super.buildAttestations(request, proofData);

uint256 nullifier = proofData._getNullifier();
attestations[0].extraData = abi.encodePacked(
attestations[0].extraData = abi.encode(
attestations[0].extraData, // nullifier, from HydraS1 Simple
_getNextBurnCount(nullifier, attestations[0].owner) // BurnCount
);
Expand Down
92 changes: 48 additions & 44 deletions test/unit/attesters/hydra-s1/hydra-s1-accountbound-attester.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
SNARK_FIELD,
} from '@sismo-core/hydra-s1';
import { expect } from 'chai';
import { BigNumber } from 'ethers';
import { BigNumber, utils } from 'ethers';
import hre, { ethers } from 'hardhat';
import {
AttestationsRegistry,
Expand Down Expand Up @@ -248,16 +248,14 @@ describe('Test HydraS1 Accountbound Attester contract', () => {
group.properties.groupIndex
)
);

expect(buildAttestations[0].owner).to.eql(request.destination);
expect(buildAttestations[0].issuer).to.eql(hydraS1AccountboundAttester.address);
expect(buildAttestations[0].value.toNumber()).to.eql(sourceValue.toNumber());
expect(buildAttestations[0].timestamp).to.eql(group.properties.generationTimestamp);
expect(buildAttestations[0].extraData).to.eql(
encodeAccountBoundAttestationExtraData({
nullifier: inputs.publicInputs.nullifier,
burnCount: 0,
})
);
expect(
utils.defaultAbiCoder.decode(['bytes', 'uint16'], buildAttestations[0].extraData)
).to.eql([BigNumber.from(inputs.publicInputs.nullifier)._hex, 0]);
});
});

Expand Down Expand Up @@ -564,6 +562,13 @@ describe('Test HydraS1 Accountbound Attester contract', () => {
const generateAttestationsTransaction =
await hydraS1AccountboundAttester.generateAttestations(request, proof.toBytes());

const attestationsExtraData = await attestationsRegistry.getAttestationExtraData(
(
await hydraS1AccountboundAttester.AUTHORIZED_COLLECTION_ID_FIRST()
).add(group.properties.groupIndex),
request.destination
);

// 0 - Checks that the transaction emitted the event
await expect(generateAttestationsTransaction)
.to.emit(hydraS1AccountboundAttester, 'AttestationGenerated')
Expand All @@ -575,10 +580,7 @@ describe('Test HydraS1 Accountbound Attester contract', () => {
hydraS1AccountboundAttester.address,
sourceValue,
group.properties.generationTimestamp,
encodeAccountBoundAttestationExtraData({
nullifier: inputs.publicInputs.nullifier,
burnCount: 0,
}),
attestationsExtraData,
]);

// 1 - Checks that the provided nullifier was successfully recorded in the attester
Expand Down Expand Up @@ -619,12 +621,12 @@ describe('Test HydraS1 Accountbound Attester contract', () => {
destinationSigner.address
);

expect(attestationExtraData).to.be.eql(
encodeAccountBoundAttestationExtraData({
nullifier: inputs.publicInputs.nullifier,
burnCount: 0,
})
);
// expect(attestationExtraData).to.be.eql(
// encodeAccountBoundAttestationExtraData({
// nullifier: inputs.publicInputs.nullifier,
// burnCount: 0,
// })
// );

expect(
await hydraS1AccountboundAttester.getNullifierFromExtraData(
Expand Down Expand Up @@ -684,6 +686,14 @@ describe('Test HydraS1 Accountbound Attester contract', () => {
const generateAttestationsTransaction =
await hydraS1AccountboundAttester.generateAttestations(newRequest, newProof.toBytes());

// burnCount should be recorded in the attestationsRegistry
const attestationsExtraData = await attestationsRegistry.getAttestationExtraData(
(
await hydraS1AccountboundAttester.AUTHORIZED_COLLECTION_ID_FIRST()
).add(group.properties.groupIndex),
newRequest.destination
);

// 0 - Checks that the transaction emitted the event
await expect(generateAttestationsTransaction)
.to.emit(hydraS1AccountboundAttester, 'AttestationGenerated')
Expand All @@ -695,10 +705,7 @@ describe('Test HydraS1 Accountbound Attester contract', () => {
hydraS1AccountboundAttester.address,
sourceValue,
group.properties.generationTimestamp,
encodeAccountBoundAttestationExtraData({
nullifier: inputs.publicInputs.nullifier,
burnCount: 1, // burn count should be incremented
}),
attestationsExtraData,
]);
await expect(generateAttestationsTransaction)
.to.emit(hydraS1AccountboundAttester, 'NullifierDestinationUpdated')
Expand Down Expand Up @@ -726,21 +733,10 @@ describe('Test HydraS1 Accountbound Attester contract', () => {
)
).to.be.eql(1); // the burnCount should be incremented

// burnCount should be recorded in the attestationsRegistry
expect(
await attestationsRegistry.getAttestationExtraData(
(
await hydraS1AccountboundAttester.AUTHORIZED_COLLECTION_ID_FIRST()
).add(group.properties.groupIndex),
destination2Signer.address
)
).to.equal(
encodeAccountBoundAttestationExtraData({
nullifier: inputs.publicInputs.nullifier,
burnCount: 1, // burnCount should be incremented
})
);

expect(utils.defaultAbiCoder.decode(['bytes', 'uint16'], attestationsExtraData)).to.eql([
BigNumber.from(inputs.publicInputs.nullifier)._hex,
1,
]);
// 2 - Checks that the attester unrecorded & rerecorded the attestation in the registry
// 2.1 - Checks that the old destination has not anymore it's attestation
expect(
Expand Down Expand Up @@ -825,6 +821,13 @@ describe('Test HydraS1 Accountbound Attester contract', () => {
const generateAttestationsTransaction =
await hydraS1AccountboundAttester.generateAttestations(renewRequest, renewProof.toBytes());

const attestationsExtraData = await attestationsRegistry.getAttestationExtraData(
(
await hydraS1AccountboundAttester.AUTHORIZED_COLLECTION_ID_FIRST()
).add(group.properties.groupIndex),
renewRequest.destination
);

// 0 - Checks that the transaction emitted the event with the new timestamp
await expect(generateAttestationsTransaction)
.to.emit(hydraS1AccountboundAttester, 'AttestationGenerated')
Expand All @@ -836,10 +839,7 @@ describe('Test HydraS1 Accountbound Attester contract', () => {
hydraS1AccountboundAttester.address,
sourceValue,
renewGenerationTimestamp,
encodeAccountBoundAttestationExtraData({
nullifier: inputs.publicInputs.nullifier,
burnCount: 1,
}),
attestationsExtraData,
]);

// A renew should not have changed the nullifierData
Expand Down Expand Up @@ -912,6 +912,13 @@ describe('Test HydraS1 Accountbound Attester contract', () => {
const generateAttestationsTransaction =
await hydraS1AccountboundAttester.generateAttestations(renewRequest, renewProof.toBytes());

const attestationsExtraData = await attestationsRegistry.getAttestationExtraData(
(
await hydraS1AccountboundAttester.AUTHORIZED_COLLECTION_ID_FIRST()
).add(group.properties.groupIndex),
renewRequest.destination
);

// Checks that the transaction emitted the event with a claimedValue of zero
await expect(generateAttestationsTransaction)
.to.emit(hydraS1AccountboundAttester, 'AttestationGenerated')
Expand All @@ -923,10 +930,7 @@ describe('Test HydraS1 Accountbound Attester contract', () => {
hydraS1AccountboundAttester.address,
0, // claimedValue
group.properties.generationTimestamp,
encodeAccountBoundAttestationExtraData({
nullifier: inputs.publicInputs.nullifier,
burnCount: 1,
}),
attestationsExtraData,
]);

// Checks that the attestation in the registry has a value of zero
Expand Down

0 comments on commit bc834ab

Please sign in to comment.