forked from AztecProtocol/aztec-packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Pedersen in typescript. (AztecProtocol#3111)
As title.
- Loading branch information
1 parent
c8e1d8b
commit 933f1b2
Showing
8 changed files
with
395 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "pedersen.hpp" | ||
#include "barretenberg/crypto/generators/generator_data.hpp" | ||
#include <gtest/gtest.h> | ||
|
||
namespace crypto { | ||
|
||
using barretenberg::fr; | ||
|
||
TEST(Pedersen, Commitment) | ||
{ | ||
auto x = pedersen_commitment::Fq::one(); | ||
auto r = pedersen_commitment::commit_native({ x, x }); | ||
auto expected = | ||
grumpkin::g1::affine_element(fr(uint256_t("2f7a8f9a6c96926682205fb73ee43215bf13523c19d7afe36f12760266cdfe15")), | ||
fr(uint256_t("01916b316adbbf0e10e39b18c1d24b33ec84b46daddf72f43878bcc92b6057e6"))); | ||
EXPECT_EQ(r, expected); | ||
} | ||
|
||
} // namespace crypto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/pedersen.test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "pedersen.hpp" | ||
#include "barretenberg/crypto/generators/generator_data.hpp" | ||
#include "barretenberg/numeric/uint256/uint256.hpp" | ||
#include <gtest/gtest.h> | ||
|
||
namespace crypto { | ||
|
||
using barretenberg::fr; | ||
|
||
TEST(Pedersen, Hash) | ||
{ | ||
auto x = pedersen_hash::Fq::one(); | ||
auto r = pedersen_hash::hash({ x, x }); | ||
EXPECT_EQ(r, fr(uint256_t("07ebfbf4df29888c6cd6dca13d4bb9d1a923013ddbbcbdc3378ab8845463297b"))); | ||
} | ||
|
||
TEST(Pedersen, HashWithIndex) | ||
{ | ||
auto x = pedersen_hash::Fq::one(); | ||
auto r = pedersen_hash::hash({ x, x }, 5); | ||
EXPECT_EQ(r, fr(uint256_t("1c446df60816b897cda124524e6b03f36df0cec333fad87617aab70d7861daa6"))); | ||
} | ||
|
||
} // namespace crypto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { toBufferBE } from '../../bigint-buffer/index.js'; | ||
import { pedersenCommit, pedersenHashWithHashIndex } from './index.js'; | ||
|
||
describe('pedersen', () => { | ||
it('pedersen commit', () => { | ||
const r = pedersenCommit([toBufferBE(1n, 32), toBufferBE(1n, 32)]); | ||
expect(r).toEqual([ | ||
Buffer.from('2f7a8f9a6c96926682205fb73ee43215bf13523c19d7afe36f12760266cdfe15', 'hex'), | ||
Buffer.from('01916b316adbbf0e10e39b18c1d24b33ec84b46daddf72f43878bcc92b6057e6', 'hex'), | ||
]); | ||
}); | ||
|
||
it('pedersen hash', () => { | ||
const r = pedersenHashWithHashIndex([toBufferBE(1n, 32), toBufferBE(1n, 32)]); | ||
expect(r).toEqual(Buffer.from('07ebfbf4df29888c6cd6dca13d4bb9d1a923013ddbbcbdc3378ab8845463297b', 'hex')); | ||
}); | ||
|
||
it('pedersen hash with index', () => { | ||
const r = pedersenHashWithHashIndex([toBufferBE(1n, 32), toBufferBE(1n, 32)], 5); | ||
expect(r).toEqual(Buffer.from('1c446df60816b897cda124524e6b03f36df0cec333fad87617aab70d7861daa6', 'hex')); | ||
}); | ||
}); |
Oops, something went wrong.