Skip to content

Commit

Permalink
Fix parsing of pubkey address
Browse files Browse the repository at this point in the history
  • Loading branch information
mdehoog committed Dec 11, 2024
1 parent a385671 commit d0e6c9b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bindings/deploy_chain.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/system_config_global.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deployments/84532-deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"SuperchainConfig": "0xC77dB710C47b6e294D3d544572a10187e8Ef6b2C",
"SuperchainConfigProxy": "0xCf940f9c053092d07EB62DaB59D0AFddF426dE67",
"SystemConfig": "0x8aB8559E6C661eFEB0a44C0f08E180CEe344dABE",
"SystemConfigGlobal": "0xc536C770BBEAfadb8dc8a0A1809A62cE96e7D822",
"SystemConfigGlobal": "0x0933e802B0977fe6287C48a0F601b39244118E04",
"SystemConfigGlobalProxy": "0x53200eC3d6E91E7Ba1fD1087D38430F43501C9Fb",
"SystemConfigProxy": "0x57708f73fF01e8697799B38f47Fbd65bDf9138Bc",
"SystemOwnerSafe": "0xFCD4AfF397A2F9D2a435B64AdA1A70efC59310aD"
Expand Down
16 changes: 16 additions & 0 deletions register-signer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ func main() {
panic(err)
}

pub, err := crypto.UnmarshalPubkey(res.Document.PublicKey)
if err != nil {
panic(err)
}
signerAddr := crypto.PubkeyToAddress(*pub)
validSigner, err := systemConfigGlobal.ValidSigners(&bind.CallOpts{}, signerAddr)
if err != nil {
panic(err)
}
fmt.Printf("Public key: %s\n", hexutil.Encode(res.Document.PublicKey))
fmt.Printf("Signer: %s\n", signerAddr.String())
if validSigner {
fmt.Printf("Signer already registered: %s\n", signerAddr.String())
return
}

certManagerAddr, err := systemConfigGlobal.CertManager(&bind.CallOpts{})
if err != nil {
panic(err)
Expand Down
9 changes: 6 additions & 3 deletions src/SystemConfigGlobal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ pragma solidity ^0.8.0;
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {ISemver} from "@eth-optimism-bedrock/src/universal/interfaces/ISemver.sol";
import {NitroValidator} from "@nitro-validator/NitroValidator.sol";
import {CborDecode} from "@nitro-validator/CborDecode.sol";
import {LibBytes} from "@nitro-validator/LibBytes.sol";
import {LibCborElement, CborElement, CborDecode} from "@nitro-validator/CborDecode.sol";
import {ICertManager} from "@nitro-validator/ICertManager.sol";

contract SystemConfigGlobal is OwnableUpgradeable, ISemver, NitroValidator {
using LibBytes for bytes;
using CborDecode for bytes;
using LibCborElement for CborElement;

uint256 public constant MAX_AGE = 60 minutes;

Expand Down Expand Up @@ -56,8 +59,8 @@ contract SystemConfigGlobal is OwnableUpgradeable, ISemver, NitroValidator {

require(ptrs.timestamp + MAX_AGE > block.timestamp, "attestation too old");

bytes memory publicKey = attestationTbs.slice(ptrs.publicKey);
address enclaveAddress = address(uint160(uint256(keccak256(publicKey))));
bytes32 publicKeyHash = attestationTbs.keccak(ptrs.publicKey.start() + 1, ptrs.publicKey.length() - 1);
address enclaveAddress = address(uint160(uint256(publicKeyHash)));
validSigners[enclaveAddress] = true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/SystemConfigGlobal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract SystemConfigGlobalTest is Test {
(bytes memory attestationTbs, bytes memory signature) = systemConfigGlobal.decodeAttestationTbs(attestation);
systemConfigGlobal.registerSigner(attestationTbs, signature);

address expectedSigner = 0xe04d808785d2BBdE18E9D0C01c05FB8CE0711f2d;
address expectedSigner = 0x874a4c5675cd4850dB08bD9A1e3184ED239087e4;
assertTrue(systemConfigGlobal.validSigners(expectedSigner));
}
}

0 comments on commit d0e6c9b

Please sign in to comment.