poseidon contract now accepts both selectors: for uint256[n] and bytes32[n]
This commit is contained in:
parent
afb4eff954
commit
3b492f9801
@ -103,8 +103,13 @@ function createCode(nInputs) {
|
|||||||
C.push(0);
|
C.push(0);
|
||||||
C.calldataload();
|
C.calldataload();
|
||||||
C.div();
|
C.div();
|
||||||
C.push(Web3Utils.keccak256(`poseidon(uint256[${nInputs}])`).slice(0, 10)); // poseidon(uint256[])
|
C.dup(0);
|
||||||
|
C.push(Web3Utils.keccak256(`poseidon(uint256[${nInputs}])`).slice(0, 10)); // poseidon(uint256[n])
|
||||||
C.eq();
|
C.eq();
|
||||||
|
C.swap(1);
|
||||||
|
C.push(Web3Utils.keccak256(`poseidon(bytes32[${nInputs}])`).slice(0, 10)); // poseidon(bytes32[n])
|
||||||
|
C.eq();
|
||||||
|
C.or();
|
||||||
C.jmpi("start");
|
C.jmpi("start");
|
||||||
C.invalid();
|
C.invalid();
|
||||||
|
|
||||||
@ -159,30 +164,51 @@ function createCode(nInputs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateABI(nInputs) {
|
function generateABI(nInputs) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"constant": true,
|
"constant": true,
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
"internalType": `uint256[${nInputs}]`,
|
"internalType": `bytes32[${nInputs}]`,
|
||||||
"name": "input",
|
"name": "input",
|
||||||
"type": `uint256[${nInputs}]`
|
"type": `bytes32[${nInputs}]`
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"name": "poseidon",
|
"name": "poseidon",
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"internalType": "uint256",
|
"internalType": "bytes32",
|
||||||
"name": "",
|
"name": "",
|
||||||
"type": "uint256"
|
"type": "bytes32"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"payable": false,
|
"payable": false,
|
||||||
"stateMutability": "pure",
|
"stateMutability": "pure",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
};
|
"constant": true,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": `uint256[${nInputs}]`,
|
||||||
|
"name": "input",
|
||||||
|
"type": `uint256[${nInputs}]`
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "poseidon",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "pure",
|
||||||
|
"type": "function"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.generateABI = generateABI;
|
module.exports.generateABI = generateABI;
|
||||||
module.exports.createCode = createCode;
|
module.exports.createCode = createCode;
|
||||||
|
@ -14,8 +14,8 @@ describe("Poseidon Smart contract test", function () {
|
|||||||
let poseidon4;
|
let poseidon4;
|
||||||
let accounts;
|
let accounts;
|
||||||
this.timeout(100000);
|
this.timeout(100000);
|
||||||
let C2
|
let C2;
|
||||||
let C4
|
let C4;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });
|
web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });
|
||||||
|
Loading…
Reference in New Issue
Block a user