-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
README.md
Outdated
SNL1ResolverStub.sol inherits from SNStateProofVerifier.sol and has been deployed to Goerli at 0xBB49c34D4d92aC3207d589657fAC14186a470116 | ||
|
||
On goerli Pedersen hash contract is already deployed at 0x1a1eB562D2caB99959352E40a03B52C00ba7a5b1 | ||
|
||
Poseidon3(starkewares version) contracts EVM code has ben generated from the following repo and deployed on Goerli at 0x84d43a8cbEbF4F43863f399c34c06fC109c957a4. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we add links to goerli etherscan to these contracts' addresses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
README.md
Outdated
|
||
SNL1ResolverStub.sol inherits from SNStateProofVerifier.sol and has been deployed to Goerli at 0xBB49c34D4d92aC3207d589657fAC14186a470116 | ||
|
||
On goerli Pedersen hash contract is already deployed at 0x1a1eB562D2caB99959352E40a03B52C00ba7a5b1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we verify this contract?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 0xBB49c34D4d92aC3207d589657fAC14186a470116 has been verified but this will change due to the changes as part of this review
README.md
Outdated
|
||
On goerli Pedersen hash contract is already deployed at 0x1a1eB562D2caB99959352E40a03B52C00ba7a5b1 | ||
|
||
Poseidon3(starkewares version) contracts EVM code has ben generated from the following repo and deployed on Goerli at 0x84d43a8cbEbF4F43863f399c34c06fC109c957a4. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here: could we verify this contract?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pedersen contract is not so simple to verify, I have created an issue here -> #22
README.md
Outdated
@@ -51,7 +58,7 @@ Current implementation is already deployed for goerli at https://starknetens.ue. | |||
|
|||
|
|||
## L2 Resolver | |||
L2 resolver is a git subtree of https://github.com/starknet-id/ens_resolver. This has been deployed to 0x7412b9155cdb517c5d24e1c80f4af96f31f221151aab9a9a1b67f380a349ea on goerli | |||
This has been upgraded to cairo1 and deployed to 0x7412b9155cdb517c5d24e1c80f4af96f31f221151aab9a9a1b67f380a349ea on goerli |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, it would be good to verify the contract here as well. and add a link to voyager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did try, cairo1 tooling is a work in progress I think, will try again -> #23
// this is the hades permutation function. TODO update the name when goerli eth is not so expensive | ||
function poseidon( | ||
uint256[3] calldata input | ||
) external view returns (uint256[3] calldata); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit surprised by calldata
here. This is only available for function arguments of external functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not so sure about that, you can use it for contract to contract calls and it works fine, its a little bit cheaper I think(but could be wrong) and one should be aware of the downsides(immutability etc etc). But you are right that that is not the convention and probably not worth the confusion it will cause. I have updated it to memory. Interesting question in general though. Happy to be corrected on this understanding
for (uint256 i = 0; i < elems.length / 2; i++) { | ||
state[0] = (state[0] + elems[2 * i]) % BIG_PRIME; | ||
state[1] = (state[1] + elems[2 * i + 1]) % BIG_PRIME; | ||
state = poseidon.poseidon(state); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternative to avoid division and multiplication:
for (uint256 i = 0; i < elems.length; i += 2) {
state[0] = (state[0] + elems[i]) % BIG_PRIME;
state[1] = (state[1] + elems[i + 1]) % BIG_PRIME;
state = poseidon.poseidon(state);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but with (i < elems.length -1) but great suggestion, thanks Massil
function poseidonHashMany( | ||
uint256[] memory elems | ||
) public view returns (uint256) { | ||
uint256[3] memory state = [uint256(0), uint256(0), uint256(0)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe I'm missing something, but I feel that the code here never updates state[2]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, it's probably updated by the function poseidon.poseidon(state)
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that is correct
); | ||
// since we have already verified the first element in the proof array correctly hashes up to the state commitment, we can assume the hash of first element in the proof array is correct. | ||
expectedHash = calculatedContractStateRoot; | ||
} | ||
require( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can move this check before the if statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
require( | ||
proofArray.length > 0, | ||
"proofs must have atleast one element!" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we move the same check below above the if statement, we can remove this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -7,13 +7,13 @@ contract StarknetCoreContractStub { | |||
*/ | |||
function stateRoot() external view returns (uint256) { | |||
return | |||
3321080970052968843805320357911538392446265524314601848332135665594593955343; | |||
2793869633745137896926484933765493995916819896677591814984705621839603171245; | |||
} | |||
|
|||
/** | |||
Returns the current block number. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment is not accurate. what does correspond to the block number 789146?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the comment
@@ -7,13 +7,13 @@ contract StarknetCoreContractStub { | |||
*/ | |||
function stateRoot() external view returns (uint256) { | |||
return | |||
3321080970052968843805320357911538392446265524314601848332135665594593955343; | |||
2793869633745137896926484933765493995916819896677591814984705621839603171245; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what the meaning of this value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a comment at the top of the file mentioning its only to be used in tests. I have moved it into mocks folder to make it more explicit. Its mock contract used only unit tests
contracts/scripts/deploy.ts
Outdated
["https://starknetens.ue.r.appspot.com/{sender}/{data}.json"], // per https://eips.ethereum.org/EIPS/eip-3668 the sender and data populated by the client library like ethers.js with data returned by the CCIP enabled contract via revert | ||
'0x7412b9155cdb517c5d24e1c80f4af96f31f221151aab9a9a1b67f380a349ea3' | ||
'0x7412b9155cdb517c5d24e1c80f4af96f31f221151aab9a9a1b67f380a349ea3' // L2 resolver contract address on starknet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use the constant L2_RESOLVER_ADDRESS
here
contracts/scripts/deploy.ts
Outdated
const proofProxy = await upgrades.deployProxy( | ||
SNResolverStub, | ||
[pedersenHash.address, starknetCoreContractStub.address, ["https://localhost:8080/{sender}/{data}.json"], '0x7412b9155cdb517c5d24e1c80f4af96f31f221151aab9a9a1b67f380a349ea3'], | ||
[pedersenHash.address, poseidon3.address | ||
, starknetCoreContractStub.address, ["https://localhost:8080/{sender}/{data}.json"], '0x7412b9155cdb517c5d24e1c80f4af96f31f221151aab9a9a1b67f380a349ea3'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use the constant L2_RESOLVER_ADDRESS
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies to all L2_RESOLVER_ADDRESS mentions below as well. They cannot all point to the same const var because frontend, contracts, gateway, client test are all independent apps with their package.json and also they happen to be the same values right now but they can be different especially in tests. Also one might want to deploy different resolvers but not yet ready to have the change reflected in the frontend app. Though I have added constants in deploy.ts file just to make it more explicit.
const proofProxy = await upgrades.deployProxy( | ||
SNResolverStub, | ||
[pedersenHash.address, starknetCoreContractStub.address, ["https://localhost:9545/{sender}/{data}.json"], '0x7412b9155cdb517c5d24e1c80f4af96f31f221151aab9a9a1b67f380a349ea3'], | ||
[pedersenHash.address, poseidon3.address, starknetCoreContractStub.address, ["https://localhost:9545/{sender}/{data}.json"], '0x7412b9155cdb517c5d24e1c80f4af96f31f221151aab9a9a1b67f380a349ea3'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, we can use L2_RESOLVER_ADDRESS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment above about L2_RESOLVER_ADDRESS
it("it should verify the sampleproof1.json", async function () { | ||
var jsonFile = "./sampleProof1.json"; | ||
const contractAddress = | ||
"0x6fbd460228d843b7fbef670ff15607bf72e19fa94de21e29811ada167b4ca39"; | ||
"0x7412b9155cdb517c5d24e1c80f4af96f31f221151aab9a9a1b67f380a349ea3"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L2_RESOLVER_ADDRESS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment above about L2_RESOLVER_ADDRESS
it("it should verify the sampleproof1.json", async function () { | ||
var jsonFile = "./sampleProof1.json"; | ||
const contractAddress = | ||
"0x6fbd460228d843b7fbef670ff15607bf72e19fa94de21e29811ada167b4ca39"; | ||
"0x7412b9155cdb517c5d24e1c80f4af96f31f221151aab9a9a1b67f380a349ea3"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L2_RESOLVER_ADDRESS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, this can be any contract, doesn't have to be a L2_RESOLVER_ADDRESS. these are just verifying proofs for a storage value for any contract.
contracts/scripts/deploy.ts
Outdated
"0x1a1eB562D2caB99959352E40a03B52C00ba7a5b1", // pedersen already deployed on goerli (goerli eth is expensive, cant do reployments all the time) | ||
"0x84d43a8cbEbF4F43863f399c34c06fC109c957a4", // poseidon already deployed on goerli (goerli eth is expensive, cant do reployments all the time) | ||
"0xde29d060D45901Fb19ED6C6e959EB22d8626708e", // starknetcore contract address on goerli |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can create constants for these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -134,13 +152,20 @@ describe("Verify", function () { | |||
expect(resultFromStarknetVerifier.toString()).to.be.eq(result[0]); | |||
}); | |||
|
|||
it(" test for a poseidon array", async function () { | |||
const result = await l1resolverStub.poseidonHashMany(["28355430774503553497671514844211693180464", "0x34894aedf9548524f9e5bb189472d25abe3c38befd577c90886a7c519e5eee4", "0x70c5acad61a421be9c2945b921e263f2699c668f20d31c90660e91b32ea99de"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could create a constant FELT_FOR_STARKNET_STATE_V0
for 28355430774503553497671514844211693180464
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and for other numbers as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These any be any random values, just checking poseidonHashMany works for any random set of values, I have added a few more tests
0xca8ac56bd313f8355dc40776427409f119924fe9067320fff8fd8765b766df, 0x7fb20da4f329a630f4bdfb75afae4ec93140da3a2527986c2cb7ee7361b9dea) )) | ||
print ('STARKNET_STATE_V0 to felt ',short_string_to_felt('STARKNET_STATE_V0') ) | ||
print ("state commitment poseidon_hash_many ", hex(poseidon_hash_many([28355430774503553497671514844211693180464, 0x34894aedf9548524f9e5bb189472d25abe3c38befd577c90886a7c519e5eee4, 0x70c5acad61a421be9c2945b921e263f2699c668f20d31c90660e91b32ea99de]))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could create constants for these numbers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a rough work area to compare values, not used as part of any script, there is a explicit comment at the top of the file. Probably should not be checked in, I only checked it in so that anybody can easily play/compare values with starkware's python implementation
…n parameter, remoove redundant proof array size check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
contracts/.DS_Store
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this file as this is not required.
Thanks Prince and Massil for the review |
No description provided.