-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step circuit instance encoding solidity (with tests) (#21)
* add missing instances in step & rotation circuits * return all 32 bytes as expected by sha chip * replace onion hashing with input concat * off-circuit instance generation for concat input hashing 0c6f3f * add lib implementing encoding and fix forge building process * adds tests between rust and solidity implementations driven from rust * refactor test function * format the solidity_tests module * restrict function types to pure * remove deploy script from this branch * add changes required from add-missing-instance * roll back solidity version change * remove unused deps * tests passing with version revert and move endian converter helpers to SyncStepLib.sol * add new just action for building contracts and do this in CI before running tests that use solidity build output --------- Co-authored-by: Timofey Luin <[email protected]>
- Loading branch information
1 parent
3c15023
commit 029283d
Showing
14 changed files
with
202 additions
and
41 deletions.
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
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,3 @@ | ||
[submodule "contracts/lib/forge-std"] | ||
path = contracts/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std |
This file was deleted.
Oops, something went wrong.
Submodule forge-std
updated
16 files
+1 −1 | src/Script.sol | |
+7 −0 | src/StdChains.sol | |
+14 −2 | src/StdCheats.sol | |
+15 −0 | src/StdInvariant.sol | |
+14 −14 | src/StdJson.sol | |
+50 −3 | src/StdStorage.sol | |
+1 −2 | src/Test.sol | |
+77 −14 | src/Vm.sol | |
+93 −77 | test/StdAssertions.t.sol | |
+20 −15 | test/StdChains.t.sol | |
+52 −44 | test/StdCheats.t.sol | |
+10 −10 | test/StdError.t.sol | |
+10 −10 | test/StdMath.t.sol | |
+58 −36 | test/StdStorage.t.sol | |
+4 −4 | test/StdStyle.t.sol | |
+28 −28 | test/StdUtils.t.sol |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
ds-test/=lib/forge-std/lib/ds-test/src/ | ||
forge-std/=lib/forge-std/src/ | ||
forge-std/=lib/forge-std/src/ |
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,55 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/console.sol"; | ||
|
||
|
||
library SyncStepLib { | ||
struct SyncStepInput { | ||
uint64 attestedSlot; | ||
uint64 finalizedSlot; | ||
uint64 participation; | ||
bytes32 finalizedHeaderRoot; | ||
bytes32 executionPayloadRoot; | ||
} | ||
|
||
function toLittleEndian64(uint64 v) internal pure returns (bytes8) { | ||
v = ((v & 0xFF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF) << 8); | ||
v = ((v & 0xFFFF0000FFFF0000) >> 16) | ((v & 0x0000FFFF0000FFFF) << 16); | ||
v = ((v & 0xFFFFFFFF00000000) >> 32) | ((v & 0x00000000FFFFFFFF) << 32); | ||
return bytes8(v); | ||
} | ||
|
||
function toLittleEndian(uint256 v) internal pure returns (bytes32) { | ||
v = ((v & 0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00) >> 8) | ||
| ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8); | ||
v = ((v & 0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000) >> 16) | ||
| ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16); | ||
v = ((v & 0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000) >> 32) | ||
| ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32); | ||
v = ((v & 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000) >> 64) | ||
| ((v & 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) << 64); | ||
v = (v >> 128) | (v << 128); | ||
return bytes32(v); | ||
} | ||
|
||
/** | ||
* @notice Compute the public input commitment for the sync step given this input. | ||
* This must always match the prodecure used in lightclient-circuits/src/sync_step_circuit.rs - SyncStepCircuit::instance() | ||
* @param args The arguments for the sync step | ||
* @param keysPoseidonCommitment The commitment to the keys used in the sync step | ||
* @return The public input commitment that can be sent to the verifier contract. | ||
*/ | ||
function toInputCommitment(SyncStepInput memory args, bytes32 keysPoseidonCommitment) internal pure returns (uint256) { | ||
bytes32 h = sha256(abi.encodePacked( | ||
toLittleEndian64(args.attestedSlot), | ||
toLittleEndian64(args.finalizedSlot), | ||
toLittleEndian64(args.participation), | ||
args.finalizedHeaderRoot, | ||
args.executionPayloadRoot, | ||
keysPoseidonCommitment | ||
)); | ||
uint256 commitment = uint256(toLittleEndian(uint256(h))); | ||
return commitment & ((uint256(1) << 253) - 1); // truncated to 253 bits | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.19; | ||
|
||
import { SyncStepLib } from "../src/SyncStepLib.sol"; | ||
|
||
/** | ||
* @title SyncStepLibTest | ||
* @dev This contract exists solely for the purpose of exposing the SyncStepLib functions | ||
* so they can be used in the Rust test suite. It should not be part of a production deployment | ||
*/ | ||
contract SyncStepExternal { | ||
using SyncStepLib for SyncStepLib.SyncStepInput; | ||
|
||
function toInputCommitment(SyncStepLib.SyncStepInput calldata args, bytes32 keysPoseidonCommitment) public pure returns (uint256) { | ||
return args.toInputCommitment(keysPoseidonCommitment); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -65,6 +65,9 @@ rstest = "0.18.2" | |
test-utils = { git = "ssh://[email protected]/sygmaprotocol/Zipline.git", rev = "27e8a01" } | ||
ethereum-consensus-types = { git = "ssh://[email protected]/sygmaprotocol/Zipline.git", rev = "27e8a01" } | ||
light-client-verifier = { git = "ssh://[email protected]/sygmaprotocol/Zipline.git", rev = "27e8a01" } | ||
ethers = "2.0.10" | ||
tokio = { version = "1.32.0", features = ["rt", "macros"] } | ||
anyhow = "1.0.75" | ||
|
||
[features] | ||
default = [] |
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
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