This makes little sense to me:
a require()
statement with no function calls seems to be causing the RangeError: Maximum call stack size exceeded
error, but only when the requirements are not met.
The Solidity is:
function checkJWTProof(address a, bytes32 jwtHash) public view returns (bool) {
bytes32 bytes32Pubkey = bytesToFirst32BytesAsBytes32Type(addressToBytes(a));
bytes memory keyXORJWTHash = bytes32ToBytes(bytes32Pubkey ^ jwtHash);
bytes32 k = sha256(keyXORJWTHash);
// debugging console.logs
console.log(proofToBlock[k]);
console.log(block.number);
require(proofToBlock[k] < block.number, "You need to prove knowledge of JWT in a previous block, otherwise you can be frontrun");
console.log('^');
require(proofToBlock[k] > 0 , "Proof not found; it needs to have been submitted to commitJWTProof in a previous block");
return true;
}
and test code:
...
it('Can prove prior knowledge of message (not JWT but can be)', async function () {
await this.vjwt.commitJWTProof(this.proof1)
await ethers.provider.send('evm_mine')
expect(await this.vjwt['checkJWTProof(address,string)'](this.owner.address, this.message1)).to.equal(true)
});
it('Cannot prove prior knowledge of message (not JWT but can be) in one block', async function () {
await this.vjwt.commitJWTProof(this.proof1)
await expect(this.vjwt['checkJWTProof(address,string)'](this.owner.address, this.message1)).to.be.revertedWith("VM Exception while processing transaction: reverted with reason string 'You need to prove knowledge of JWT in a previous block, otherwise you can be frontrun'");
});
...
Of the test code, the former 'Can prove prior knowledge of message (not JWT but can be)'works. But the latter 'Cannot prove prior knowledge of message (not JWT but can be) in one block' doesn't work. They only differ by one line which changes the block number. between function calls.
The output is
14
15
^
✓ Can prove prior knowledge of message (not JWT but can be) (42ms)
17
17
1) Cannot prove prior knowledge of message (not JWT but can be) in one block
...AssertionError: Expected transaction to be reverted with VM Exception while processing transaction: reverted with reason string 'You need to prove knowledge of JWT in a previous block, otherwise you can be frontrun', but other exception was thrown: RangeError: Maximum call stack size exceeded
So it stops execution on that require statement, as it is only called when 17 == 17. The line after the require() statement never runs when 17 == 17 and the error is thrown. How could require()'s failure cause a stack depth to be so deep?
Even stranger, I checked out a previous version of the code where these test passed, and the tests now don't pass in the previous version. I tried changing the node version, upgrading solc to the latest version, and deleting/reinstalling node_modules. None of those fixed it.